Author Topic: micronucleus, a 2.07kb usb bootloader for attiny85 chips  (Read 17688 times)

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
micronucleus, a 2.07kb usb bootloader for attiny85 chips
« on: September 26, 2012, 11:59:14 pm »
For those of you who already have experience with attiny85 chips, and have an ISP programmer at hand, I have a new project I think you might be interested in! It's a usb 2.07kb bootloader for tiny85: https://github.com/Bluebie/micronucleus-t85 - with this you can get a head start playing with tiny85's with reset pin enabled.

You'll never guess where it's being used. I intend to get it to 2.0kb in a future software update too!
« Last Edit: September 26, 2012, 11:59:14 pm by Bluebie »

ukonline2000

  • Newbie
  • *
  • Posts: 2
micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #1 on: September 27, 2012, 01:27:19 am »
@Bluebie this bootloader  compatible with the digispark? Have compare easy use tutorial? :)

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #2 on: October 03, 2012, 01:54:37 am »
No tutorials yet. If you don't already have a pretty good idea of how to hook up a V-USB device you should probably wait for digisparks to ship :)

Micronucleus bootloaded tiny85 chips are perfectly compatible with the digispark arduino software.
« Last Edit: February 18, 2013, 04:49:56 pm by Bluebie »

psergiu

  • Newbie
  • *
  • Posts: 3
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #3 on: February 18, 2013, 07:37:08 am »
Now that we have our DigiSparks, anyone has any tutorial on how to upload micronucleus to a bare ATtiny85 using only a DigiSpark ?
Thanks.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #4 on: February 18, 2013, 04:49:01 pm »
If you have a dedicated AVR programmer, go right ahead and use that to upload micronucleus-t85/firmware/releases/micronucleus-1.05.hex, then set the fuses to: lfuse = 0xF1, hfuse = 0x5F, efuse: 0xFE


If the above doesn't mean anything to you, follow the littlewire tutorial to install the littlewire programmer software in to one of your digisparks. Next, install avrdude on your computer somehow. For Mac's, install the latest version of CrossPack. Download this https://github.com/Bluebie/micronucleus-t85 (the ZIP button) and open a command line or terminal.


In the terminal type "avrdude -c usbtiny -p t85 -U flash:w:" then drag in the micronucleus-1.05.hex file from firmware/releases in the zip you downloaded.


Next, get your attiny85 chip and stick it down on a breadboard. Use jumpers to connect it to your digispark, connecting every pin for pin. Looking at the chip with the little indented circle in the top left, the pins start at bottom right with D0 and then go up that side D1 and D2 - connect all of these with wires, and connect the top right pin to 5v. On the left side connect the bottom left pin to gnd, and the top right pin goes to D5.


Now go back in to your terminal and press enter on that command we setup before. avrdude will talk over USB to the littlewire software, which will translate commands across to upload the micronucleus firmware in to the chip.


Once avrdude has finished uploading and verifying micronucleus on the chip we need to change the fuses. To do this, enter the following command: "avrdude -c usbtiny -p t85 -U lfuse:w:0xf1:m -U efuse:w:0xfe:m -U hfuse:w:0x5f:m". After this command you will no longer be able to use your ISP programmer on this chip- the reset pin has been disabled so you can use it as IO (it is D5).


Next, you'll need to wire up a USB connector to your chip in the usual way with resistors and zenner diodes. If you search the web for 'V-USB' you can find heaps of examples. The chip we're using needs to be wired up like the digispark - two zenner diodes, three resistors, connecting the D3 and D4 pins to the USB data wires. You can see a simplified schematic for this sort of setup on the littlewire.cc download page. Note that the particular resistor values aren't very strict. Many USB projects use 68 ohm resistors where the littlewire uses 27 ohm, and the 1.2kohm in the littlewire circuit is usually 1.5kohm. Try using whatever resistors you can which are close to those values. The zener diodes are much stricter. Get the lowest wattage zener diodes you can. These ones are known to work well. If you can't wait, try the circuit without zeners - some computers will put up with it, some wont!


I recommend against running the tiny85 chip at less than 4v (which is sometimes a hack used to do without the zener diodes) because once when I was running a chip at 3v it became bricked, and I had to replace it. Maybe you'll be luckier, and maybe 3.6v isn't so bad, but I still dislike this method as it runs the chip totally out of spec.


Anyhow, once you've done all that stuff you should be able to upload sketches to your chip from the digispark arduino software just like the real thing!

semicolo

  • Full Member
  • ***
  • Posts: 137
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #5 on: February 19, 2013, 07:20:55 am »
Maybe using 12.8MHz instead of 16.5MHz would increase the chances of the chip running correctly below 4V, it's only 28% more than the recommended clock, whereas 16.5 is 65% more.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #6 on: February 19, 2013, 03:21:41 pm »
V-USB recommend running at 16.5mhz. Some chips can reach 12.8mhz, some cannot. 16.5mhz is attainable on all attiny85 chips. Tuning 16.0mhz up to 16.5mhz is not as much of a stretch as tuning 8mhz up to 12.8mhz. Aside from that all digispark software is currently configured to run best at 16.5mhz.

semicolo

  • Full Member
  • ***
  • Posts: 137
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #7 on: February 20, 2013, 06:29:26 am »
Ah yes it must be using the high speed PLL at 16MHz and not the internal RC oscillator and the safe voltage is 3.8V or more for this speed.
I didn't realize the chip had to go from 8MHz up to 12.8.
I need to spend more time with the tiny datasheet, I'm more used to the atmega one.

What about tuning 16MHz down to 12.8?

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #8 on: February 20, 2013, 08:12:42 pm »

I don't know you can try it if you like. I don't think it's useful for digispark though. 16.5mhz is a better clock speed. Closer to 16.0mhz which is more useful with existing arduino libraries. Just don't upload stuff to the bootloader when it isn't running on USB power at 5v. That doesn't seem so hard to me?

fr

  • Newbie
  • *
  • Posts: 17
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #9 on: March 08, 2013, 01:07:43 am »
Bonjour Bluebie,

Je suis très intéressé par micronucleus en version windows mais j'aurais besoin d'un tutoriel d'installation plus pour les nuls
J'ai un ATtiny85 neuf, un
http://dx.com/p/usb-isp-programmer-for-atmel-avr-atmega-attiny-51-board-148046
pas à pas qu'est-ce que je fais ensuite ? 

Hello Bluebie,

I am very interested in micronucleus windows version but I need a installation tutorial for dummies
I have a new ATTINY85 a
http://dx.com/p/usb-isp-programmer-for-atmel-avr-atmega-attiny-51-board-148046
step by step what I do next?

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: micronucleus, a 2.07kb usb bootloader for attiny85 chips
« Reply #10 on: March 08, 2013, 02:57:52 pm »
In the next version of the Digispark Arduino software, set to be released any day now, you'll be able to wire up your chip to the ISP in the usual way, choose your ISP type in Tools > Programmer, then select Tools > Burn Bootloader. This currently doesn't work. Alternatively you can simply use the File > Upload Using Programmer option to upload directly without a bootloader. Uploading via a programmer tends to be slower, but it means you don't need to make a USB connector (three resistors and two zenner diodes, though on some computers you can get away with it without the zenner diodes).


Please make sure your ATtiny85 is the 20 variety, and not an ATtiny85v-10. The v version is low voltage and is totally out of spec for USB stuff like the micronucleus bootloader. It might work, but I have never tried it and certainly couldn't endorse it.



Uploading micronucleus another way is very tedious to explain and I can't be bothered, so either wait a few days for the new software or find an existing tutorial on uploading .hex files to chips using avrdude. You can find avrdude included in the digispark arduino software in tools > hardware > avr > bin. Download a zip of the micronucleus project at https://github.com/Bluebie/micronucleus-t85 and upload firmware/releases/micronucleus-1.06.hex, then set the fuses using avrdude again with these options: -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m, or if you want to be able to use the reset pin for IO like on the digispark use -U lfuse:w:0xe1:m -U efuse:w:0xfe:m -U hfuse:w:0x5d:m. I'd suggest running the first version first and making sure your chip is working, because once you disable the reset pin you'll not be able to use your ISP programmer anymore to control the chip so if it isn't working, you effectively wasted a chip unless you can reset it with a tiny fuse resetter circuit or a HVSP.


Once you have done this upload, you'll need to wire up the chip to a USB port using a circuit similar to this: http://littlewire.cc/downloads.html - the 27 ohm resistors are usually 68 ohm in V-USB circuits, but it's pretty loose so use something around 27-100ish. The 1.2k resistor is usually 1.5kohm, but I've seen circuits work with resistors as low as 750ohm. So you can get away with a lot of different values here. Pick something close to 1.5kohm and you should be fine. The zenner diodes have very strict requirements. You must use zenner diodes with a low wattage rating. For through-hole zenners probably the best you will find are 0.25watt ones. The USB connection will probably not work at all with zenner diodes with a wattage rating over 0.5!!! The zenner diodes should also be exactly 3.6v. And like I said above, the circuit works on some computers without any zenners, so it's not the most important thing. If you're not able to get zenner diodes you can try running the chip out of spec at a lower voltage. I don't recommend you do this if you disable the reset pin, because there is an increased risk of the bootloader bricking itself. Certainly running the chip at around 2.8v I had the bootloader brick in one case. 3.6v maybe alright. You can connect two regular diodes in series to bring the USB 5v supply down to about 3.6 volts ish. This works for many V-USB projects but runs the chip completely out of spec. Because the chip is out of spec it is not necessarily going to always be a turing machine, so it may do random stuff, including overwrite bits of itself with junk corrupting the bootloader.