Error compiling line following code for 3pi

I am using an Intel Macbook Pro on OS X 10.5.4. I am currently trying to configure the Arduino 0017 software to program my 3pi robot through my Orangutan programmer.
The blinking LED code tends to work, but anything in the code library I downloaded from your site has an issue compiling. This particular error message came up when I attempted to upload the Simple3piLineFollower example:

Is there a way you can help me figure this out?



The Arduino version of the Pololu library hasn’t been updated in a while. There are pin macros like PD1 defined for the ATmega168, which the 3pi was originally based on, but the newer ATmega328 (which is presumably on your 3pi) instead uses defines like PORTD1. Can you try editing the library code to replace PD3 with PORTD3, PD5 with PORTD5, PD6 with PORTD6, and PB3 with PORTB3?

You will have to make similar changes to get other parts of the library to compile, too.

- Ben

OK, I did that to some library codes like the LCD, pushbutton and buzzer codes, and the LCD code worked for a bit but then when I tried the buzzer, I got an error message. The same message came up when I tried the LCD code again, and it hasn’t worked since then:

It sounds like your programmer isn’t able to talk to the 3pi. Are you using an Orangutan USB programmer? Did the 3pi lose power while programming?

- Ben

Turns out there was an instance where I forgot to turn the robot on when I was uploading a code…
so now I unplugged the USB cord, plugged it back in, and everything seems to be working fine.

I’m glad to hear the solution was simply to cycle power on the programmer. If it had been caused by a loss of power while programming, you’d probably have needed to send the unit back to us to have the MCU replaced. This is why we recommend that users put code in all their programs that displays the battery level to the LCD (like we have in our sample 3pi programs) so they can tell when the batteries are getting low.

- Ben

Hi there,

I’m now starting to learn how to use the Ladyada’s Waveshield for Arduino and to do so I wrote a simple code that includes Mr. Fat’s code for playing songs off of an SD card.(Sorry for the redundant lines that extend the code but I wanted to make sure I state everything)

#include <dac.h>

//////////CODE between dashed lines are written by Mr. Fat16/////////////
#include "WaveUtil.h"
#include "WaveHC.h"

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're playing

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer*/
int a1 = 8;
int a2 = 9;
int ledPin1 = 13;
int ledPin2 = 12;
int analogPin = 4;

int power = LOW;
int onoff;

int ding = 2;
int dong = 3;
int dingstatecurrent = LOW;
int dongstatecurrent = LOW;
long int dongtimes;//set varieble to store the number of times it donged 
long int dingtimes; //set varieble to store the number of times it dinged 

int lastDebounceTime = 0;
int debounce = 10;

void setup(){
  pinMode(power, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ding, INPUT);
  pinMode(dong, INPUT);

  //------------Mr. Fat16--------------//

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  
//  card.partialBlockRead(true);

  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
  if (part == 5) {                       
    putstring_nl("No valid FAT partition!");

  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?

  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); 
  dirLevel = 0;


void loop(){
 int dingstate = digitalRead(ding);
  int dongstate = digitalRead(dong);
  int photocell = analogRead(analogPin);

  if (dingstate != dingstatecurrent) {                      //if SWITCH1 is ON and it is DARK 
      Serial.print("dingtimes is ");
    // playfile("SOUND3.WAV");
     digitalWrite(ledPin2, HIGH);
     digitalWrite(ledPin1, LOW);
     digitalWrite(ledPin2, LOW);
     lastDebounceTime = millis();
   if ((millis() - lastDebounceTime) > debounce) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:
    dingstatecurrent != dingstate;
  if (dingtimes>=10){
   digitalWrite(ledPin1, HIGH);
     digitalWrite(ledPin2, LOW);
     digitalWrite(ledPin1, LOW);
     digitalWrite(ledPin2, HIGH);

switch (check_switches()) {
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {        // already playing something, so stop it!
    wave.stop();               // stop it
  // look in the root directory and open the file
  if (!, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  // ok time to play! start playback;

After properly installing the libraries I got the same error message :

I had no idea what that means so I tried to look it up online. This thread was the closest I got to, everything else I found was on a way higher complexity level than mine.
I tried to apply what you said earlier so I went through the library files (AF_Wave and WaveHC) but I didn’t find anything close to PD5 that I could change. I tried just stating an int PD5; but that didn’t help either. Based on that, would be able to offer any suggestions. I would greatly appreciate it.



The code you posted isn’t that relevant since the problem is in WaveHC.cpp. You could try changing PD5 to PORTD5 in that file and see if that fixes the problem. The MCU the arduino was originally based on used pin defines like PD5. The newer, larger version of that MCU no longer supports those pin definitions. Instead, it uses pin definitions such as PORTD5, which can cause code written for the atmega168 to not compile on the atmega328. I don’t know if this is your problem, but it seems likely that it is.

- Ben