Skip to content

Instantly share code, notes, and snippets.

@dbdness
Last active May 8, 2024 13:45
Show Gist options
  • Save dbdness/072b032ecbab80578730345dbe68fb5b to your computer and use it in GitHub Desktop.
Save dbdness/072b032ecbab80578730345dbe68fb5b to your computer and use it in GitHub Desktop.
DigiSpark Kickstarter ATTINY85 Setup on macOS + Hello World

Digispark ATTINY85 Initial Setup on macOS + Hello World

Originally written in January 2021.

Originally written for macOS Big Sur 11.1

Step 1: Acquire a DigiSpark ATTINY85 Board

Board used for this guide is the Kickstarter version.

Step 2: Download the Arduino IDE

Version at the time of writing is 1.8.13

a) Downloading the .app: https://www.arduino.cc/en/software b) Using Homebrew

$ brew install --cask arduino

Step 3: Setup Digispark Development Environment through Arduino IDE

  1. Update board source In Arduino IDE, go to File -> Preferences and dump the following into the Additional Boards Manager URLs box:

http://digistump.com/package_digistump_index.json

  1. Install the Digistump AVR Boards Still in Arduino IDE, go to Tools -> Board -> Boards Manager. From the Type dropdown, select Contributed. Select the Digistump AVR Boards package and click install.

  2. Set the Digistump AVR Boards as the default board Still in Arduino IDE, go to Tools -> Board -> Digitump AVR Boards -> Digispark (Default - 16.5mhz).

Step 4: Verify Environment with Sample 'Hello World' Script

  1. Paste the following into the sketch present in Arduino IDE:
#include "DigiKeyboard.h"
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(600);
  DigiKeyboard.print("Hello, World!");
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  for(;;){ /*empty*/ }
}

When this script executes through the board, it will simply open a Spotlight Search, enter "Hello, World!" and press Enter.

  1. Verify the script before you upload it, by clicking "Verify" in the top-left corner (alternately, Sketch -> Verify/compile).

If all is well, you should see the following output in the console at the bottom:

Sketch uses 2700 bytes (44%) of program storage space. Maximum is 6012 bytes.
Global variables use 95 bytes of dynamic memory.

NB: However, if you experience the following error:

fork/exec /Users/XXXXX/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
Error compiling for board Digispark (Default - 16.5mhz).

The solution is to substitute (link) the built-in, outdated AVR tools that Digistump config looks for, with the new, updated one included in the Arduino IDE (Thanks to user Anjin from the Digistump boards). It is done in the following way:

For Arduino IDE 1.x:

$ cd ~/Library/Arduino15/packages/arduino/tools/avr-gcc
$ mv 4.8.1-arduino5 orig.4.8.1
$ ln -s /Applications/Arduino.app/Contents/Java/hardware/tools/avr 4.8.1-arduino5

For Arduino IDE 2.x (thanks to @jorgezazo and vgenov-py):

$ cd ~/Library/Arduino15/packages/arduino/tools/avr-gcc 
$ mv 4.8.1-arduino5/ orig.4.8.1 
$ ln -s ~/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 4.8.1-arduino5

Step 5: Upload and Execute 'Hello World' Script

Once the script can be verified with no issues (as per step 4), prepare the Digispark ATTINY85 board.

  1. From the Arduino IDE, click "Upload" in the top left, and wait for the prompt:
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
  1. Plug in the board and wait.

  2. The following should be displayed in the Arduino console, and the script should self-execute on the machine:

> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 1.6
> Available space for user applications: 6012 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94  page size: 64
> Erase function sleep duration: 752ms
parsing: 50% complete
> Erasing the memory ...
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete
> Starting to upload ...
writing: 70% complete
writing: 75% complete
writing: 80% complete
> Starting the user app ...
running: 100% complete
>> Micronucleus done. Thank you!
@RGSMA
Copy link

RGSMA commented Apr 25, 2023

Thank you! The compiling error had me stumped.

@jorgezazo
Copy link

jorgezazo commented Oct 19, 2023

For Arduino IDE 2, the symbolic link line is:

ln -s ~/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 4.8.1-arduino5

@DevelopMan
Copy link

@dbdness Hey, thanks a lot for the guide. I followed it, but I've got an Flash erase error -32 has occured ...
The full log is:

Sketch uses 2700 bytes (44%) of program storage space. Maximum is 6012 bytes.
Global variables use 95 bytes of dynamic memory.
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device ... 
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 1.6
> Available space for user applications: 6012 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94  page size: 64
> Erase function sleep duration: 752ms
parsing: 50% complete
> Erasing the memory ...
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete
>> Flash erase error -32 has occured ...
>> Please unplug the device and restart the program.

I've tried 2 different boards and the result is the same. My IDE version is 2.2.1 and Sonoma 14.0. What could be an issue?

@DevelopMan
Copy link

I did as it said "unplug the device and restart the app (IDE)" and it works! Thanks!

@dbdness
Copy link
Author

dbdness commented Oct 20, 2023

For Arduino IDE 2, the symbolic link line is:

ln -s ~/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 4.8.1-arduino5

@jorgezazo Thank you! Gist updated.

@vgenov-py
Copy link

vgenov-py commented Dec 9, 2023

Just for anyone that might need it for the 2.X version the complete commands will be the following:
bash $ cs /Users/<username>/Library/Arduino15/packages/arduino/tools/avr-gcc

bash $ mv 4.8.1-arduino5/ orig.4.8.1
bash $ ln -s ~/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 4.8.1-arduino5

You should have also the AVR Arduino library installed too!

@dbdness
Copy link
Author

dbdness commented Jan 2, 2024

Just for anyone that might need it for the 2.X version the complete commands will be the following: bash $ cs /Users/<username>/Library/Arduino15/packages/arduino/tools/avr-gcc

bash $ mv 4.8.1-arduino5/ orig.4.8.1 bash $ ln -s ~/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 4.8.1-arduino5

You should have also the AVR Arduino library installed too!

Thanks @vgenov-py, gist updated.

@EpicTia93
Copy link

I get correctly to the Step 5 but when I insert the Digispark nothing happens, must be some kind of problem with not recognizing the port, how can I solve it?

@pflavio
Copy link

pflavio commented Jan 9, 2024

So I could flash sucesssfully a few times, but now I'm getting ">> Flash erase error -32 has occured ...

Please unplug the device and restart the program." Every time. I did the restart, but no luck. Any ideas on what to try next?

@davydmaker
Copy link

I have the same problem here, has anyone found a solution?

@pflavio
Copy link

pflavio commented Feb 23, 2024

I have the same problem here, has anyone found a solution?

Just plug it in again, using a docking station or a USB hub or a USB extension cord. After that it worked (relatively) reliably for me.

@davydmaker
Copy link

I have the same problem here, has anyone found a solution?

Just plug it in again, using a docking station or a USB hub or a USB extension cord. After that it worked (relatively) reliably for me.

I am using a Multi-Port USB Type-C Hub from Sabrent (https://sabrent.com/products/hb-tc6c), and here it worked 1 out of every 8 times I tried.
No matter the port connected to the computer or the HUB, it was very unstable.

@pflavio
Copy link

pflavio commented Feb 23, 2024

I have the same problem here, has anyone found a solution?

Just plug it in again, using a docking station or a USB hub or a USB extension cord. After that it worked (relatively) reliably for me.

I am using a Multi-Port USB Type-C Hub from Sabrent (https://sabrent.com/products/hb-tc6c), and here it worked 1 out of every 8 times I tried. No matter the port connected to the computer or the HUB, it was very unstable.

Did you try any other devices? For me it worked best on the not-for-charging USB-A ports of a HP USB-C Dock and a cheap USB extension cord I got off of Amazon.

@KennyTw
Copy link

KennyTw commented Mar 14, 2024

Guys, if you're using ATTINY85 General Micro USB(USB male connector on the board) and Type C adapter, you can try to plug in thru a usb type A male to female cable. When I plug into the adapter directly without the cable, it fails 100%. But, when I use the cable, it succeeds 100%.

@Martius108
Copy link

Martius108 commented Apr 6, 2024

I finally could connect the device successfully with a OTG cable as KennyTw recommended but I still get the error mentioned above:

Please plug in the device ...
Press CTRL+C to terminate the program.
Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
Device has firmware version 1.6
Available space for user applications: 6012 bytes
Suggested sleep time between sending pages: 8ms
Whole page count: 94 page size: 64
Erase function sleep duration: 752ms
parsing: 50% complete
Erasing the memory ...
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete

Flash erase error -32 has occured ...
Please unplug the device and restart the program.

Restarting the IDE didn't help.

@zephyr41
Copy link

hy, i can't get the link

@DevelopMan
Copy link

Does anybody face this issue?

Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device ... 
> Press CTRL+C to terminate the program.
> Device search timed out

It worked before I started playing with libraries. I installed AltSoftSerial, SoftSerialTX, and a new board ATTinyCore. At some point, it stopped working. I tried to reinstall Arduino IDE and I removed all installed libraries, but it still doesn't work.

@dbdness
Copy link
Author

dbdness commented May 8, 2024

Guys, if you're using ATTINY85 General Micro USB(USB male connector on the board) and Type C adapter, you can try to plug in thru a usb type A male to female cable. When I plug into the adapter directly without the cable, it fails 100%. But, when I use the cable, it succeeds 100%.

Agreed, I did not encounter any connection issues with a regular USB 2.0 extender (male to female).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment