Hello everyone. I started to work with Adafruit PCA9685 to control some servos with arduino nano. I connected a lot of them and make it work right with the examples but now I'm with a problem, I connected two servos and they spin on opposite direction CW and CCW and I'm trying to figure out how to make it work but without success, only one servo works, the other do nothing.
This is my code:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver servos = Adafruit_PWMServoDriver();
#define SERVOMIN 147
#define SERVOMAX 589
void setup() {
servos.begin();
servos.setPWMFreq(60);
}
int getAngleToPulse(int angle){
return map(angle, 0, 180, SERVOMIN, SERVOMAX);
}
int getAngleToPulseInverted(int angle){
return map(angle, 0, 180, SERVOMAX, SERVOMIN);
}
void loop() {
servos.setPWM(0, 0, getAngleToPulse(90)); // works
servos.setPWM(1, 0, getAngleToPulseInverted(90)); // doesn't work, no movement
delay(1000);
servos.setPWM(0, 0, getAngleToPulse(0)); // works
servos.setPWM(1, 0, getAngleToPulseInverted(0)); // doesn't work, no movement
delay(1000);
}
Using examples from library without caring about direction both of them works right.
When one item is working and another identical item doesn't, switch them to locate the fault. If you switch the cables connecting the servos to your servo driver. If same servo fails, you have a bad servo. If the other servo fails, the failure is somewhere earlier. Switch the failing servo to another pin on the PCA9685 and change your code accordingly. If it works now, you have a faulty pin. If it doesn't, the failure is somewhere earlier...
Johan_Ha:
When one item is working and another identical item doesn't, switch them to locate the fault. If you switch the cables connecting the servos to your servo driver. If same servo fails, you have a bad servo. If the other servo fails, the failure is somewhere earlier. Switch the failing servo to another pin on the PCA9685 and change your code accordingly. If it works now, you have a faulty pin. If it doesn't, the failure is somewhere earlier...
Thanks for your answer, I'll try that, but I don't believe that is the problem, with servo.ino example from Adafruit PWM Servo Driver the two servos spins right but on opposite direction, and when I try to sync them to go to same direction only one works, with the code above.
I'll try what you suggest and come here again the results.
Doesn't "inverted" mean the levels 0 and 1 are swapped? That's not what you want. Just use identical commands for the servos. One gets the angle a, the other gets the angle 180 - a.
Add some Serial.prints and check what values you're actually sending to the servo driver. The code LOOKS o.k. but I don't have a PCA9685 handy to test it.
If you have any other servos try a different one in port 1 in place of the one that you're trying to reverse. What happens?
BTW the standard servo frequency is 50Hz not 60Hz but it shouldn't make any difference.
Steve
"I connected two servos and they spin on opposite direction CW and CCW"
Are these identical servos, or are they different types/brands? I think I've seen/have servos that rotate in different directions.