There are a few different ways of getting firmware onto one of AVR’s ATtiny85 microcontrollers, including bootloaders that allow for firmware to be updated without the need to plug the chip into a programmer. However, [casanovg] wasn’t satisfied with those so he sent us a tip letting us know he wrote an I2C bootloader for the ATtiny85 called Timonel. It takes into account a few particulars of the part, such as the fact that it lacks a protected memory area where a bootloader would normally reside, and it doesn’t have a native I2C interface, only the USI (Universal Serial Interface). He’s just released the first functional version for the ATtiny85, but there’s no reason it couldn’t be made to work with the ATtiny45 and ATtiny25 as well.
Timonel is designed for systems where there is a more powerful microcontroller or microprocessor running the show (such as an ESP8266, Arduino, or even a board like a Raspberry Pi.) In designs where the ATtinys are on an I2C bus performing peripheral functions such as running sensors, Timonel allows the firmware for these peripheral MCUs to be updated directly from the I2C bus master. Embedded below is a video demo of [casanovg] sending simple serial commands, showing a successful firmware update of an AVR ATtiny85 over I2C.
The ATtiny85 tends to show up a lot in many diminutive projects, like this Tiny Function Generator and Business Card Tetris.
I didn’t learn anything from watching the video, but at least it had good music. “Suzi Quatro & Chris Norman – Stumblin’ In”, check it out on youtube.
there is this one too: https://github.com/3devo/AtTinyBootloader
Yes “but” (there’s always a “but” with I2C on the Tiny85 due to its lack of dedicated HW), as the readme explains:
“This code only supports the attiny841 and attiny441 (only 841 was tested) with TWI hardware. Some attempts have been made to also support attiny24/44/84 with USI hardware, which worked (see the two-wire-usi branch), but due to some of the polling required this was a bit less robust.”
I’ve searched a lot in the hope of being able to use a bootloader ready and tested, but none worked directly on the Attiny85 for one reason or another, that’s why I’ve written this. I really don’t enjoy reinventing the wheel :)
The video on the AMP version I broken
Why I2C, needing 2 wires, rather than the usual serial, needing one? Less code in the serial case too, I’d imagine.
The whole point is that there is bidirectional communication between the master processor and the slave nodes… I2C doesn’t need that much code either even if you were just bitbanging it and in this case there is the USI doing most of it.
Most bootloaders also do verification that it was flash correctly… which can’t be done with just a single serial line.
Technicallyyyyyyy you could do it with half-duplex serial in one line, but the real advantage of doing it with i2c is alluded to in the article – being able to program multiple devices on the same bus with different code.
Technicallyyyyyyy you could use a higher layer protocol to make it an addressable multipoint bus. Synchronous buses are considered to be more robust.
Not the author, can only guess: b/c he’s using the Tiny85 as an I2C slave/device and wants to be able to update the firmware in place. Darn convenient if you think about it.
Your guess is correct, I’m working on a small project where the Tiny85 is used as a kind of “I2C-controlled AC mains handling device” (it is in charge of the zero- crossing detection, PWM output, and measures the consumed AC mains current with its ADC). The I2C master, in this case, is an ESP8266 upgradeable by OTA, so with this boot manager, the Tiny85 FW can also be updated wirelessly.
Bah, that’s nothing. I needed a CEC bootloader for one of my projects:
https://github.com/russdill/smart-cec/blob/master/cec_bl.S
Takes up 296 bytes, or 5 64 byte erase blocks, so it runs fine on an attiny45. CEC is the HDMI 1-wire communication protocol, it’s rather slow so it takes about 3 minutes to program 4kB.
That’s awesome. I wonder if we need to do an “odd AVR bootloader roundup” piece.
Are there devices this would support that offer more GPIOs and ADCs—like the ATMega328P? I had wanted to connect a Pi to an Arduino via I2C and have the ability to flash it over that I2C channel for remote upgrades.
I haven’t used any of these, but:
https://code.google.com/archive/p/raspy-juice/wikis/Bootloader.wiki
https://github.com/mihaigalos/miniboot
are two of the first few hits when searching “avr i2c bootloader”.
It’s a _lot_ easier on the Mega328 b/c it has a dedicated bootloader memory area and I2C peripheral hardware. The OP’s hack to get one on a Tiny85 is cool / more involved.