Go Down

Topic: COmpiler issue (Read 669 times) previous topic - next topic

ebkapalka

Hello!
I am having a compiling issue.  When I try to compile the example servo code that comes with the IDE, I get this error:  

Sweep.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Users\Owner\AppData\Local\Temp\build1200514424625972248.tmp/Sweep.cpp:8: undefined reference to `Servo::Servo()'
Sweep.cpp.o: In function `loop':
C:\Users\Owner\AppData\Local\Temp\build1200514424625972248.tmp/Sweep.cpp:23: undefined reference to `Servo::write(int)'
C:\Users\Owner\AppData\Local\Temp\build1200514424625972248.tmp/Sweep.cpp:28: undefined reference to `Servo::write(int)'
Sweep.cpp.o: In function `setup':
C:\Users\Owner\AppData\Local\Temp\build1200514424625972248.tmp/Sweep.cpp:15: undefined reference to `Servo::attach(int)'

I have managed to compile other code perfectly, so I don't think it's a driver issue........

Here is an example that works:
Code: [Select]
int servoPin     =  2;    // control pin for servo motor  
int minPulse     =  600;  // minimum servo position  
int maxPulse     =  2400; // maximum servo position  
int turnRate     =  100;  // servo turn rate increment (larger value, faster rate)  
int refreshTime  =  20;   // time (ms) between pulses (50Hz)  
 
/** The Arduino will calculate these values for you **/  
int centerServo;         // center servo position  
int pulseWidth;          // servo pulse width  
int moveServo;           // raw user input  
long lastPulse   = 0;    // recorded time (ms) of the last pulse  
 
 
void setup() {  
 pinMode(servoPin, OUTPUT);                                       // Set servo pin as an output pin  
 centerServo = maxPulse - ((maxPulse - minPulse)/2);  
 pulseWidth = centerServo;                                        // Give the servo a starting point (or it floats)  
 Serial.begin(9600);  
 Serial.println("      Arduino Serial Servo Control");  
 Serial.println("Press < or > to move, spacebar to center");  
 Serial.println();  
}  
 
void loop() {  
                                                                   // wait for serial input  
 if (Serial.available() > 0) {  
                                                                   // read the incoming byte:  
   moveServo = Serial.read();  
                                                                   // ASCII '<' is 44, ASCII '>' is 46 (comma and period, really)  
   if (moveServo == 44) { pulseWidth = pulseWidth - turnRate; }  
   if (moveServo == 46) { pulseWidth = pulseWidth + turnRate; }  
   if (moveServo == 32) { pulseWidth = centerServo; }  
 
                                                                   // stop servo pulse at min and max  
   if (pulseWidth > maxPulse) { pulseWidth = maxPulse; }  
   if (pulseWidth < minPulse) { pulseWidth = minPulse; }  
 
                                                                   // print pulseWidth back to the Serial Monitor (uncomment to debug)  
    Serial.print("Pulse Width: ");  
    Serial.print(pulseWidth);  
    Serial.println("us");   // microseconds  
 }  
 
 // pulse the servo every 20 ms (refreshTime) with current pulseWidth  
 // this will hold the servo's position if unchanged, or move it if changed  
 if (millis() - lastPulse >= refreshTime) {  
   digitalWrite(servoPin, HIGH);   // start the pulse  
   delayMicroseconds(pulseWidth);  // pulse width  
   digitalWrite(servoPin, LOW);    // stop the pulse  
   lastPulse = millis();           // save the time of the last pulse  
 }  
}  


Please help!  Thanks!

PaulS

Quote
Here is an example that works:

But, I'm having some problems with other code that I'm not going to show you...

Well, good luck resolving the issues.

AWOL

It is very unlikely to be a compiler or a driver issue.
It is more likely related to your installation, but like the man said, without seeing your code...
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

ebkapalka


Quote
Here is an example that works:

But, I'm having some problems with other code that I'm not going to show you...

Well, good luck resolving the issues.


It's the example code under file -> examples -> servo -> sweep.
I apologize for the inconvenience.  I thought it came standard
with all installations of the arduino IDE.  Here it is:
Code: [Select]
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.


#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}


void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


help?

PaulS

When I compile that code, the only "error" I get is:
Quote
Binary sketch size: 2,666 bytes (of a 30,720 byte maximum)


It looks like you've managed to hose up the Servo library somehow.

AWOL

Code: [Select]
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees

I hate that example.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

ebkapalka

How else would you propose I do the same thing?  Coincidentally, the example should do exactly what I need my servo to do....  If you have any suggestions, could you let me know?  Thanks!

PeterH


How else would you propose I do the same thing?


The comments look reasonable, but the code doesn't do what the comments say - hardly a good example to set.
I only provide help via the forum - please do not contact me for private consultancy.

Nick Gammon

It compiled OK for me under version 1.0 of the IDE.

What version of the IDE do you have? What board is selected? What operating system are you using?
http://www.gammon.com.au/electronics

ebkapalka



How else would you propose I do the same thing?


The comments look reasonable, but the code doesn't do what the comments say - hardly a good example to set.


All the code has to do is turn the servo 180 degrees, delay for 15ms or so, and turn back 180 degrees.  How could I do this (more efficiently) ?

AWOL

If you've managed to hose the Servo library, it seems likely to me that you've hosed other libraries too. I'd concentrate on fixing that first, if you intend doing more Arduino projects.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up