Skip to content

Instantly share code, notes, and snippets.

@amcolash
Last active April 23, 2024 21:28
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amcolash/b930cb9d206b75ca5fd4ab974cb78a60 to your computer and use it in GitHub Desktop.
Save amcolash/b930cb9d206b75ca5fd4ab974cb78a60 to your computer and use it in GitHub Desktop.
ATTiny85 + micronucleus using an AVR programmer
This gist is a list of instructions that I used to program my ATTiny85s with Micronucleus. They worked for me, but your mileage may vary! I would highly recommend starting by looking at the SparkFun article linked at the bottom for schematics and more in-depth info. This gist is mostly just a copy/paste list.
## Required:
- ATTiny85
- AVR programmer
- 1 uF capacitor
- Micronucleus FW: https://github.com/micronucleus/micronucleus/releases
- avrdude: http://www.nongnu.org/avrdude/
## Setup:
- Attach the avr programmer to the tiny
- Attach cap from GND to RESET (Otherwise try GND <-> V+. I only needed this the 2nd time)
- Plug in AVR programmer
- Download FW and unzip
- Make sure you have avrdude
## Burning:
- `cd micronucleus-master/firmware/releases`
- Burn firmware: `avrdude -P usb -c usbasp -p t85 -U flash:w:t85_default.hex`
- Burn fuses: `avrdude -P usb -c usbasp -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m`
- NOTE: user @german-namestnikov found that the above did not work and instead changed the value of the `CKSEL` bit. Instead they used `avrdude -P usb -c usbasp -p t85 -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m`
- Verify fuses (should read E:FE, H:DD, L:E2): `avrdude -P usb -c usbasp -p t85 -U lfuse:r:-:i`
- Test it works by unplugging from avr, use usb connection
- Go to commandline tool folder: `cd ../../commandline`
- Build + test: `make && micronucleus -?`
## Using with Arduino:
- Add additional board: http://digistump.com/package_digistump_index.json
- Install "Digistump AVR Boards"
- Select board "Digispark Default" and programmer "Micronucleus"
If things don't work it is most likely that the arduino board package does not have the latest micronucleus tool.
To fix, run `cp micronucleus-master/commandline/micronucleus ~/.arduino15/packages/digistump/tools/micronucleus/2.0a4`
Restart Arduino
Cheers!
## Sources:
- https://learn.sparkfun.com/tutorials/how-to-install-an-attiny-bootloader-with-virtual-usb/install-micronucleus
- http://digistump.com/wiki/digispark/tutorials/connecting#software
@german-namestnikov
Copy link

Hi Andrew!
Thanks for such a great gist, it saved a lot of time for me.

During my work, I had no success with fuses -U lfuse:w:0xe2:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m for ATTiny85-20PU, the device couldn't be detected by OS and for every USB plug in I saw "usb 1-1.2: device descriptor read/64, error -32" error message in my dmesg log.

After some play with fuse bits I realized that the next setting works fine for my case: -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m.

It is very strange. As I see, the only change I did is about CKSEL bits, determining whose clock frequency to use in MCU. Could you please explain the fuses selection for your case?

@amcolash
Copy link
Author

amcolash commented Apr 5, 2020

Glad to hear that it helped! The fuses that I used were completely based off of the sparkfun article linked at the bottom. For me, those seemed to work well but I will update to mention your success in the gist. I really have not delved deeply enough into how these fuses work.

@german-namestnikov
Copy link

Thanks!

@hpsaturn
Copy link

hpsaturn commented Sep 4, 2022

Hi, thanks for this help. I have a weird issue, after upload process the board doesn't works. It's dont recognized like other boards like digispark for example.

I think that I have a right output:

(master) avp:releasesȹ avrdude -P /dev/ttyUSB0 -c buspirate -p t85 -U flash:w:t85_default.hex

Attempting to initiate BusPirate binary mode...
avrdude: Paged flash write enabled.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.09s

avrdude: Device signature = 0x1e930b (probably t85)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "t85_default.hex"
avrdude: input file t85_default.hex auto detected as Intel Hex
avrdude: writing flash (8170 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 8170 bytes of flash written
avrdude: verifying flash memory against t85_default.hex:
avrdude: load data flash data from input file t85_default.hex:
avrdude: input file t85_default.hex auto detected as Intel Hex
avrdude: input file t85_default.hex contains 8170 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 8170 bytes of flash verified

avrdude: safemode: Fuses OK (E:FE, H:DD, L:E2)

avrdude done.  Thank you.

But when I disconnect the board from my Bus Pirate and put it for upload my firmware, is not recognized.

I have the next dmesg error:

Sep  4 14:31:34 minisf kernel: [63716.543286] usb 1-2.1.4-port1: attempt power cycle
Sep  4 14:31:34 minisf kernel: [63717.253148] usb 1-2.1.4.1: new low-speed USB device number 25 using xhci_hcd
Sep  4 14:31:34 minisf kernel: [63717.280869] usb 1-2.1.4.1: Device not responding to setup address.
Sep  4 14:31:35 minisf kernel: [63717.520815] usb 1-2.1.4.1: Device not responding to setup address.
Sep  4 14:31:35 minisf kernel: [63717.733167] usb 1-2.1.4.1: device not accepting address 25, error -71
Sep  4 14:31:35 minisf kernel: [63717.929175] usb 1-2.1.4.1: new low-speed USB device number 26 using xhci_hcd
Sep  4 14:31:35 minisf kernel: [63717.956806] usb 1-2.1.4.1: Device not responding to setup address.
Sep  4 14:31:35 minisf kernel: [63718.196790] usb 1-2.1.4.1: Device not responding to setup address.
Sep  4 14:31:35 minisf kernel: [63718.409224] usb 1-2.1.4.1: device not accepting address 26, error -71

It is my setup for upload it:

photo_2022-09-04_12-36-00

@hpsaturn
Copy link

hpsaturn commented Sep 4, 2022

I found the issue, we need put extra options to burning step:

avrdude -P /dev/ttyUSB0 -c buspirate -p attiny85 -U flash:w:t85_default.hex -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

I don't why, but with this line, with fuse burning in the same instruction, it works 👯

@f-zhuk
Copy link

f-zhuk commented Apr 23, 2024

Oh god just thank you

my board cost me 2 bucks and no hassle to get a new one locally, I am just frustrated with tons of useless guides and youtube videos I watched before I got here.
Worked nicely for digispark board, no additional cap used

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