Saturday 27 July 2013

Optiboot

The heart of a cheap Arduino clone is an ATmega328 chip. Often sellers of this chip will assume you're going to use it for an Arduino and burn a bootloader onto it before shipping it to you. But what if you get one without a bootloader? What if you want to use a different bootloader, for example Optiboot?

Optiboot is great: it fits inside a single 512-byte sector of flash, freeing up a (sometimes) precious 1.5kB for your programs. It allows downloading at 115200bps, also handy for large sketches. In conjunction with a 100nF capacitor between RTS and RESET, it turns your homebrew clone into an Arduino Uno (from the point-of-view of the IDE anyway).

So (adjusting your avrdude settings accordingly), firstly read the fuse bits:

$ avrdude -q -q -P /dev/ttyUSB0 -b 19200 -c avrisp -p m328p -U hfuse:r:-:h -U efuse:r:-:h -U lfuse:r:-:h
0xda
0x5
0xff

Check this online calculator for the meaning of these bits. In this case, the value of the high bits (0xda) means that 2k is reserved for the bootloader section, we're only going to need 512 bytes:

$ avrdude -q -P /dev/ttyUSB0 -b 19200 -c avrisp -p m328p -U hfuse:w:0xde:m 

Next program the optiboot bootloader (the version shipped with the Arduino IDE is in hardware/arduino/bootloaders/optiboot):

$ avrdude -q -P /dev/ttyUSB0 -b 19200 -c avrisp -p m328p -U flash:w:optiboot_atmega328.hex -U lock:w:0x0f:m

Now when you power up your Arduino clone, you should see a triple-flash on the LED on pin 13 indicating that Optiboot is ready to receive your sketches.

No comments:

Post a Comment