Programming the Arduino with the AVR Dragon (an Atmel programming/development board) was something I had to accomplish this week. In the image above the right-hand board is our Firstbot prototype. The Firstbot is an Arduino compatible board. Simply put that means it runs the Arduino bootloader and can be programmed using the Arduino software interface. Hardware connections match the Arduino Uno, and the Atmel chip we used is the ATmega328-AU that matches the Arduino Pro (5V 16MHz version). We’ve added a couple of motor controllers to the board (Freescale MC33926) so that it can easily be used to create a robot running Arduino code. The board on the left is Atmel’s AVR Dragon, a fairly cheap debugger and programmer (PN: ATAVRDRAGON, about $50US).
Using the AVR Dragon to load the Arduino bootloader into our design was pretty straightforward. But I thought a tutorial might be useful to anyone else trying to accomplish the same thing with a custom board, or just trying to get an Arduino reprogrammed with the correct bootloader file.
Preparation: There are a few things to take note of while preparing to program and Arduino with the AVR Dragon. I downloaded/installed Atmel Studio 6.0 to use as the IDE(integrated development environment) for the AVR Dragon. Future iterations of this IDE, or earlier version, will look a little different, so the software pictures below might change. Your board will also need to be connected to the AVR Dragon via the 6 pin in-circuit serial programming header (ICSP). The pinout should connect to your Atmel IC pins with matching names. Pin numbers will differ depending on the IC package and chip part number. The AVR Dragon and Arduino Uno 6 pin headers will match these connections. I used a 2×5 (10 pin) ribbon cable to make this connection (grey cable above) because it was handy. Only 6 connections (2×3) are required.
1 – MISO (master in slave out)
2 – VCC (system voltage)
3 – SCK (serial clock)
4 – MOSI (master out slave in)
5 – RST (reset)
6 – GROUND (ground return)
Your Arduino or compatible board should be powered separately from the AVR Dragon.
For clarification, the AVR Dragon is used to program a bootloader into the Arduino compatible board. A different connection is used to program the Arduino compatible board with the code it will run as its application. For the Arduino Uno this is done with a USB connection. On our board we used an RS232 interface. You can see the jumper wires connected to the back side of our Firstbot board. These connect to the RS232 cable that we used to program the board
Power both boards (AVR Dragon powers through the USB connection, and your Arduino or Arduino compatible board will need to be powered separately. After launching Atmel Studio select Tool/Device Programming from the menu (screen not shown). A new programming window will open (shown below). In this window select AVR Dragon as the tool, select the IC on your board (ATmega328 for our design), and select ISP as the interface. We used the ATmega328, but many Arduinos use the ATmega328P. When these items are selected press the “Apply” button. I also found that the ISP clock on my board needed to be set below the 1MHz default setting. 250KHz worked for me. If you have issues with communication you can try adjusting the ISP clock setting.
Press the read button next to the “Device signature” text box. If the AVR Dragon and your Arduino are correctly connected you should get a hex value back associated with the IC you’re using. You’ll also see a voltage reading for the board about to be programmed. In our case it is 5V.
Prior to programming of the bootloader you’ll need to program the fuses for the Atmel IC to operate correctly. Select the “Fuses” section on the left hand side of the software window. Type in the appropriate fuse value for the Arduino you are programming, or the hardware you are duplicating if it is a custom design. Once entered, hit “Program”. For the Arduino Pro 5V 16MHz the settings are…
EXTENDED – 0x05 HIGH – 0xDA LOW – 0xFF
Your settings may be different. I ran across a lot of warnings on the internet not to program in the wrong values. Since this is a flash part I assume you can always erase the device and start from scratch if you make a mistake. I ran across a web page, Coding with Cody, that had a ton of the fuse settings for various Arduino models. I can’t vouch for all the settings, but the one I used for the Arduino Pro 5V 16MHz did work.
In the “Memories” section selected on the left side of the software window use the browse button (the “…” button right of the Flash text box) navigate to the Arduino bootloader file location. Select the appropriate bootloader file for your application and hit “Program”.
I found the bootloader I needed in the Arduino folder under hardware/arduino/bootloaders/Atmega.
If everything worked your board should start blinking the LED connected to pin 13 (assuming your board has an LED there). That’s a good indicator that the bootloader was loaded into the IC correctly. You’re almost done. Now you can attempt to load an application into your board using the Arduino software interface. A quick test is to modify the example LED blinking code found under File/Examples/Basic/Blink. Just cut the delay numbers in half, and if programming is successful the LED connected to pin 13 will blink twice as fast.
To load the software connect your USB (or other interface) to the Arduino compatible board. Select the appropriate communications port under Tools/Serial Port. Then make sure you pick the right Arduino board model to program. Since we used the ATmega328-AU, and programmed our board with the fuses associated with the Arduino Pro 5V 16Mhz, we needed to select the board type associated with that hardware (shown below).