Step 9: Programming
Although I can use an AVR programmer to load code into the microcontrollers, the way I designed the PCB makes it slightly inconvenient. Using a serial port bootloader is easier for this job. So I will use an AVR programmer just once to get the bootloader flashed into the microcontroller first, and use the bootloader the rest of the time.
The AVR programmer must support 3.3V circuits. My USBtinyISP is capable of this, but I needed to supply the 3.3V into it in order for it to know to use 3.3V.
Although the transmitter uses a 2X5 male header connector, YOU MUST NOT PLUG IN THE ISP TO IT DIRECTLY, because the pin mapping does not match. Connect the ISP to this header using wires instead, while following the pin labels carefully. (The adapter I used is from SparkFun, but you can make your own really easily)
First thing to do is to program the fuse bits of the transmitter microcontroller, which tells it to use the 16 MHz crystal, to run the bootloader on reset, and how big the bootloader is.
- lfuse = 0xF7
- hfuse = 0xD8
The bootloader is derived from the Arduino bootloader, I'm using a modified version of the Zigduino port of the Arduino bootloader. Flash the bootloader atmegaboot_picopter.hex file into the transmitter microcontroller.
Note: You may encounter a verification error while trying to flash the bootloader, this appears to be caused by a bug in AVRDUDE where nothing is read back (I was unable to even obtain a basic memory dump) for the ATmega128RFA1 (I don't know if this applies to any other chip). Ignore this error unless you are sure that the bootloader is malfunctioning.
At this point, make sure you've plugged in the transmitter circuit to your computer via USB, and have powered it on. Install the drivers if you need to. Remember the name of the serial port that it shows up as.
The bootloader is activated by placing a jumper between GND and SER<, and then powering on the transmitter circuit. Once activated, the red LED should blink 3 times and green LED will stay on. The green LED will also indicate busy status by blinking really fast (technically it is toggling once per byte).
Before you open up Arduino, you need to add the following entries into Arduino's "board.txt":
Copy the core files inside "picopter_core" into where you install Arduino cores. Copy the bootloader files inside "picopter_boot" into where you install Arduino bootloaders. Copy the libraries "PicopterWiiClassicCtrler" and "PicopterRadio" into where you install Arduino libraries. Copy the sketches "PicopterTransmitter" and "Multiwii_Picopter" into your Arduino sketch folder.
Also since Arduino is built using an outdated version of AVR GCC, it will not support ATmega128RFA1 properly, I had to overwrite the contents of the folder called "tools" with the contents from an up-to-date version of AVR GCC (obtained from MHV AVR Tools).
Open Arduino, open the "PicopterTransmitter" sketch, select the board to be "picopter_station", and select the right serial port. Activate the bootloader on the transmitter, then compile and upload the sketch.
The transmitter firmware has a neat feature: if you do not connect the Wii Classic Controller when you turn it on, it will go into ISP mode (indicated by really fast alternating red-green LED flashing, also flashes when busy), where it becomes another AVR programmer (protocol is stk500v1, baud rate is 115200). So now, connect the quadcopter circuit to the transmitter circuit. Using the command line and AVRDUDE, set the fuses of the quadcopter microcontroller to be:
- lfuse = 0xF7
- hfuse = 0xD9
Open the "MultiWii_Picopter" sketch, select the board to be "picopter_flier", and compile & upload the sketch. You have just programmed the quadcopter firmware using the transmitter.
Note: You might get a verification error while trying to upload firmware to the quadcopter using the Arduino IDE, if you do, then use AVRDUDE in command line to force a chip erase (using the "-e" option) and then try again. This is because Arduino forces the "-D" option while uploading.