Verifying sketch for a 4 wheel drive robot produces undefined reference errors

I recently purchased a Arduino Controlled Robot kit from Oreilly as the result of seeing it advertised in Make magazine. Very cool entry level project. The Robot is assembled and ready to conduct a test of the motors (4) operation. This is a exercise outlined in the book published by Oreilly titled “Make an Arduino Controlled Robot”. The sketch is shown on page 68. I have downloaded the Arduino software. Also, I have downloaded the library from Make an Arduino-Controlled Robot [Book] To run this test I have loaded the program titled “MotorTest4wd”. This application uses the Arduino Leonardo board.
When I attempt to execute a verify compile instruction I recieve errors that I have been unable to resolve. Any help on this issue would be greatly appreciated.
Note when previewing this post i noted that a icon appears after the blink command instead of an 8 followed by a ). I don't understand why.
Thanks- Bob C


/*******************************************

  • MotorTest4wd.ino

  • Initial motor test for 4WD

  • robot rotates clockwise

  • (Left motors driven forward, right backward)

  • Michael Margolis 24 July 2012
    ********************************************/
    const int LED_PIN = 13;
    const int speed = 60; // percent of maximum speed

#include <AFMotor.h> // adafruit motor shield library (modified my mm)
AF_DCMotor Motor_Left_Front(4, MOTOR34_1KHZ); // Motor 4
AF_DCMotor Motor_Right_Front(3, MOTOR34_1KHZ); // Motor 3
AF_DCMotor Motor_Left_Rear(1, MOTOR12_1KHZ); // Motor 1
AF_DCMotor Motor_Right_Rear(2, MOTOR12_1KHZ); // Motor 2

int pwm;

void setup()
{
Serial.begin(9600);
blinkNumber(8); // open port while flashing. Needed for Leonardo only

// scale percent into pwm range (0-255)
pwm= map(speed, 0,100, 0,255);
Motor_Left_Front.setSpeed(pwm);
Motor_Right_Front.setSpeed(pwm);
Motor_Left_Rear.setSpeed(pwm);
Motor_Right_Rear.setSpeed(pwm);
}

// run over and over
void loop()
{
Serial.println("rotate cw");
Motor_Left_Front.run(FORWARD);
Motor_Left_Rear.run(FORWARD);

Motor_Right_Front.run(BACKWARD);
Motor_Right_Rear.run(BACKWARD);

delay(5000); // run for 5 seconds
Serial.println("stopped");
Motor_Left_Front.run(RELEASE); // stop the motors
Motor_Right_Front.run(RELEASE);
Motor_Left_Rear.run(RELEASE); // stop the motors
Motor_Right_Rear.run(RELEASE);

delay(5000); // stop for 5 seconds
}

// function to indicate numbers by flashing the built-in LED
void blinkNumber( byte number) {
pinMode(LED_PIN, OUTPUT); // enable the LED pin for output
while(number--) {
digitalWrite(LED_PIN, HIGH); delay(100);
digitalWrite(LED_PIN, LOW); delay(400);
}
}``

Following are the error statements-

MotorTest4wd.cpp.o: In function ‘_static_initialization_and_destruction_0’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:14: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:15: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:16: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:17: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
MotorTest4wd.cpp.o: In function ‘loop’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:38: undefined reference to ‘AF_DCMotor: ::run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:39: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:41: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:42: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:46: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
MotorTest4wd.cpp.o: C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:47: more undefined references to ‘AF_DCMotor: :run(unsigned char)’follow
MotorTest4wd.cpp.o: In function ‘setup’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:28: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:29: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:30: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:31: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’

For refernce, here is the AFMotor.h file

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

// updated for Arduino 1.0.2 by mem 22 Nov 2012

#ifndef AFMotor_h
#define AFMotor_h

#include <inttypes.h>
#include <avr/io.h>

//#define MOTORDEBUG 1

#define MICROSTEPS 16 // 8 or 16

#if defined(AVR_ATmega8) ||
defined(AVR_ATmega48) ||
defined(AVR_ATmega88) ||
defined(AVR_ATmega168) ||
defined(AVR_ATmega328P)
#define MOTOR12_64KHZ _BV(CS20) // no prescale
#define MOTOR12_8KHZ _BV(CS21) // divide by 8
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS22) // divide by 64

#elif defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
#define MOTOR12_64KHZ _BV(CS10) // no prescale
#define MOTOR12_8KHZ _BV(CS11) // divide by 8
#define MOTOR12_2KHZ _BV(CS11) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS12) // divide by 64

#elif defined(AVR_ATmega32U4) // Leonardo (mem 22 Nov 2012)
#define MOTOR12_64KHZ _BV(CS00) // no prescale
#define MOTOR12_8KHZ _BV(CS01) // divide by 8
#define MOTOR12_2KHZ _BV(CS01) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS02) // divide by 64
#endif

#if defined(AVR_ATmega8) ||
defined(AVR_ATmega48) ||
defined(AVR_ATmega88) ||
defined(AVR_ATmega168) || \
defined(AVR_ATmega328P)
#define MOTOR34_64KHZ _BV(CS00) // no prescale
#define MOTOR34_8KHZ _BV(CS01) // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
#else
#define MOTOR34_64KHZ _BV(CS40) // no prescale
#define MOTOR34_8KHZ _BV(CS41) // divide by 8
#define MOTOR34_1KHZ _BV(CS41) | _BV(CS40) // divide by 64
#endif

#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4

#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3
#define MICROSTEP 4

/*
#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB

#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4

#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7

#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB
*/

// Arduino pin names
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8

class AFMotorController
{
public:
AFMotorController(void);
void enable(void);
friend class AF_DCMotor;
void latch_tx(void);
};

class AF_DCMotor
{
public:
AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
void run(uint8_t);
void setSpeed(uint8_t);

private:
uint8_t motornum, pwmfreq;
};

class AF_Stepper {
public:
AF_Stepper(uint16_t, uint8_t);
void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
void setSpeed(uint16_t);
uint8_t onestep(uint8_t dir, uint8_t style);
void release(void);
uint16_t revsteps; // # steps per revolution
uint8_t steppernum;
uint32_t usperstep, steppingcounter;
private:
uint8_t currentstep;

};

uint8_t getlatchstate(void);

#endif

For refernce, here is the AFMotor.h file

From the messages, that file is not where the IDE expects to find it. Where IS it?

Thanks for your reply.
Both programs are in the same folder. ==> C:\Documents and Settings\Owner\My Documents\Arduino\libraries\MotorTest4wd
I think you may be on to something but not sure how to trace this issue without help.

The smiley is there because you did not put your code in code tags (naughty, naughty) and it was mangled by the forum software.

Code tags? I thought i did. what did i do wrong?

Out of interest, what does this comment refer to ?

 blinkNumber(8); // open port while flashing. Needed for Leonardo only

Did I get it right that you have your .ino in libraries folder? This is not a good place for it. Try moving it elsewhere, maybe this will help. As an alternative, try #include with double quotes but not angle brackets (this will tell the compiler to look for the .h in the folder of your .ino, not in libraries folder).

VT-
I tried double quotes in lieu of angle brackets... same error messages result.
Where would you suggest i put the .ino if not in the libraries folder?

Where would you suggest i put the .ino if not in the libraries folder?

In a folder of its own in the My Documents\Arduino folder, assuming you use Windows

Also, which libraries folder have you put the library files in ?
They should be in My Documents\Arduino\libraries

Have a look at My Documents\Arduino to see how other sketch folders and libraries are arranged

Thanks all.
I must get off line for today. My Bride calls me.
Be back tomorrow...

Try locate like this:
C:\Documents and Settings\Owner\My Documents\Arduino\MotorTest4wd\MotorTest4wd.ino
C:\Program Files\Arduino\arduino-1.04\libraries\AFMotor\AFMotor.h
C:\Program Files\Arduino\arduino-1.04\libraries\AFMotor\AFMotor.cpp (there must be some other-than-.h file, maybe several)
OR
C:\Documents and Settings\Owner\My Documents\Arduino\MotorTest4wd\MotorTest4wd.ino
C:\Documents and Settings\Owner\My Documents\Arduino\MotorTest4wd\AFMotor\AFMotor.h
C:\Documents and Settings\Owner\My Documents\Arduino\MotorTest4wd\AFMotor\AFMotor.cpp

Also, try reading this: http://arduino.cc/en/Hacking/LibraryTutorial

For Windows 7 user libraries go in the C:\Users\owner\Documents\Arduino\libraries folder in a folder with the same name as the library, not in the libraries folder under Arduino in Program Files.

This explains how they should be installed http://arduino.cc/en/Guide/Libraries

Wow! I have windows 8 and on my machine, libraries are in the same folder as are arduino executables (but not in program files)
To be exact, C:_vt\Distrib\Arduino soft\arduino-1.0.3\libraries
But .. sorry for a misleading post.

Thanks to all!
Your guidance has helped me to solve the problem.
I had 2 "Library" files. (Not very smart)

BobCarter338:
Note when previewing this post i noted that a icon appears after the blink command instead of an 8 followed by a ). I don't understand why.

Read this, it shows how to add code tags:

How to use this forum

VT:
Wow! I have windows 8 and on my machine, libraries are in the same folder as are arduino executables (but not in program files)
To be exact, C:_vt\Distrib\Arduino soft\arduino-1.0.3\libraries
But .. sorry for a misleading post.

Those are the supplied built-in libraries, your own library folder is inside the folder with your sketches. Don't put libraries in the
arduino-1.0.3/libraries/ folder or they will get deleted when you upgrade the Arduino software.

Don't put libraries in the arduino-1.0.3/libraries/ folder or they will get deleted when you upgrade the Arduino software.

They may become unavailable to sketches created in a later version but they will not be deleted, will they ?

Not moved, he meant. They will "seem" deleted.