Problem mapping pulse width on a RDS3218 (270°)

I'm attempting to control 6 servo motors in a 6-axis robotic arm.
Video of the problem I'm having: https://youtu.be/vQaEbI6lFIM

Schematic:


Everything seems ok, except I'm having trouble controlling RDS3218 with RV6_base potentiometer.

Code:

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

#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define FREQUENCY 50
#define CONVERSION_RATE 4096

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// pins on Uno
int potWrist = A0;
int potForearm = A1;
int potElbow = A2;
int potShoulder = A3;
int potBase = A4;

// pins on driver board
int hand = 0;
int wrist = 1;
int forearm = 2;
int elbow = 3;
int shoulder = 4;
int base = 5;

void setup() {
  delay(3000);
  pwm.begin();
  pwm.setPWMFreq(FREQUENCY);
  pwm.setPWM(hand, 0, 90); // hand close at 90°

  pinMode(13, INPUT_PULLUP); // switch for hand

  Serial.begin(9600);
  Serial.println("Initialized.");
}
 
void moveMotor(int controlIn, int motorOut, bool isBase) {
  float mappedValue;
  int pulse_width, potVal;

  potVal = analogRead(controlIn); //read potentiometer
  if (isBase) {
    mappedValue = map(potVal, 0, 1023, 500, 2500); //RDS3218's PWM values are between 500~2500uS
    pulse_width = int(mappedValue / 1000000 * FREQUENCY * CONVERSION_RATE);
  } else {
    mappedValue = map(potVal, 150, 900, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
    pulse_width = int(mappedValue / 1000000 * FREQUENCY * CONVERSION_RATE);
  }
  pwm.setPWM(motorOut, 0, pulse_width);
}
 
void loop() {
  moveMotor(potWrist, wrist, 0);
  moveMotor(potForearm, forearm, 0);
  moveMotor(potElbow, elbow, 0);
  moveMotor(potShoulder, shoulder, 0);
  moveMotor(potBase, base, 1);

  int pushButton = digitalRead(13);
  if (pushButton == LOW) {
    pwm.setPWM(hand, 0, 180); //hand closed if pin is closed
  }
  else {
    pwm.setPWM(hand, 0, 90); //hand open if pin is open
  }
}

The problem I'm experiencing:
All servo motors only move between 0~180°, except the one for base. It should move from 0~270°, and according to its data, PWM should be 500us~2500us.
The way I set it now, when I turn RV6_base potentiometer to a certain degree, everything stops working, other motors included. I have to reset Arduino for it to work, sometimes even that doesn't work. I'm guessing the problem is within the code, but I'm out of idea.

This is a clear symptom of a power supply problem, either overloading the servo power supply by stalling one or more servos, or a pot overloading the Arduino 5V power supply.

The servo power supply should be rated for at least 10 Amperes, minimum, as the MG996R stall current is around 2.5 Amperes, which each servo briefly draws every time it starts moving.

Welcome to the forum.

It is a typical power or grounding problem with servo motors. I could be wrong, but it is the first thing to look into.
The stall current for the RDS3218 is about 2A. Your power supply should have no problem to give those amps. When a servo motor starts to move, then it needs a peak current that can be near the stall current.

Is this the Servo Driver board ? https://www.adafruit.com/product/815
Could you please call it a "PCA9685" or a "Adafruit Servo Driver" board, but not a "815".
Schematic: https://learn.adafruit.com/assets/36269

What is the voltage of the battery ?
The Servo Driver board has a maximum of 5.5V and the Arduino VIN has a minimum of 7.5V :grimacing:

Beside the power, there could a grounding problem. The (peak) current goes through the servo motor and that current is going via a GND wire back into the power supply. That current through the GND wire can mess up the I2C bus.
Can you show a photo with the wires, so we can check that ?

While I was writing this, jremington already wrote the same.

I'm using a 306W DC power supply rated for 0~30V, 0~6A, that's the best one I'm currently able to get. 10A sounds bonkers! I'm able to move every 180° motor at the same time except RDS3218 though? When I move 2 motors at the same time, current only goes up to something like 0.2A.

No, not at all. Just the 3 MG996R servos can easily overload a 6A power supply.

The startup/stall current is drawn for about 10 milliseconds, and you need a scope to see it. If the power supply sags sufficiently, the other servos will start moving too, drawing about 7.5A total.

a 306W DC power supply

This is typical advertising nonsense. At the very most, 30V @ 6A is 180 W, and I would be skeptical of that as well.

But the above is just a guess, you have a serious problem somewhere, but haven't posted enough information to be sure of anything.

The Servo Driver board has a maximum of 5.5V and the Arduino VIN has a minimum of 7.5V

If that's the case, I'll have to think of a way to solve that.
Edit: I measured 5.98V from Uno's VIN pin.



The breadboard is another major problem. The tracks are for low power logic, and tend to burn out at currents > 500 mA or so. And the photo shows no sign a "306W power supply", of any description.

Use a servo power distribution PCB. You can buy them or make your own.

BTW I would guess that the RDS3218 servo startup/stall current is > 4A, given the 20 kg-cm torque rating.

Good luck with your project.

I know the power rating is kinda weird when I saw the specs. I think it's weird too. Let's assume it's 180W utmost.

I haven't be able to see more than 1A current drawn though, even when I turn 3 motors at the same time. I don't have a scope though, so what I'm seeing may be averaged number throughout a certain time.

When the "problem" happens, they all stop. No motor gitters. Maybe I should film it.

The power supply might "crowbar", in the trade lingo. Check the manual.

This is what I mean by "they all stop".

What's funny is, if I press "reset" on Arduino board, sometimes it goes back to normal, where all motors except RDS3218 can move freely without any stopping, and when I turn the one for RDS3218, same thing happens.

Thanks for the photos.

A4 = SDA
We missed something :cold_sweat: :exclamation: Sorry.
The I2C bus is at pin A4 (SDA) and A5 (SCL). The pins that you use near the USB connector are also SDA and SCL, they are directly connected to A4 and A5.
That means you can not use A4 for analog input, because it is already used for SDA.

You have only 4 analog inputs. That's all.
If you want more analog inputs, then you need another Arduino board. There might be a trick go make it work with the Arduino Uno.

Voltages
The USB cable to power the Arduino board is good during development. For the final version, there are step-up and step-down voltage converters. Some power the Arduino board with 5V to its 5V pin. There are enough possibilities.

Power
The wires from the Power Supply to the Adafruit Servo Driver board might be too thin.

Grounding
The GND from the Arduino side is connected to the power GND at the Adafruit Servo Driver board. That is good.

Aaaah! Oooooh that makes total sense! That's why only the motor through A4 pin is misbehaving!
I'll change to another board with more analog pins first, and see if that's the problem. That said, I need to order one, so if I have further questions, I'd get back. Thx guys :pray:

Can you tell which Arduino board that you have in mind ?

Some boards have troubles, such as the Arduino Due.
Some boards have a extra chip for WiFi, but it is easier to run a IoT project on a ESP32.
If you want to add a analog NTC temperature sensor, then the analog input of the ESP32 is not good enough.

The Adafruit Servo Driver board is compatible with a 3.3V Arduino board.
I think you can do your project with a Raspberry Pi Pico.

I was thinking of getting a Arduino Mega 2560 Rev3 clone. I can get one for $18 here, but I don't really need that many digital pins.

ESP32 boards sound good, nano one has 8 analog pins and 12-bit resolution with built-in wireless connections. I think I may go with nano ESP32.

Raspberry Pi Pico only has 3 analog pins according to datasheet?

  1. Why the two 0.15 ohm current limiting resistors between the supply and PCA9685 screw terminals. Those thin Dupond wires are for signals, not power.

  2. Yellow wire between servo power and Uno V-in.
    That could drag down USB 5volt backwards through the 5volt regulator when servo power drops below 4volt. Remove that yellow wire!
    Leo..

I checked it, and it has only 3 or 4 analog inputs: https://github.com/arduino/ArduinoCore-mbed/blob/main/variants/RASPBERRY_PI_PICO/pins_arduino.h#L26

The Arduino Nano ESP32 is a ESP32-S3 processor on a board that has the "Nano" format size and with changed pin numbers. You could just as well buy a common ESP32-S3 board.
Wikipedia has a list of the variants: https://en.wikipedia.org/wiki/ESP32.
If you want to use the Arduino Cloud without any fuzz, then the Arduino Nano ESP32 can be a good choice.

My advice: If you buy a ESP32 or a variant, then buy a common board or a Arduino board. The software for the common boards is made by Espressif (the manufacturer of the ESP32) and the Arduino board software is by Arduino. I trust only those two for fixing bugs and maintaining the build environment.

The Arduino Mega 2560 is handy when an Arduino Uno is used with a shield (add-on board) and it has not enough memory. In many cases, the Uno can be exchanged by the Mega board.

1 Like

What do you mean by "two 0.15 ohm current limiting resistors"? You mean the dupont wires?
I'll change them to 0.8mm or 1mm wires. Thx for reminding.

You're right, V+ of servo board doesn't have to be connected to VIN of logic board.

Yes, that is what Wawa meant.

The actual resistance depends on the quality of those wires.
On the Driver module is a capacitor. The schematic says it is 10µF. Is it that small ? That is by far not enough to deal with the peak current of the Servo motors.

See the Servo motors as cookie monsters who eat peak currents every time they start to move.

The capacitor on PCA9685 says 1000µF 10V. Should be enough.
I'm using only a bunch of MG 996Rs and a 20kg servo, so I guess this servo board can handle it.

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