
Here's a few quick notes that will help you program your own Arduino-compatible boards for first-time use. This is just for people building their own boards. If you bought ArduPilot or BlimpDuino pre-made, all this has already been done for you, so ignore this.
Here are the necessary steps to load firmware onto the Atmega chip:
1) You'll need an ICSP AVR programmer and a FTDI cable. We recommend
AVRSIP2 [shown] or
USBTinyISP for the former and the
Adafruit cable for the latter. Connect the cable to the ICSP port on your board [on ArduPilot it's the one marked "AT168"]. The red stripe on the cable should be on the same side of the connector as the square solder pad on the back of the board. (On our boards that means that the red strip is on the side closest to the processor)
2) Now you'll need to change (turn off) one of the default "fuse" settings in the Atmega, which divides the internal clock by 8 so it only runs at 1 Mhz. (Explanation of all that and more about fuses are in the excellent Sparkfun tutorial
here). For that you'll need to download some special software. If you have the AVRSIP2 programmer, it came with AVR Studio, which is excellent. If you got the USBTinyISP, I recommend AVRdude, and instructions on how to get and install it are
here.
3) To change the fuse with AVR Studio, connect the programmer and go to Tools/Program AVR/Connect. Choose AVRISP mkII. You may get an error (choose cancel). On the "Main" tab of the dialog, click the "Settings" button and pick 125khz, then click "Write". Then make sure "Device" is ATMega168 and "Read signature". At the bottom it should say that all's okay. If so, switch to "Fuses" tab and uncheck CKDIV8. Press "Program", then "Verify" to make sure it's working. Now you can go back to the "Main" tab and change the Settings to 2Mhz. You processor is working fine and ready to program.
To change that fuse with AVRDude call up the Windows command line CMD and enter the following command (this assumes you're using the USBTinyISP programmer; if you're using the AVRISP2, substitute "avrispv2" for "usbtiny"): avrdude -p m168 -c usbtiny -U lfuse:w:0xE2:m
4) Now you'll need to burn the bootloader. It's easiest to do this within AVR Studio. Still in the AVR Studio dialog box you used above, go to the Program tab. Where it says "Flash", input the correct bootloader file. For ArduPilot, that's the "ATmegaBOOT_168_diecimila.hex" file in your Arduino hardware\bootloaders\atmega168 folder. For BlimpDuino it's the "ATmegaBOOT_168_pro_8MHz.hex" in the same folder. Click "Program". All should go well and you'll see the OKs below.
If you don't have AVR Studio, you can do this within the Arduino IDE. We've found that it doesn't currently support the AVRISP2 programmer, but it does support the Adafruit one linked above. If you're using a crystal or resonator on your board (to run the processor at 16MhZ), select the Decimila board in the Arduino IDE [Note: this is the mode you should use for ArduPilot]. If you're not using any external frequency generator and are thus running on the Atmega's internal 8 Mhz clock, select "Arduino Pro or Arduino Mini (8mhz)" [Note: this is the mode you should use for BlimpDuino]. Connect the AVR programmer to the ICSP pins on the board and select "Burn Bootloader" with whichever AVR programmer you have. The IDE should freeze for about 15 seconds and then report that it's done that successfully. If it doesn't work despite a few attempts, you may have a wiring problem on the board. Each one of those ICSP pins connects straight to an ATmega pin as shown in the schematics, so it should be pretty easy to diagnose.
5) Now you should be able to upload Arduino sketches (ie, your program) from the IDE. Just remember to make sure you've selected the right board--Decimila if you're using an external frequency generator [ArduPilot] and Arduino Pro if you're not [BlimpDuino]. Both boards now support autoreset when programming, so all you should need to do is to press the "upload to I/O board" button in the Arduino IDE and wait a minute. [If for any reason autoreset isn't working you can manually push the reset button on the board every time you uploading code so the bootloader can "look" for the IDE.].
If this all seems a bit complicated, rest assured it's a lot easier to read and follow these instructions than it is to figure it out yourself over months, like Jordi and I did ;-) And remember, you only have to go through this once. After the Atmega is configured for Arduino, you can let the IDE take over all the hard work.
You need to be a member of DIY Drones to add comments!
Join DIY Drones