Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Programming Orangutans and the 3pi Robot from the Arduino Environment View document on multiple pages. [https://www.pololu.com/docs/0J17] View this document as a printable PDF: orangutan_arduino.pdf [https://www.pololu.com/docs/pdf/0J17/ orangutan_arduino.pdf] 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 2. ATmega168/328-Arduino Pin Mapping . . . . . . . . . . . . 2.a.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 1. Introduction Baby Orangutan B with included header pins soldered in for breadboard installation. The Orangutan LV-168 attached to a 3-AA battery holder. Arduino [http://www.arduino.cc/] is a popular, open-source prototyping platform that makes it easy for people with little electronics experience to get into the world of microcontrollers and embedded programming.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation The Orangutans and 3pi robot offer integrated hardware that Arduinos do not, such as on-board dual motor drivers. This makes them well suited for applications involving control of small- to medium-sized robots. The Orangutan SV-xx8, Orangutan LV-168, and 3pi robot also have integrated pushbuttons, a piezo buzzer, and a removable LCD, all of which are additional features not found on official Arduinos.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 2. ATmega168/328-Arduino Pin Mapping In our standard Orangutan and 3pi documentation, we use the same convention that Atmel uses in its ATmega168/328 datasheet, referring to pins by their associated ports. For example, pin PD7 is pin 7 of port D. This convention is used because each port is controlled by its own AVR registers, and the bits of these registers correspond to individual pins.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 2.a. Orangutan SV-xx8 and LV-168 Pin Mappings 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment Orangutan SV-168 bottom view with dimensions (Arduino pin mapping). 2. ATmega168/328-Arduino Pin Mapping © 2001–2015 Pololu Corporation Orangutan LV-168 bottom view with dimensions (Arduino pin mapping).
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Function Function Arduino Pin mega168 Pin digital I/Os (x8) digital pins 0 and 1 analog inputs 0 – 5 PD0, PD1, PC0 – PC5 analog inputs (x8) analog inputs 0 – 7 PC0 – PC5, ADC6, ADC7 motor 1 control (A and B) digital pins 5 and 6 PD5 and PD6 motor 2 control (A and B) digital pins 3 and 11 PD3 and PB3 red user LED digital pin 1 PD1 green user LED digital pin
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Pin Arduino Pin Orangutan Function Notes/Alternate Functions digital pin 0 digital I/O USART input pin (RXD) digital pin 1 digital I/O connected to red user LED (high turns LED on) USART output pin (TXD) digital pin 2 LCD control line RS external interrupt 0 (INT0) digital pin 3 M2 control line Timer2 PWM output B (OC2B) digital pin 4 LCD control line E USART
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 2.b. Baby Orangutan B Pin Mappings 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Function Function Arduino Pin mega168 Pin digital I/Os (x16) PD0 – PD2, PD4, PD7, digital pins 0 – 2, 4, 7 – 10, 12, 13 PB0 – PB2, PB4, PB5, analog inputs 0 – 5 PC0 – PC5 analog inputs (x8) analog inputs 0 – 7 PC0 – PC5, ADC6, ADC7 motor 1 control (A and B) digital pins 5 and 6 PD5 and PD6 motor 2 control (A and B) digital pins 3 and 11 PD3 and PB3 red user LED
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Pin Arduino Pin Orangutan Function Notes/Alternate Functions digital pin 0 digital I/O USART input pin (RXD) digital pin 1 digital I/O connected to red user LED (high turns LED on) USART output pin (TXD) digital pin 2 digital I/O external interrupt 0 (INT0) digital pin 3 M2 control line Timer2 PWM output B (OC2B) digital pin 4 digital I/O USART external clock
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 2.c. 3pi Robot Pin Mappings General features of the Pololu 3pi robot, top view. 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Labeled bottom view of the Pololu 3pi robot. 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Specific features of the Pololu 3pi robot, top view. 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Function Function free digital I/Os (x3) (remove PC5 jumper to free digital pin 19) Arduino Pin digital pins 0, 1, 19 mega168 Pin PD0, PD1, PC5 free analog inputs (if you remove jumpers, x3) analog inputs 5 – 7 PC5, ADC6, ADC7 motor 1 (left motor) control (A and B) digital pins 5 and 6 PD5 and PD6 motor 2 (right motor) control (A and B) digital pins 3 and 11 PD3 and
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pin Assignment Table Sorted by Pin 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment Arduino Pin Orangutan Function © 2001–2015 Pololu Corporation Notes/Alternate Functions digital pin 0 free digital I/O USART input pin (RXD) digital pin 1 free digital I/O connected to red user LED (high turns LED on) USART output pin (TXD) digital pin 2 LCD control line RS external interrupt 0 (INT0) digital pin 3 M2 control line Timer2 PWM output B (OC2B) digital pin 4 LCD control line E USART external clock input/out
Programming Orangutans and the 3pi Robot from the Arduino Environment 2.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 3. Configuring the Arduino Environment The configuration instructions in this section explain how to alter the Arduino IDE so that it programs your Orangutan or 3pi robot using the correct settings via our USB AVR Programmer [https://www.pololu.com/product/ 1300], and provides a series of libraries that can help you interface with onboard hardware on your device. 1. Go to http://www.arduino.
Programming Orangutans and the 3pi Robot from the Arduino Environment • PololuArduinoLibraries-080826 PololuArduinoLibraries-080826.zip?file_id=0J127] 3. Configuring the Arduino Environment © 2001–2015 Pololu Corporation [https://www.pololu.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 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...
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Select the programmer: If you are using a Pololu USB AVR Programmer, select “Pololu USB AVR Programmer” in the Programmer menu. Otherwise, consult the documentation of your programmer to find out which option to select. Select the programmer’s serial port: 4.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation If you are using a Pololu USB AVR Programmer, make sure you have installed the proper drivers (see the programmer’s user’s guide [https://www.pololu.com/docs/0J36]) 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.
Programming Orangutans and the 3pi Robot from the Arduino Environment 4.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 5. Arduino Libraries for the Orangutan and 3pi Robot Note: Because the Orangutans were not designed as official Arduino boards, and run at 20 MHz instead of 16 Mhz, not all existing Arduino library code will be directly compatible with them. Also, Orangutan-specific libraries might conflict with existing Arduino libraries if the two are competing for the same hardware peripherals (e.g.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This section provides a series of Orangutan-specific libraries that will allow you to easily interface with the Orangutan/3pi hardware from the Arduino environment. It is important to note that the Baby Orangutan B is a hardware subset of the larger Orangutan SV-xx8 and LV-168, and these Orangutans are (almost) a hardware subset of the 3pi robot.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage examples Most libraries come with at least one example sketch that demonstrates how the library can be used. To load an example sketch, open the Arduino IDE and go to File > Examples > Orangutan____. The Pololu3pi library comes with several detailed line-following and maze-solving example sketches that can be loaded using File > Examples > Pololu3pi.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library provides a set of methods that can be used to read analog voltage inputs, as well as functions specifically designed to read the value of the trimmer potentiometer (on the 3pi robot [https://www.pololu.com/product/975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], Orangutan LV-168 [https://www.pololu.com/product/775], and Baby Orangutan B [https://www.pololu.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanAnalog Methods Complete documentation of this library’s methods can be found in Section 2 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with two example sketches that you can load by going to File > Examples > OrangutanAnalog. The example sketches that come with the OrangutanMotors library also make limited use of this library. 1.
Programming Orangutans and the 3pi Robot from the Arduino Environment } © 2001–2015 Pololu Corporation delayMicroseconds(avg + 1); 2. OrangutanAnalogExample2 Intended for use on the Orangutan LV-168. Note that it will run on the 3pi robot and Orangutan SV-xx8, but the displayed temperature will be incorrect as the analog input connected to the temperature sensor on the Orangutan LV-168 is connected to 2/3rds of the battery voltage on the 3pi and to 1/3rd of the battery voltage on the Orangutan SV-xx8.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library allows you to easily control the piezo buzzer on the 3pi robot [https://www.pololu.com/product/975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], and Orangutan LV-168 [https://www.pololu.com/product/ 775].
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanBuzzer Methods Complete documentation of this library’s methods can be found in Section 3 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with three example sketches that you can load by going to File > Examples > OrangutanBuzzer. 1. OrangutanBuzzerExample Demonstrates one way to use this library’s playNote() method to play a simple melody stored in RAM. It should immediately start playing the melody, and you can use the top user pushbutton to stop and replay the melody.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 100, 25, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 375, 125, 250, 375, 250, 250, 125, 250, 167, 167, 167, 250, 125, 125, 125, 250, 125, 125, 375, 375, 125, 250, 375, 250, 250, 125, 250, 167, 167, 167, 250, 125, 125, 125, 250, 125, 125, 375, 250, 125, 125, 125, 250, 125, 125, 125, 125, 125, 125, 125, 125, 125, 250, 125, 125, 125, 250, 125, 125, 200, 50, 100, 25, 500, 250, 125, 125, 125, 250, 125, 12
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation #include #include #include /* * OrangutanBuzzerExample2: for the Orangutan SV-xx8, Orangutan LV-168, * and 3pi robot * * This example uses the OrangutanBuzzer library to play a series of notes on * the buzzer. It uses the OrangutanPushbuttons library to allow the user * select which melody plays.
Programming Orangutans and the 3pi Robot from the Arduino Environment } } © 2001–2015 Pololu Corporation lcd.print("stopped"); } else { buzzer.playNote(NOTE_A(5), 200, 15); lcd.print("note A5"); } 3. OrangutanBuzzerExample3 Demonstrates the use of this library’s playMode() and playCheck() methods. In this example, automatic play mode is used to allow the melody to keep playing while it blinks the red user LED.
Programming Orangutans and the 3pi Robot from the Arduino Environment // (the remaining two should #define WORKING_CORRECTLY //#define ALWAYS_AUTOMATIC //#define ALWAYS_CHECK be // // // © 2001–2015 Pololu Corporation commented out) this is the right way to use playMode() playMode() is always PLAY_AUTOMATIC (timing is inaccurate) playMode() is always PLAY_CHECK (delays interrupt the sequence) OrangutanLEDs leds; OrangutanBuzzer buzzer; OrangutanLCD lcd; #include
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation 5.c. OrangutanLCD - LCD Control Library 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library gives you the ability to control the 8×2 character LCD on the 3pi robot [https://www.pololu.com/product/ 975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], and Orangutan LV-168 [https://www.pololu.com/product/775].
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanLCD Methods Complete documentation of this library’s methods can be found in Section 5 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with two example sketches that you can load by going to File > Examples > OrangutanLCD. Note that most of the other libraries have example sketches that use the LCD, so please see these for more OrangutanLCD usage examples. 1. OrangutanLCDExample Demonstrates shifting the contents of the display by moving the word “Hello” around the two lines of the LCD.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation #include #include #include // used for its "random" and "srandom" functions /* * OrangutanLCDExample2: for the Orangutan SV-xx8, Orangutan LV-168 or 3pi robot * * This example uses the OrangutanLCD library to display custom characters on * the LCD. Simply push a any user pushbutton to display a new, randomly * chosen mood character.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation lcd.loadCustomCharacter(happy, 0); lcd.loadCustomCharacter(sad, 1); lcd.loadCustomCharacter(indifferent, 2); lcd.loadCustomCharacter(surprised, 3); lcd.loadCustomCharacter(mocking, 4); lcd.clear(); // must be called before we can use the custom chars lcd.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library allows you to easily control the LED(s) on the 3pi robot [https://www.pololu.com/product/975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], Orangutan LV-168 [https://www.pololu.com/product/775], and Baby Orangutan B [https://www.pololu.com/product/1220].
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanLEDs Methods Complete documentation of this library’s methods can be found in Section 6 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with an example sketch that you can load by going to File > Examples > OrangutanLEDs. 1. OrangutanLEDExample Alternately blinks the red and green LEDs on the Orangutan SV-xx8, Orangutan LV-168, or 3pi robot.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library gives you the ability to control the motor drivers on the 3pi robot [https://www.pololu.com/product/ 975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], Orangutan LV-168 [https://www.pololu.com/product/ 775], and Baby Orangutan B [https://www.pololu.com/product/1220].
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanMotors Methods Complete documentation of this library’s methods can be found in Section 7 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with two example sketches that you can load by going to File > Examples > OrangutanMotors. 1. OrangutanMotorExample Demonstrates controlling the motors using the trimmer potentiometer and uses the red LED for feedback. #include #include #include
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation #include /* * OrangutanMotorExample2 for the 3pi robot, Orangutan LV-168, * and Orangutan SV-xx8. * * This example uses the OrangutanMotors and OrangutanLCD libraries to drive * motors in response to the position of user trimmer potentiometer * and to display the potentiometer position and desired motor speed * on the LCD.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library allows you to easily interface with the three user pushbuttons on the 3pi robot [https://www.pololu.com/product/975], Orangutan SV-xx8 [https://www.pololu.com/product/1227], and Orangutan LV-168 [https://www.pololu.com/product/775] by either polling for the state of specific buttons or by waiting for press/ release events on specifiable buttons.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation OrangutanPushbuttons Methods Complete documentation of this library’s methods can be found in Section 9 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with an example sketch that you can load by going to File > Examples > OrangutanPushbuttons. 1. OrangutanPushbuttonExample Demonstrates interfacing with the user pushbuttons. It will wait for you to push either the top button or the bottom button, at which point it will display on the LCD which button was pressed.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Overview This library allows you to easily interface with the five infrared reflectance sensors on the 3pi robot [https://www.pololu.com/product/975]. Note that in order to use this library, you must also include PololuQTRSensors.h in your sketch. You should have something like the following at the top of your sketch: #include #include #include #include
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Pololu3pi Methods Complete documentation of this library’s methods can be found in Section 19 of the Pololu AVR Library Command Reference [https://www.pololu.com/docs/0J18]. 5.
Programming Orangutans and the 3pi Robot from the Arduino Environment © 2001–2015 Pololu Corporation Usage Examples This library comes with three example sketches that you can load by going to File > Examples > Pololu3pi. There is a simple line-following example, a more advanced PID-based line-following example, and a basic maze-solving example.