Why PCA9685 doesn't work?

Code:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver srituhobby = Adafruit_PWMServoDriver();

#define servoMIN 150
#define servoMAX 600

void setup() {
Serial.begin(9600);
srituhobby.begin();
srituhobby.setPWMFreq(60);
}

void loop() {
srituhobby.setPWM(1, 0, servoMIN);
delay(300);

srituhobby.setPWM(1, 0, servoMAX);
delay(300);

}

Why doesn't the servo motor move at all?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Where is the pin used for the servo defined?
Which controller is used?

@timeab is using a PCA9685 PWM board rather than the Servo library. The number of the servo, and hence its connection to the PWM board is the first parameter of the SetPWM() function

    srituhobby.setPWMFreq(60);

Shouldn't the frequency be 50 Hz rather than 60Hz ?

Can you measure 5V on the middle pin of the servo headers?

Isn't the usual frequency for analog hobby servos 50Hz, not 60Hz?

With servos, it's the pulse length that's critical, I understand. The frequency, less so.

Your sketch works for me. The frequency should be set to 50 rather than 60 but the servo does move when it is set to 60, albeit not quite as it should

As suggested, check that the servo is getting 5V at the connection to the PWM board

1 Like

Thank you so much!!

Have you got it working ?

Yes, I also connected the V+ pin from the PCA9685 to the Vin from the arduino, it doesn't work as I wanted, but at least the servos move

Stop right there. Vin on the Arduino is only used for supply voltages from ~6.5V up. It feeds an onboard regulator to produce stable 5V for the processor and a limited amount for peripherals. But If your V+ exceeds 6.5V be aware, you'll likely damage the PCA9685 with this voltage.

Buy without that it doesn't work at all

Over time on this forum, you will learn to communicate more clearly.

Without what - connecting 5V to Vin? Doesn't matter. It may function, marginally, but it does not constitute a correct way to supply power to your Arduino, and will lead to unpredictable, impossible to diagnose problems, now or later.
You need to provide the PCA9685 with 5.0V at several Amperes. You also need to provide your Arduino with either >6.5V on Vin, OR 5.0V on the 5V pin(on a Nano, you can use this pin as an input or output), or leave USB plugged in so it powers the Nano.

BUT, I see from your photo in post #1 that you do NOT have anything wired to Vin, so you leave me confused as to what you're really doing...
Good luck, as you seem to believe the problem is solved.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.