Multiple PCA9865 Problem

Hi,

I have 3 PCA9865 daisy chained as instructions from Adafruit. Have 3 5v. bricks, for each one to power the servos. One 7.5v brick to power Arduino through it’s barrel jack.

No issues when running code with USB attached to PC but without it, the code doesn’t run. Copilot suggested creating a star GND from Arduino and the GND’s of the 3 bricks feeding the boards, which I did. But still not working.

Pls see the wiring scheme

Wiring.pdf (27,1 KB)

The contents of the PDF

Which Arduino board are you using ?

Please post your sketch here using code tags when you do

Rather than attaching images it is better if you post them here

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

And when you only connect one PCA9685, does it still not run?

@rr1991
Unfortunately, your connection is not clearly explained by the schematic. Please be more precise and indicate exact pins on Arduino and PCA9685 used for connections.

By the way, what the PCA9685 do you use? Are it a modules or bare chips? Some clear photos of the project also may helps.

@robtillaart a couple of servos move when using only one board.

@b707 I’m using the modules. Here are the connections you asked
VCC –> Arduino 5v, SDA –> A4, SCL –> A5, GND –> GND

Arduino UNO

From the datasheet. NXP - Rev. 4 — 16 April 2015

The PCA9685 is an I2C-bus controlled 16-channel LED controller optimized for
Red/Green/Blue/Amber (RGBA) color backlighting applications. Each LED output has its
own 12-bit resolution (4096 steps) fixed frequency individual PWM controller that operates
at a programmable frequency from a typical of 24 Hz to 1526 Hz with a duty cycle that is
adjustable from 0 % to 100 % to allow the LED to be set to a specific brightness value.
All outputs are set to the same PWM frequency

…
Each LED output can be off or on (no PWM control), or set at its individual PWM controller
value. The LED output driver is programmed to be either open-drain with a 25 mA current
sink capability at 5 V or totem pole with a 25 mA sink, 10 mA source capability at 5 V. The
PCA9685 operates with a supply voltage range of 2.3 V to 5.5 V and the inputs and
outputs are 5.5 V tolerant. LEDs can be directly connected to the LED output (up to
25 mA, 5.5 V) or controlled with external drivers and a minimum amount of discrete
components for larger current or higher voltage LEDs.

Maybe less suited for the servos used?

You have not connected the OE pin to the Arduino. If it is floating it might just switching all things off.

The active LOW Output Enable input pin (OE) allows asynchronous control of the LED
outputs and can be used to set all the outputs to a defined I2C-bus programmable logic
state. The OE can also be used to externally ‘pulse width modulate’ the outputs, which is
useful when multiple devices need to be dimmed or blinked together using software
control.

Thank you.

I’ve always used these modules with servos with no issue.

However, it’s the first time I’m using multiple power sources and that, I guess, is the culprit.

Have never had to use OE pins but I guess they can be grounded.

Your second wiring diagram only shows one power supply, yet you say you are using three

If you are using three separate 5V power supplies, then you sould not have V+ connected between boards.

Are you using the Adafruit board as shown below?

You have shown three different wiring diagrams, one with three power supplies, one with one power supply connected to one board and one with one power supply connected to three board.

Which is the actual diagram for your set-up

Output enable on the PCA9865 by Adafruit has a 10K pull down on the PCB so the outputs should be enabled by default and the OE pin then becomes optional.

Is your code (which we haven't seen yet) waiting for a response from the serial port, which it can't get when the USB is disconnected?

Sorry for the confusion Jim, pls see my first post. I’m using 3 separate power sources, one for each board for the servos.

Following what Adafruit says, the v+ in between boards is for the logic.

I’m not using the exact board you posted but similar ones with big CAP and no FET.

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

#include <ThreeWire.h>
#include <RtcDS1302.h>


const int SWEEP_STEP = 3;
const int SWEEP_DELAY_MS = 10;

// Define DS1302 pin connections
const int DATpin = 3;  // Data
const int CLKpin = 2;  // SCLK
const int RSTpin = 4;  // RST

// Create 3-wire interface and RTC object
ThreeWire myWire(DATpin, CLKpin, RSTpin);  // IO, SCLK, CE
RtcDS1302<ThreeWire> rtc(myWire);


#define Servo_Min 100 //110      // Min pulse width
#define Servo_Max   580 //590     // Max pulse width
#define SERVO_RANGE 270.0  // Total servo rotation

Adafruit_PWMServoDriver brd1(0x40);
Adafruit_PWMServoDriver brd2(0x41);
Adafruit_PWMServoDriver brd3(0x42);

// 1-based array: index 0 is dummy (unused)
Adafruit_PWMServoDriver* arrayBrds[] = { nullptr, &brd1, &brd2, &brd3 };


struct ServoPair {
  uint8_t board;
  uint8_t servoH;  // odd-numbered pin (H-hand, CW)
  uint8_t servoM;  // even-numbered pin (M-hand, CCW)
};


// === Grid > first digit brd number, second H hand, third M hand ===
ServoPair servoGrid[3][8] = {
  { { 1, 5, 4 }, { 1, 11, 10 }, { 2, 1, 0 }, { 2, 7, 6 }, { 2, 13, 12 }, { 2, 15, 14 }, { 3, 9, 8 }, { 3, 15, 14 } },

  { { 1, 3, 2 }, { 1, 9, 8 }, { 1, 15, 14 }, { 2, 5, 4 }, { 2, 11, 10 }, { 3, 1, 0 }, { 3, 7, 6 }, { 3, 13, 12 } },

  { { 1, 1, 0 }, { 1, 7, 6 }, { 1, 13, 12 }, { 2, 3, 2 }, { 2, 9, 8 }, { 3, 3, 2 }, { 3, 5, 4 }, { 3, 11, 10 } }
};

int currentPos[3][8][2];  // [row][col][0 = H-hand, 1 = M-hand]
int TargetPos;

int lastMinute = -1;  // To track minute changes
int hour12;           // 12-hour format hour
String ampm;          // "AM" or "PM"

int dig1, dig2, dig3, dig4;  // Time digits: HH:MM


bool isDST_Europe(RtcDateTime now) {
  int year = now.Year();
  int month = now.Month();
  int day = now.Day();
  int weekday = now.DayOfWeek(); // Sunday = 0

  // DST starts: last Sunday of March
  if (month == 3) {
    if (day >= 25 && weekday == 0) return now.Hour() >= 2;
    if (day > 25) return true;
  }

  // DST ends: last Sunday of October
  if (month == 10) {
    if (day >= 25 && weekday == 0) return now.Hour() < 3 ? true : false;
    if (day > 25) return false;
  }

  // Between April and September: DST is active
  if (month > 3 && month < 10) return true;

  return false;
}


void Get_Time() {
  
  ///*
  // Set time manually once — comment this out after first upload
  RtcDateTime italyTime(2025, 8, 8, 8, 26, 0);
  rtc.SetDateTime(italyTime);
  Serial.println("RTC time set to Italy local time.");
 // */

  // Read current time from RTC
  RtcDateTime now = rtc.GetDateTime();

  int hour24 = now.Hour();
  int minute = now.Minute();

// Apply DST offset if needed
if (isDST_Europe(now)) {
  hour24 += 1;
  if (hour24 >= 24) hour24 -= 24;
}


  if (minute != lastMinute) {
    lastMinute = minute;

    // Convert to 12-hour format
    hour12 = hour24 % 12;
    if (hour12 == 0) hour12 = 12;
    ampm = (hour24 < 12) ? "AM" : "PM";

    // Break into individual digits
    dig1 = hour12 / 10;
    dig2 = hour12 % 10;
    dig3 = minute / 10;
    dig4 = minute % 10;

    // Serial print formatted time
    Serial.print("Time: ");
    Serial.print(hour12);
    Serial.print(":");
    if (minute < 10) Serial.print("0");
    Serial.print(minute);
    Serial.print(" ");
    Serial.println(ampm);

    // Serial print digits
    Serial.print("Digits: ");
    Serial.print(dig1); Serial.print(" ");
    Serial.print(dig2); Serial.print(" : ");
    Serial.print(dig3); Serial.print(" ");
    Serial.println(dig4);


  }

  delay(500);
}




inline void sweepChannel(uint8_t board, uint8_t channel, int &posRef, int target) {
  if (posRef == target) return;
  int dir = (target > posRef) ? SWEEP_STEP : -SWEEP_STEP;
  int p = posRef;
  while ((dir > 0 && p < target) || (dir < 0 && p > target)) {
    p += dir;
    if ((dir > 0 && p > target) || (dir < 0 && p < target)) p = target;
    arrayBrds[board]->setPWM(channel, 0, p);
    delay(SWEEP_DELAY_MS);
  }
  posRef = target;
}


void sweepAllToMax() {
  for (int row = 0; row < 3; row++) {
    for (int col = 0; col < 8; col++) {
     
      
      ServoPair sp = servoGrid[row][col];
      sweepChannel(sp.board, sp.servoH, currentPos[row][col][0], Servo_Max);
      sweepChannel(sp.board, sp.servoM, currentPos[row][col][1], Servo_Max);

      
    }
  }
}


void setup() {
 
  
  Serial.begin(9600);
  Wire.begin();
 rtc.Begin();


 for (int b = 1; b <= 3; b++) {
    arrayBrds[b]->begin();
    arrayBrds[b]->setOscillatorFrequency(27000000);  
    arrayBrds[b]->setPWMFreq(50);
    delay(100);}
 
 
 sweepAllToMax();

}

void loop() {

}

NO, it's Vcc. By connecting V+ you are putting all the power supplies in parallel and that can cause serious problems.

I wonder if you have damaged your Uno and/or PCA9865 boards.

All your modules must have a different addresses, as you used in the code above. And did you soldered address jumpers on the modules?

That’s my wiring, it then continues from one board to another.

With the USB connected have no issues so I doubt any hardware damage.

I still think (?) it has to do with GND. But can’t figure it out.

@b707 yes I did solder adresses. I2C Scanner shows correct adresses.

Do you think the negative from the brick powering the Arduino should be connected to the star common ground of the others ?