AeroQuad 2.4.2 – Barometer with the Uno

James Young · July 8, 2011

I picked up a BMP-085 barometer breakout board for my quadcopter last week.  I decided to pick up one because the new AeroQuad 2.4.2 code is able to be compiled to support altitude hold and be able to fit on an Arduino Uno.

However, there’s an issue.  Apparently the version of the Optiboot bootloader that comes with the Uno has a bug in it where it reserves flash RAM equal to the biggest bootloader (~2k or so), even though Optiboot only takes up 512 bytes.  This means that if your sketch compiles to over ~30k, you can compile but you can’t upload.  You get a very obtuse error message.

There’s a way to fix this though.  Make use of the ArduinoISP I made earlier to reflash the bootloader!

There’s a fixed version of Optiboot that allows upload, but I realized that I could upload the Aeroquad binaries directly to the Arduino and bypass the bootloader entirely, and then I could use the entire 32k flash (!).  Optiboot be damned.

In order to do this, you’ll need to get hold of your compiled code in .HEX format.  The easy way to do this is to hit Ctrl-R in the Arduino IDE, then use Windows Explorer to browse to %TEMP% .  Look around for a folder called buildtmp.XXXXXX where XXXXXX is some random gibberish.  Inside of that will be a copy of all the AeroQuad code source files, a bunch of .o files, and a single .HEX file.  This is what you want.  Copy it somewhere.

After that’s done, you can use avrdude in the Arduino IDE kit to flash the Arduino directly.  The following command assumes you’re using the ArduinoISP and it’s connected to COM4.  It also assumes that the .HEX file is in c:\arduino, and you’ve installed the Arduino IDE as displayed.

C:\arduino\hardware\tools\avr\bin>avrdude -pm328p -cstk500v1 -b19200 -PCOM4 -v -C ..\etc\avrdude.conf -e -U flash:w:\arduino\aeroquad.hex
avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         System wide configuration file is “..\etc\avrdude.conf”
         Using Port            : COM4
         Using Programmer      : stk500v1
         Overriding Baud Rate  : 19200
         AVR Part              : ATMEGA328P
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ———– —- —– —– —- —— —— —- —— —– —– ———
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.04s
avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: erasing chip
avrdude: reading input file “\arduino\aeroquad.hex”
avrdude: input file \arduino\aeroquad.hex auto detected as Intel Hex
avrdude: writing flash (31406 bytes):
Writing | ################################################## | 100% 36.19s
avrdude: 31406 bytes of flash written
avrdude: verifying flash memory against \arduino\aeroquad.hex:
avrdude: load data flash data from input file \arduino\aeroquad.hex:
avrdude: input file \arduino\aeroquad.hex auto detected as Intel Hex
avrdude: input file \arduino\aeroquad.hex contains 31406 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 36.03s
avrdude: verifying …
avrdude: 31406 bytes of flash verified
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK
avrdude done.  Thank you.</p>

C:\arduino\hardware\tools\avr\bin></span>

</blockquote>



Ta-da!  After that's finished, you should have the AeroQuad code running on a Uno, with no bootloader.  One advantage with this technique is I'm pretty sure you can compile it to have BatteryMonitor, AltitudeHold and use DCM instead of ARG, which is a better flight algorithm.

Flight testing on the weekend 🙂

Twitter, Facebook