Pca9685 - Driving servos

Hello I am using two pca9685 modules with 24 Servos

When I want to control my servo motors, one or two servo motors are always not recognized (always a different one)

That's too bad.

Maybe we could help if we had more information.

have any idea?

I am using this Sketch:

//Michael Klements
//The DIY Life
//8 February 2020

#include <virtuabotixRTC.h>               //Include library for clock module
#include <Adafruit_PWMServoDriver.h>      //Include library for servo driver

Adafruit_PWMServoDriver pwmH = Adafruit_PWMServoDriver(0x40);    //Create an object of Hour driver
Adafruit_PWMServoDriver pwmM = Adafruit_PWMServoDriver(0x41);    //Create an object of Minute driver (A0 Address Jumper)

int servoFrequency = 60;      //Set servo operating frequency

int segmentHOn[14] = {380,355,390,397,387,392,372,390,380,370,382,372,385,378};   //On positions for each Hour servo
int segmentMOn[14] = {380,395,372,375,375,350,375,372,395,372,390,380,375,387};   //On positions for each Minute servo
int segmentHOff[14] = {185,155,185,180,185,185,175,180,180,178,178,185,175,175};    //Off positions for each Hour servo
int segmentMOff[14] = {170,175,170,172,172,170,165,171,170,180,180,175,170,185};    //Off positions for each Minute servo
int digits[10][7] = {{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},
                     {1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};    //Position values for each digit

virtuabotixRTC myRTC(6, 7, 8);    //Create a clock object attached to pins 6, 7, 8 - CLK, DAT, RST
int hourTens = 0;                 //Create variables to store each 7 segment display numeral
int hourUnits = 0;
int minuteTens = 0;
int minuteUnits = 0;

int prevHourTens = 8;           //Create variables to store the previous numeral displayed on each
int prevHourUnits = 8;          //This is required to move the segments adjacent to the middle ones out of the way when they move
int prevMinuteTens = 8;
int prevMinuteUnits = 8;

int midOffset = -100;            //Amount by which adjacent segments to the middle move away when required

void setup() 
{
  pwmH.begin();                             //Start each board
  pwmM.begin();
  delay(1000);
  pwmH.setOscillatorFrequency(27000000);    //Set the PWM oscillator frequency, used for fine calibration
  pwmM.setOscillatorFrequency(27000000);
  delay(1000);
  pwmH.setPWMFreq(servoFrequency);          //Set the servo operating frequency
  pwmM.setPWMFreq(servoFrequency);
  delay(1000);
  //myRTC.setDS1302Time(00, 10, 16, 5, 8, 4, 2022);        //Only required once to reset the clock time
  for(int i=0 ; i<=13 ; i++)    //Set all of the servos to on or up (88:88 displayed)
  {
    pwmH.setPWM(i, 0, segmentHOn[i]);
    delay(2000);
    pwmM.setPWM(i, 0, segmentMOn[i]);
    delay(2000);
  }
  delay(2000);
}

void loop()
{
  myRTC.updateTime();                 //Update the time
  int temp = myRTC.hours;             //Get the hours and save to variable temp
  hourTens = temp / 10;               //Split hours into two digits, tens and units
  hourUnits = temp % 10;
  temp = myRTC.minutes;               //Get the minutes and save to variable temp
  minuteTens = temp / 10;             //Split minutes into two digits, tens and units
  minuteUnits = temp % 10;

  if(minuteUnits != prevMinuteUnits)  //If minute units has changed, update display
    updateDisplay();

  prevHourTens = hourTens;            //Update previous displayed numerals
  prevHourUnits = hourUnits;
  prevMinuteTens = minuteTens;
  prevMinuteUnits = minuteUnits;

  delay(500);
}

void updateDisplay ()                               //Function to update the displayed time
{
  updateMid();                                      //Move the segments out of the way of the middle segment and then move the middle segments
  for (int i=0 ; i<=5 ; i++)                        //Move the remaining segments
  {
    if(digits[hourTens][i]==1)                      //Update the hour tens
      pwmH.setPWM(i+7, 0, segmentHOn[i+7]);
    else
      pwmH.setPWM(i+7, 0, segmentHOff[i+7]);
    delay(10);
    if(digits[hourUnits][i]==1)                     //Update the hour units
      pwmH.setPWM(i, 0, segmentHOn[i]);
    else
      pwmH.setPWM(i, 0, segmentHOff[i]);
    delay(10);
    if(digits[minuteTens][i]==1)                    //Update the minute tens
      pwmM.setPWM(i+7, 0, segmentMOn[i+7]);
    else
      pwmM.setPWM(i+7, 0, segmentMOff[i+7]);
    delay(10);
    if(digits[minuteUnits][i]==1)                   //Update the minute units
      pwmM.setPWM(i, 0, segmentMOn[i]);
    else
      pwmM.setPWM(i, 0, segmentMOff[i]);
    delay(10);
  }
}

void updateMid()                                              //Function to move the middle segements and adjacent ones out of the way
{
  if(digits[minuteUnits][6]!=digits[prevMinuteUnits][6])      //Move adjacent segments for Minute units
  {
    if(digits[prevMinuteUnits][1]==1)
      pwmM.setPWM(1, 0, segmentMOn[1]-midOffset);
    if(digits[prevMinuteUnits][6]==1)
      pwmM.setPWM(5, 0, segmentMOn[5]+midOffset);
  }
  delay(100);                                                 //Delay allows adjacent segments to move before moving middle
  if(digits[minuteUnits][6]==1)                               //Move Minute units middle segment if required
    pwmM.setPWM(6, 0, segmentMOn[6]);
  else
    pwmM.setPWM(6, 0, segmentMOff[6]);
  if(digits[minuteTens][6]!=digits[prevMinuteTens][6])        //Move adjacent segments for Minute tens
  {
    if(digits[prevMinuteTens][1]==1)
      pwmM.setPWM(8, 0, segmentMOn[8]-midOffset);
    if(digits[prevMinuteTens][6]==1)
      pwmM.setPWM(12, 0, segmentMOn[12]+midOffset);
  }
  delay(100);                                                 //Delay allows adjacent segments to move before moving middle
  if(digits[minuteTens][6]==1)                                //Move Minute tens middle segment if required
    pwmM.setPWM(13, 0, segmentMOn[13]);
  else
    pwmM.setPWM(13, 0, segmentMOff[13]);
  if(digits[hourUnits][6]!=digits[prevHourUnits][6])          //Move adjacent segments for Hour units
  {
    if(digits[prevHourUnits][1]==1)
      pwmH.setPWM(1, 0, segmentHOn[1]-midOffset);
    if(digits[prevHourUnits][6]==1)
      pwmH.setPWM(5, 0, segmentHOn[5]+midOffset);
  }
  delay(100);                                                 //Delay allows adjacent segments to move before moving middle
  if(digits[hourUnits][6]==1)                                 //Move Hour units middle segment if required
    pwmH.setPWM(6, 0, segmentHOn[6]);
  else
    pwmH.setPWM(6, 0, segmentHOff[6]);
  if(digits[hourTens][6]!=digits[prevHourTens][6])            //Move adjacent segments for Hour tens
  {
    if(digits[prevHourTens][1]==1)
      pwmH.setPWM(8, 0, segmentHOn[8]-midOffset);
    if(digits[prevHourTens][6]==1)
      pwmH.setPWM(12, 0, segmentHOn[12]+midOffset);
  }
  delay(100);                                                 //Delay allows adjacent segments to move before moving middle
  if(digits[hourTens][6]==1)                                  //Move Hour tens middle segment if required
    pwmH.setPWM(13, 0, segmentHOn[13]);
  else
    pwmH.setPWM(13, 0, segmentHOff[13]);
}

and it is for a seven segment clock with servos

But every time I try to test it one or two servos don't work.

When I reconnect the power supply one or two different motors don't work

Post a schematic. Hand drawn, photographed and posted is fine. Include all components, their part numbers and/or values and all power supplies.

Post links to the component technical data (data sheets, manuals).

Post clear photos of the project and wiring.

But I don't think that the wiring or something could be the problem because everytime some work and some don't ..

I wa hoping that this is a common problem I could fix easly

I use 2x Pca9685
1x ArduinoUno Rev3
24x Servos
1x RTC Module

What are the specifications of the power supply? Rated voltage, current capability?

the Pca9685 gets 5 V and the Servos 5 V too.

The most common problem is lack of power. Since you refuse to supply the specifications of the components (power supply(s), servos) there is no way to say for sure. But dollars to donuts your servo supply does not have the current capability necessary to run 24 servos.

but I can't do more than 5 volts in the v+ or?

I can find a data sheet for the PCA9685 if I wanted to, but since I doubt that it has any relevance I don't need to. I would like a data sheet for the servo power supply.

You do not need more voltage. You likely do need more current. Each servo (I still don't have a part number) can require 1A or more of current. That means that your servo power supply needs to output the 5V and 24A. That is 120 Watts, minimum. Anything less and the voltage gets dragged down and the servo start to go crazy.

So I will ask once again, what is the CURRENT capability specification of the servo power supply?

I use the mg90s Servos

I also use a 12 volt power supply (2A, 24W) which is divided into the power supply for the Arduino and is compressed to 5 volts for the pca

OK, 12V at 2A dropped to 5V with perfect efficiency is 4.8A. A tad short of the 24A you need (assuming 1A per servo).

So you do have the common problem and the common solution is to acquire a power supply capable of delivering the required current at the right voltage. Or by acquiring a number of supplies that can together supply the required current.

Connect the grounds.

oh okay i will try I guess

If you want to run 24 servos and have them work reliably, there is no choice.

but they aren't moving all at the same time

Servos are always drawing some power.

Do you have a DMM (Digital MultiMeter)? Connect it to the servo supply power supply output and watch it while the servos are operating. What do you observe? A rock steady 5V?

nope

That's it, nope? What did you see? Can you be more descriptive? How low was the lowest?