-
Notifications
You must be signed in to change notification settings - Fork 2
Programming Arduino
(These are general instructions for programming APM, which use simple demo programs to show you the basics. We'll be downloading and using the full APM software in the next step.)
Open the Arduino IDE, go to the File menu, pick Open, navigate to your code folder and load the "sketchfile" you want to use, which is typically the file that has the same name as the folder and ends in {{{.pde}}}. Here, we've loaded the RC input test program, by opening the file {{{!ArduPilotMega_demo.pde}}}:
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/demo.png
Ensure that the board selected in the Arduino IDE Tools menu is Arduino Mega (Atmega1280) or Arduino Mega 2560, depending on whether you have an APM1280 or the newer APM2560 board (you can tell by looking for the 1280 or 2560 on the big chip at the center of the board).
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/board.png
In the Arduino software in the Tools menu make sure you have selected the right serial port (the FTDI cable will create a new one). If you're not sure what com port number your PC assigned to the FTDI cable check in the Windows Device Manager (found in the Control Panel). It will look like this:
http://ardupilot.googlecode.com/svn/images/serialport.png
On a Macintosh you will typically only have one serial port - the one created by the FTDI cable. If you have more than one, you want the one with "ftdi" in its name.
To upload, click the "Upload to I/O board" icon (the little arrow pointing to the right). Nothing should happen for about 30 seconds as the code is compiling, then the !ArduPilot LEDs aside from power will go out as the board is reset and the code downloaded. (If you're using the USB cable via the IMU shield, a yellow LED on the shield will flash quickly while the code is uploading.) In less than a minute, at the bottom of the Arduino IDE the software should report that the sketch was successfully uploaded by reporting "Done uploading".
Note: If you're loading the demo program linked above, you need to open the Arduino serial terminal (icon on the right of the icon row) and set the baud rate to 57600 to see the output. You'll need to have a RC receiver connected to the input pins of APM). Also note that some of the early boards had the fuses in the Atmega 328 chip (PPM encoder) misprogrammed. If so, your board will not read all channels and will show glitchy servo output. If this is the case, please return it to Sparkfun for reprogramming, or reprogram it yourself using this tutorial.
If you are having problems uploading the code (you get a bunch of error messages in red) follow ALL of the debugging tips here.
And remember that it's always a good idea to watch the output of the board in the Arduino IDE's serial monitor (usually 38400 baud). That will tell you what it's doing and is an invaluable debugging aid.
Here's another fun program to run. If you have servos plugged into APM's outputs, this program will make them dance!
<wiki:video url="http://www.youtube.com/watch?v=U0Smrhy1xYg"/>