Go Down

Topic: Compile error for Servo.h (Read 2364 times) previous topic - next topic

My Arduino Servo example (sweep) worked without the arduino library.
Here's the exact code in my program:

Code: [Select]
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

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
  }
}


I downloaded the Servo library and suddenly everything stopped working.
I got these errors:

Code: [Select]








C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'uint8_t Servo::attach(int)':
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:28: error: 'digitalWrite' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:29: error: 'OUTPUT' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:29: error: 'pinMode' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::write(int)':
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:52: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp: In static member function 'static void Servo::refresh()':
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:74: error: 'millis' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:107: error: 'digitalWrite' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:109: error: 'TCNT0' was not declared in this scope
C:\Users\Misha_2\Documents\Arduino\libraries\Servo\Servo.cpp:124: error: 'digitalWrite' was not declared in this scope


I deleted the Servo library and reverted the state of my Arduino folder to the same way it was just before I got the library, and it still didn't work.
'TCNT0' is not in any files in the Servo library or in the Arduino folder as far as I can see.
Does anyone know how to fix this problem?
Thanks!

ematson5897

What version of arduino are you running? if its not the latest version get the latest version and see if it works

retrolefty

#2
Jan 05, 2013, 01:23 am Last Edit: Jan 05, 2013, 01:25 am by retrolefty Reason: 1
Don't you have to have at the very start of your sketch a:

#include <Servo.h>

Also you don't have to down load a servo library, it's included in the current IDE. Possibly you have replaced the correct one with an older incorrect library?


Lefty

ematson5897

Yea thats what I was thinking. But he has to have servo.h included because the errors are from servo.cpp

Jantje

I have seen wierd things with the latest versions (1.0.1 and later) and "special libraries"
It happened again after I described it in this post http://arduino.cc/forum/index.php/topic,135457.msg1018947.html#msg1018947
Renaming the folder only helps for the run you are doing. Next time you start the Arduino IDE it piced it up again. So the problem is not name related.

Not sure it is related to the problem of the PO but it does sound a bit like it.

Anyway posting the full sketch should be the starting point.

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

V7Theory

I had this same problem and as others have mentioned, it turned out to be that I had downloaded a servo library, so to make my code work all I had to do was delete the servo library and restart the arduino app and everything was happy again!

Go Up