4. Using the Arduino IDE: Blinking an LED

Now it’s time to take the Arduino IDE for a spin. Our first goal will be to load a simple LED-blinking sketch (Arduino program) onto our Orangutan or 3pi.

Open the Arduino IDE and create the following sketch:

/*
 * Blink
 *
 * The basic Arduino example, modified to work for Orangutans.  
 * Turns on an LED for one second, then off for one second, 
 * and so on...  We use pin 1 because Orangutans have an LED
 * on PD1, which corresponds to Arduino pin 1.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

int ledPin = 1;                 // LED connected to digital pin 1 (PD1) on Orangutans

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
} 

Either copy the above text into a new, blank sketch, or download this sketch as OrangutanBlinkExample.pde (1k pde) and open it in the Arduino IDE.

Select one of our specially-created boards using the Tools > Board menu:

Select the programmer:

If you are using a Pololu USB AVR Programmer, select “AVR ISP v2” in the Programmer menu. Otherwise, consult the documentation of your programmer to find out which option to select.

Select the programmer’s serial port:

If you are using a Pololu USB AVR Programmer, make sure you have installed the proper drivers (see the programmer’s user’s guide) and have connected it to your computer. Once this is done, you should be able to see its COM port listed under the Tools > Serial Port menu. If you don’t know which COM port your programmer is on, you can determine this by bringing up your computer’s device manager and expanding the Ports (COM & LPT) list. To bring up the device manager, right-click on “My Computer” and select Manage, then click the Device Manager option listed on the left side under System Tools. Look for the port that says “Pololu USB AVR Programmer Programming Port”.

If you are using a true USB programmer (i.e. one that does not emulate a serial port), you shouldn’t need to select a serial port.

Program your Orangutan or 3pi with the sketch:

Connect your programmer to the Orangutan or 3pi via its six-pin ISP header, making sure that pin 1 of the programmer lines up with pin 1 of the target’s programming header. The Orangutan SV-xx8, Orangutan LV-168, and 3pi each have a shrouded header that will enforce correct pin orientation, but the Baby Orangutan B does not. Pin 1 on the Baby Orangutan is marked by a copper arrow on the PCB and pin 1 on our USB AVR Programmer is marked by a raised plastic triangle on the IDC connector.

With the programmer connected to both your computer and your Orangutan or 3pi, click the Upload to I/O Board button (circled in the screen capture below) or press Ctrl+U to compile the sketch and upload it to your target device. The status bar at the bottom of the window will say “Uploading to I/O Board…” while the upload is in progress and will read “Done uploading.” when the upload is complete. If everything has worked correctly you should now see the target’s red user LED blinking on and off every second. Please note that if you are using a 3pi and have not yet soldered in the optional through-hole LEDs, you will need to look at the underside of the robot to see the flashing LED.