Possible Code Issue?

Hello all,
So I'm an Electrical Automation Engineer. PLC's, Scada, HMI is my usual knowledge of Coding.

For fun I bought this kit off AliExpress 5 dof robotic arm that I've bought and put together with my 10 year old daughter.

I've watched a few youtube videos on these and picked up a code to upload and it uploaded fine - No errors but nothing happens
None of the servo's start moving.
Certainly no genius with this type of coding, would appreciate a little help

Here's my hardware
Arduino Uno
PCA 9685 PWM
Power Supply 6.0 vdc to PCA 9685

Downloaded the Adafruit pwm servo driver from the library
Found my Arduino board and com port
Everything fine there, I can see on the Arduino the program been loaded to the board by the LEDS through the com connection, but alas no movement from the servo's

Here is the code I've used

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

// Initialize the PCA9685 module with the default address (0x40)
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

// Define the PWM frequency for standard analog servos
#define SERVOFREQ 50 

// Define the servo channels for each DOF
#define BASE_SERVO 0
#define SHOULDER_SERVO 1
#define ELBOW_SERVO 2
#define WRIST_SERVO 3
#define GRIPPER_SERVO 4

// Define the pulse width for minimum and maximum servo angles (0 and 180 degrees)
#define SERVOMIN 150  // Minimum pulse length (out of 4096)
#define SERVOMAX 600  // Maximum pulse length (out of 4096)

// Function to calculate the pulse length from an angle
int angleToPulse(int angle) {
  return map(angle, 0, 180, SERVOMIN, SERVOMAX);
}

void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(SERVOFREQ);  // Set the PWM frequency
  
  // Wait for a second to allow the module to start
  delay(1000); 

  // Center all servos to a neutral 90-degree position
  pwm.setPWM(BASE_SERVO, 0, angleToPulse(90));
  pwm.setPWM(SHOULDER_SERVO, 0, angleToPulse(90));
  pwm.setPWM(ELBOW_SERVO, 0, angleToPulse(90));
  pwm.setPWM(WRIST_SERVO, 0, angleToPulse(90));
  pwm.setPWM(GRIPPER_SERVO, 0, angleToPulse(90));
}

void loop() {
  // Example 1: Move all servos in a sequence
  Serial.println("Moving servos to 0 degrees...");
  for (int i = 0; i < 5; i++) {
    pwm.setPWM(i, 0, angleToPulse(0));
    delay(500); 
  }

  Serial.println("Moving servos to 180 degrees...");
  for (int i = 0; i < 5; i++) {
    pwm.setPWM(i, 0, angleToPulse(180));
    delay(500); 
  }

Thanks Geoff in New Zealand

Welcome to the forum

Please post a schematic of your project showing how the components are connected and powered. The majority of problems with servos come down to how they are powered


Sorry don't have a schematic drawn up - but hope the photos will suffice

I am sorry, but it is impossible from your photographs to tell how the servos and the servo board are powered.

The schematic does not have to be fancy. A photo of a hand drawn circuit is good enough

Same as this - but with 5 Servo's
Thankyou for replying to my post btw, and the welcome

First step - is the board address the same as the default address in the code? Run the I2C sniffer(it's in the xamples in the IDE), see if the board can be seen, and at what address.

What type of servos? The servo power supply should be rated for at least 1 Ampere per servo (for small ones like SG90), and 2.5 Amperes/servo for larger ones like the MG996R.

So, 6V at 5 Amperes, or 30 watts, absolute minimum.

For a robotic arm, 12 Amperes is the more likely requirement, which the traces on a single PCA9685 board probably can't handle.

If you look through this forum, this is a very common question. The vast majority of servo problems are due to inadequate servo power supplies.

I'm using MG996R
Yes correct - I was concerned not enough amperage. I tested each servo individually and they all work, but as you say - Load might be the issue. Although I have to also wonder though - the program itself is set to run each servo separately in sequential step through, not more than one servo as it steps through the program. So is this still an issue???

Was that with the sketch that you posted ?

Not really. Brushed DC motors briefly draw the stall current (2.5 A for the MG996R) every time they start moving, even when not loaded. Load exacerbates the problem, of course.

For that arm, you will need a power supply capable of delivering about 70 watts at 6V.

No - it was another one from the Arduino library for running a single servo off the Arduino Uno board only

Disconnect all but one of your servos and try the sketch. Does that one servo move ? If so, ad a second one and so on

Ok - might have to hook this up to my Bench power supply 0-30vdc at 5amps max
That's all I can try because I don't have anything else with bigger amperage.
But it's funny seeing videos of these robotic arms on youtube running with 6 volt power packs with no issues

No it doesn't work - I tried that

Did you check the I2C address as suggested earlier in the topic ?

I can't quite get my head around the addressing thing head. But I do know the program is communicating through the usb port with the board - it's flashing away with the LEDS when uploading to the Arduino

The I2C protocol is used to communicate between the Uno and the servo board. The latter has an address which must be used by your sketch otherwise communication between the boards will not work

Leave your circuit as it is and run the I2C scanner example from the Wire library. What, if anything, does it report ?

What does it report

You mean in the output box?

In the Serial monitor of the IDE

Serial.print("I2C device found at address 0x");
Serial.print(address, HEX);
Serial.print("Unknown error at address 0x");
Serial.println("No I2C devices found\n");