1

I posted this a few days ago Servomotor and music shield

and now I moving my servo motor and my musicshield (seeduino musicshield v2.0) together with and Arduino uno, in my other post they told me to put the library ServoTimer2 because I was having a conflict with the two libraries(the servo.h library and the musicshield library). And I'm having a lot of trouble with the servotimer2 library, at first didn't work, it gives me always this error: C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: conflicting declaration 'typedef bool boolean'

typedef bool boolean;

but I read that if I erase the //typedef uint8_t boolean; in the ServoTimer2.h It will be working. So I did it, and it works somehow. Now, the musicshield is playing the songs and the servomotor is moving, but is not moving "properly" I mean it moves so little like 10° and moving back and so on, the servo motor is not moving the 90° or stopping the time I want it to stop. I don't know if it's the code, I search and the servo.h and the servotimer2 library change only in the way you define your servo and pin. So I tried this without the musicshield and it didn't work either, in this case the servomotor make some noise like a clock like tic, tic, tic, but don't move

#include <ServoTimer2.h>


ServoTimer2 servoNine;

int val;//for the servo

void setup() {
  servoNine.attach( 9 );




 }
void loop() {
val = 0  ;// start point
servoNine.write(val);
delay(100); 

val = 90 ;//
servoNine.write(val);
delay(100);//

}

so, I think the problem is the code. The servomotor is not broken I tested that, with the normal servo.h and the same code and it's moving properly

#include <Servo.h>
Servo myservo;
int val;


void setup() {
  myservo.attach( 9 );
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
val = 0;// 
myservo.write(val);
delay(100);

val = 90;//
myservo.write(val);
delay(100);
}

it moved! I runned the example program and my servomotor it's behaving properly now,is an adaptation from the three servos example the code I'm using is this

#include <ServoTimer2.h>  // the servo library

// define the pins for the servos
#define rollPin  9


ServoTimer2 servoRoll;    // declare variables for up to eight servos


void setup() {
  servoRoll.attach(rollPin);     // attach a pin to the servos and they will start pulsing

}


// this function just increments a value until it reaches a maximum 
int incPulse(int val, int inc){
   if( val + inc  > 2000 )
      return 1000 ;
   else
       return val + inc;  
}

void loop()
{ 
 int val;

   val = incPulse( servoRoll.read(), 1);
   servoRoll.write(val);



   delay(10);   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.