Program ATTiny85 with Arduino IDE Mar 6th 2021 Words: 555

I bought a $1 Chinese version Digispark ATTiny85 kit.

Step

Open Arduino IDE, in File > Settings > Additional Boards Manager URLs, add https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json and save.

In Tools > Board > Boards Manager, search and install digistump AVR Boards.

Select the Digispark Default 16.5MHz board and Micronucleus programmer.

Write some example codes, for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define LED_PIN 1

void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Click upload, then plug in the board according to the hint.

Micronucleus and bootloader update

While uploading, my version of board throws the following error:

1
2
3
Warning: device with unknown new version of Micronucleus detected.
This tool doesn't know how to upload to this new device. Updates may be available.
Device reports version as: 2.2

Update micronucleus

Compile the micronucleus cli from GitHub - micronucleus, or download from its release page

Overwrite the old version in ~/.arduino15/packages/digistump/tools/micronucleus/

Now try to uplaod the code again.

In case of permission error:

1
Permission denied. For Linux, copy file https://github.com/micronucleus/micronucleus/blob/master/commandline/49-micronucleus.rules to /etc/udev/rules.d

Do what the error message says.

1
2
3
sudo wget https://github.com/micronucleus/micronucleus/blob/master/commandline/49-micronucleus.rules -O /etc/udev/rules.d/49-micronucleus.rules

sudo udevadm control --reload-rules

And the code shall uplaod without problem now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Sketch uses 700 bytes (11%) of program storage space. Maximum is 6012 bytes.
Global variables use 9 bytes of dynamic memory.
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device (will time out in 60 seconds) ...
> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 2.2
> Device signature: 0x1e930b
> Available space for user applications: 6522 bytes
> Suggested sleep time between sending pages: 7ms
> Whole page count: 102 page size: 64
> Erase function sleep duration: 714ms
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!

Update bootloader

Get latest bootloader from GitHub - micronucleus/firmware/upgrades/upgrade-t85_default and save it to somewhere you can find.

With the latest micronucleus cli:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
micronucleus --run /path/to/upgrade-t85_default.hex

> Please plug in the device ...
> Device is found!
connecting: 33% complete
> Device has firmware version 2.2
> Device signature: 0x1e930b
> Available space for user applications: 6522 bytes
> Suggested sleep time between sending pages: 7ms
> Whole page count: 102 page size: 64
> Erase function sleep duration: 714ms
parsing: 50% complete
> Erasing the memory ...
erasing: 66% complete
> Starting to upload ...
writing: 83% complete
> Starting the user app ...
running: 100% complete
>> Micronucleus done. Thank you!

Done!

Reference

Use an ATtiny85 with Arduino IDE

Digistump wiki - Linux troubleshooting