Thursday, February 9, 2012

AVR ISP Flashing ATMEGA328 with Arduino UNO Boards

Okay, so as part of my photo gear hacking fun, I'm working with Arduino UNO boards. Why? Because they are fairly straight forward, fairly forgiving, and have an awesomely easy to use interface.

So, looking around, you can pickup ATMEL atmega328p-pu MCU(s) for a pretty low price. If you want the Arduino bootloader pre-flashed, that's an extra $1+ per chip. Figuring I can just do it myself, I went a bought a bunch from JameCO of California.

Arduino UNO: The AVRisp exception

So, on the site, there is an awesome page for how to use an Arduino board as an AVR ISP programmer for another Arduino:

However, at the top of the page, there is a gotcha:

NOTE: Currently, you cannot use an Arduino Uno as an ISP programmer because the optiboot bootloader does not support this sketch. A revision for this is in progress.
So... after hitting many sites, building countless ISP or bypass circuits on breadboards, and basically banging my head against the wall, I visited this site for the umpteenth time:

And instead of trying to build a breadboard of the ISP circuit, I actually did something reasonable: I read the source code notes provided by WestfW, who wrote the OptiLoader, and you will note it says:

// If the aim is to reprogram the bootloader in one Arduino using another// Arudino as the programmer, you can just use jumpers between the connectors// on the Arduino board. In this case, connect:// Pin 13 to Pin 13// Pin 12 to Pin 12// Pin 11 to Pin 11// Pin 10 (of "programmer") to RESET (of "target" (on the "power" connector))// +5V to +5V and GND to GND. Only the "programmer" board should be powered// by USB or external power. 

OMG!! Well, since I actually had 2 Arduino UNO boards, I made the hookups and plugged in a handle AC adapter. Voila! It flashed the chip in the other board! I tested uploading the blink sketch to the newly Arduino turned chip, and it accepted it. Amazing!

So, for the countless folks out there who are otherwise happy owners of the Arduino UNO board and just want to turn a blank atmega328 into an Arduino atmega328, give OptiLoader a try. It rocks.

Note, the OptiLoader sketch handles putting the optiboot loader onto more than just atmega328(s). Check out the source code for a complete list.

Happy photo gear hacking!


  1. I only have one uno board and blank atmega328p-pu. Is there a way I can flash it using instructions here?

  2. Hey Test,

    Sorry for taking so long to publish and reply to your comment. For some reason, I wasn't getting notifications of comments. :( My bad.

    If you have one UNO board(with a flashed and working atmega168 or 328p mcu) and you want to flash the firmware of a blank atmega328p with new firmware, you can do it with just the one UNO board. However, you will need a breadboard and some extra parts to basically build the minimum bits and pieces of an arduino board(crystal oscillator, caps, some wires to hook things up).

    Now, if you were going to program the new blank chip to be a standalone chip, ie. using the internal oscillator, I found an interesting sketch, which will do what you want. Basically, it has various firmwares loaded into the program memory space and when you hook up the blank chip to the UNO board via their instructions, including a clock signal line, you will be able to reflash the new blank chip using just one UNO board(w/flashed and working arduino software), and a breadboard and wires. No caps, crystals, or other bits required. That chip could then be used standalone.

    To build your own "arduino board" on a breadboard:

    Stand Alone circuit with ISP:

    Arduino as an ISP:

    For a standalone programmer: