Burning the Arduino bootloader to an AVR uC can be very useful and maybe even fun, but also a bit tricky. With that said, let me start with a little background; I recently built a couple kits from Bleep Labs, namely the HSS3i and the Nebulophone. Both the HSS3i and the Nebulophone use an ATMega 328p with an Arduino bootloader to get the job done. Dr. Bleep and Gieskes have also both been nice enough to post the source for these projects. Obviously this means we need to play with the source and make these devices do new stuff. This is all great news, but there is a problem. The Nebulophone is a very compact device and doesn’t have a programming header on it. The HSS3i does have a programming header on it, but that doesn’t help me with the Nebulophone. After realizing this I decided to put my modding on the back-burnner and move forward with making both wonderful and horrendous sounds and visuals with my new toys.
After spending copious amounts of time playing with my new toys I decided it was time to give the modding a bit more thought. Like any respectable hacker should I consulted the inter-webs for a solution to my problem, what I found was the Adafruit AVR ISP Shield Kit. This kit would allow me to buy ATMega328ps and burn the Arduino bootloader to them. I also found a link on the Adafruit site that had a few mods to allow you to turn the shield along with an Arduino into a stand-alone programmer, bonus!
I soon received my kit from Adafruit. I opened it up, spread the parts out on my work bench, broke out the iPad and loaded up the build instructions. After looking through the instructions I realized that soldering all of the connections was a bit limiting. I had recently read a Make article about burning the Arduino bootloader on an ATTiny, and I wanted to be able to do that with my new shield kit. That would have been impossible if I soldered all of the wires in the config for a 328p. After giving it a bit of thought I decided to breakout all of the pins on the Zif socket to male headers. I then subbed the standard headers that came with the shield for wire wrap male headers. This new config allows me to use female/female jumper wires to reconfigure the programmer for all sorts of AVRs uCs, basically any AVR with up to a 28-pin DIP package, like the 328p.
After completing assembly of the shield with my new mods it was now time to give it a try. I snagged the AVR ISP Programmer code from the Adafruit Git Hub repo & uploaded it to my Arduino. Next, following the instructions on the Adafruit site, I then placed my new programmer shield on the Arduino, inserted a blank ATMega328p into the nifty Zif socket, paying close attention to its orientation and pulled the lever down to secure the chip. Now that the hardware is all setup I just need to make a couple changes to the Arduino IDE. From the “Tools” menu I moused down to “Programmer” and then selected “Arduino as ISP” from the options. Now I should be all set. Fingers crossed, I then clicked “Tools” again and selected “Burn Bootloader.” I then saw a few blinkinlights on the Arduino followed by an error in the IDE that said the following;
avrdude: stk500_getsync(): not in sync: resp=0x15. I tried a couple more times with the same results at which point I decided to consult Google.
After a bit of searching on Google I came across the post on the Arduino site about the Mega ISP. That page in turn, led me to this Arduino Playground page, where I learned that my problem most likely stemmed from the auto-reset capabilities of the Duemilanove that I am using. Apparently, when AVRDude (and most other programs for that matter) connects to the Arduino’s serial port, the DTR (Data Terminal Ready) line is set and then unset which causes the Arduino to reset. This is a problem because AVRDude wants to start programming immediately but can’t because the chip is resetting. This is the cause of the sync error mentioned above. There were several solutions to this problem listed on the Arduino Playground page (linked to above,) but the easiest was to add a 120 ohm resistor (or a 10uF cap on the Uno) between reset & 5v. This resistor effectively disables the auto-reset function by supplying enough impedance to hold the reset line high, stopping the reset & allowing AVRDude to do it’s business. Since I might use my AVR ISP shield with an Uno one of these days, I decided to add some machine pin headers to the board so I could swap the resistor for a cap, or remove it entirely if necessary.
To wrap things up, I managed to get my programmer working and the mods I’ve made to it make it pretty flexible. I should be able to program ATTiny’s with no problem and I can also use it as a stand alone programmer if I ever need to program lots of AVRs with the same code. Now I can go about modifying the firmware for my Nebulophone and HSS3i and burn it to it’s own 328p so I can swap back and forth between the stock firmware and my own. I’ve included a gallery below with a few more images so you can see exactly what I did to mod the AVR ISP Shield kit if you decided that you’d like to do the same. Please leave any questions (or corrections) that you might have for me in the comments.