Servo Motors not attaching (Answered)

Hi guys

I'm working on controlling the orientation of an object using servo motors. I'm using 3 Tower pro micro servos to test my code before investing in some servos with some more torque. The problem I have is that not all of the servos power up and move to the commanded positions.

Tests I have completed to try and sort out the problem:

-I have checked that the servos are working and not damaged.

-I have checked enough current is being supplied to the servos from my power supply, it can turn all the servos without them being slow or lagging.

-I have checked all the wired connections between the Arduino, power supply and servos.

-I have checked that the values being given to the servos to position them fall between 0 and 180.

-I have tried my code and setup on a Mega 1280 and a Duemilanove 328, both are Seeeduino clones but I have never had any issues with them. I have tried to attach the servos to different PWM pins but no difference.

-Finally I have used the 'attached()' command in the servo library to test if the servos are attached (returns bool), the servos that move return true but the servo that doesn't move returns false.

The code for each servo is exactly the same so I can not understand why they would work differently. I've Included the parts of the code that the servos are affected by below.

void setup() {
    myservo1.attach(3);
    myservo2.attach(12);
    myservo3.attach(11);
}

void loop() {
   servocontrol()
}

void servocontrol() {
on = myservo1.attached();
  if (on == true) {
   digitalWrite(7, HIGH); 
  }
  float pos1 = (ypr[2] * 180/M_PI) + 90;  // Pitch
  float pos2 = (ypr[0] * 180/M_PI) + 90;  // Yaw
  float pos3 = (ypr[1] * 180/M_PI) + 90;  // Roll
  
  myservo1.write(pos1);  // Pitch
  myservo2.write(pos2);  // Yaw
  myservo3.write(pos3);  // Roll

  delay(10);
}

Any suggestion of what could be wrong and how to solve it would be greatly appreciated.

void loop() {
   servocontrol()
}

Come back with code that actually compiles.

My code is 300 lines long and 90% of it does not affect the servo motors, it uses a Library from Jeff Rowberg for using the MPU6050 Gyro sensor (i2cdevlib/Arduino/MPU6050 at master · jrowberg/i2cdevlib · GitHub) the 6 axis '.h' file

I've included my sketch file.

Thanks for the fast reply

MPU6050_DMP6_Jeff_Servocontrol.ino (12.6 KB)

I'd aim at getting more of those constant strings into flash memory.

Where does the PWMServo library come from?

I got the PWMServo library from a friend when the same problem occured with the standard servo library that come with Arduino. Having had a look on the web for it this is the only place I can find it.

http://arduiniana.org/libraries/pwmservo/

It seems to be fairly old so may be the problem.

As a test, just now, I swapped back to the servo library that comes with Arduino (Servo - Arduino Reference) but there is no change in the servos that work and the one that does not.

Ok so I swapped back to the Arduino Servo library changed the attach pin numbers to 10, 11, 12 and rewired the servo connection and now it all works.

The problem must have been the PWMServo library.

Thanks for your quick suggestions now I can get on with tidying my code!