Servos Jittering and Moving Slightly

Hello,

I am a complete beginner with most electronic things. I applied for a research project through my school to push myself outside of my comfort zone in making a stabilizing leg. This forum is one of my last hopes as even though this project was supposed to be with a teacher, I have not been able to receive much help as my teacher has been in Brazil for the entire duration of the project. The leg design ended up being a hexapod leg that I will need to make code for later for self-stabilization. I have been struggling with getting my servo motors to consistently move.

I am using three Hiwonder servo motors. Two of which are LD-220MG Full Metal Gear Digital Servo with Dual Ball Bearing and 20kg strong torque (Working voltage 6V-8.4V / No-load current 100mA / Stalled current 2.4~3A). The other servo motor is a LD-20MG Full Metal Gear Digital Servo with 20kg high torque(Working voltage 6V-7.4V / No-load current 100mA / Min Working current 1A / Their website did not put a stalled current but I would figure it is still in that 2.4~3A range). All the information on the servos were obtained from the specifications on Hiwonder's website.

Right now, I need to get a better understanding on how to power the servo motors. I am using a Hiletgo PCA9685 16-channel servo driver. There are three servo motors connected to it. The power supply I have is a battery holder that holds four AA batteries. I have four Rayovac High Energy batteries. The datasheet for the battery shows that each battery can have an output of 750mA for around 1.2 hours(each battery is 1.5V). This means I have 6V with a current of 3A. This power supply has in no way been consistent over the past week. I did a demo yesterday where all of the servos were moving 50% of the time when the grey part of the leg was not apart of the project. 50% Meaning sometimes I could get a minute of it moving, while the other times it would just jitter. When the grey part was attached, the servos would either only jitter and move in slight intervals, or they would just make a buzzing noise and not move at all. I know that the increased load makes the current rise, but I have not been able to figure out a way to measure the current draw even after watching a couple videos. I am ignorant of the basic principles in using Arduino or an Ammeter in order to measure the current draw.

Should I just guess the current needed? I would guess I need a total of 4A-5A, but I have not been able to find a set of four AA batteries that fit my specifications. I would like to use the recommended lithium polymer battery for the servo motors, but I don't know how to connect them to the PCA, as the PCA needs stripped wires inserted into clamps for the power supply.



below is a rough set of code that I had used to get the servos moving with the PCA-9685. I couldn't send a video of my leg moving using the accelerometer in my project, so I tried to simplify everything to just the leg with the servo motors, as the code with the accelerometer includes hundreds of lines of code where 95% of it just deals with the accelerometer.

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

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);

// Depending on your servo make, the pulse width min and max may vary, you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  150 // This is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  520 // This is the 'maximum' pulse length count (out of 4096)

#define USMIN  500 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX  2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 100 // Analog servos run at ~50 Hz updates

// our servo # counter
uint8_t servonum    = 0;
uint8_t servonumMax = 1;


void setup() {
  Serial.begin(9600);
  Serial.println("First 2 channels, Servo test!");

  pwm.begin();
  /*
   * In theory the internal oscillator (clock) is 25MHz but it really isn't
   * that precise. You can 'calibrate' this by tweaking this number until
   * you get the PWM update frequency you're expecting!
   * The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
   * is used for calculating things like writeMicroseconds()
   * Analog servos run at ~50 Hz updates, It is importaint to use an
   * oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
   * 1) Attach the oscilloscope to one of the PWM signal pins and ground on
   *    the I2C PCA9685 chip you are setting the value for.
   * 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
   *    expected value (50Hz for most ESCs)
   * Setting the value here is specific to each individual I2C PCA9685 chip and
   * affects the calculations for the PWM update frequency. 
   * Failure to correctly set the int.osc value will cause unexpected PWM results
   */
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);  // Analog servos run at ~50 Hz updates

  delay(10);
}

// You can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. It's not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
  
  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= SERVO_FREQ;   // Analog servos run at ~60 Hz updates
  Serial.print(pulselength); Serial.println(" us per period"); 
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit"); 
  pulse *= 1000000;  // convert input seconds to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {

  int dly = 1000;
  
  pwm.setPWM(0, 0, 515);  //servo 1 PWM is from 515(180 degrees) to 95(0 degrees)
  pwm.setPWM(1,0,492);     //servo 2 PWM is from 492(180 degrees) to 87(0 degrees)
  pwm.setPWM(2,0,492);
  delay(dly);

  pwm.setPWM(0, 0, 305);  //Middle Values
  pwm.setPWM(1,0,290);
  pwm.setPWM(2,0,300);
  delay(dly);

  pwm.setPWM(0, 0, 95);
  pwm.setPWM(1,0,87);
  pwm.setPWM(2,0,90);
  delay(dly);

  pwm.setPWM(0, 0, 305); 
  pwm.setPWM(2,0,492);
  pwm.setPWM(1,0,300);
  delay(dly);
}

All of the helpers have been in the same situation. Nothing wrong in that.
Please read and use this topic: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum

Note the request for links to the datasheet of the devices You use.
Note the request for schematics giving power supply data.

The best way building a system like this is: Start writing code for one device making it work. Then add one more device and continue.
Banging all together is the best way to make fault finding the most difficult.

Your current load will suck down anything short of a Sears Die Hard car battery in short order. You need more power. Those motors are taking their STALL CURRENT most of the time (robots do a lot of start-stop motion).
You need a line powered power supply or stock in a battery company.

1 Like

In addition to what others have said, your basic battery math is incorrect. Four batteries in series will give you your 6V, but you don't sum their current output at the same time, because they're in series. So yeah, you're trying to fight a fire with a straw.

You need someone to advise you on properly powering the project, which must start with a schematic of the project.

No, it means you will have 6V at 750mA. The voltages add the currents don't
Also the 1.5V is not constant it will start at about 1.6V and drop to 0.9V

1 Like

What is the recommended battery?

Most likely, either the power supply is inadequate, or you don't have a common ground.

Hello Mark,

I just switched to using a DC power supply for any testing for the leg. Thank you for pointing me in the right direction! I may still look to use a battery for the project's conclusion, but learning to use a power supply was a great help. I've noted fundamental inadequacies in my knowledge through camsysca's and jim-p's inputs.

Slap an ammeter on the power feed and meter what it actually draws.

Hello Jim,

firstly, I apologize for my ignorance of the understanding of batteries in series. That was incredibly fundamental information that I just looked over, so you have saved me a lot of time.

In relation to battery recommendation, Hiwonder said in the important notes section:
Recommend to use lithium polymer battery with high rate discharge(min 5C), please don't use the dry battery
Hiwonder ld-220mg
Hiwonder ld-20mg

I am sorry for being vague on recommended battery. I do not know of a specific battery that would be sufficient. I also do not know the best place to look. I have tried places like battery junction, but I'm not confident in the required amps that will be drawn. I will look to find this out soon.

Hello Mark,

I put a quick picture with a question after it to just make sure I'm not breaking anything.

Would putting the red lead from the multimeter with the white wire(supplies wire) and then the black wire(multimeter) with the red wire(PCA-9685) measure current drawn? I'm sorry if it is a simple question, I just do not want to risk messing anything up. I know to be careful of allowing the white and black wire to touch when it is powered on, but I do not know if there is anything else to be worried about.

Electrically both servos are the same
The easy way to figure how much current you need is to add all the stall currents
So 3 servos x 3A = 9A.
The voltage can be anything form 6V to 8.4V. 7.4V is common for LI-ion

So you need one 7.4V battery or two 3.7V batteries in series that can deliver at least 9A.
Battery junction is a good place. This would be a good choice:
https://www.batteryjunction.com/panasonic-ncr18650bd-battery.html

Hello Jim,

I have tried to look up explanations on stall current, but I still do not understand it. I had the servos moving with 2-3A with the DC power supply, so I initially thought stall current was when the servo motors start overloading. Is there a better way to think about minimum current vs stall current?

Why do you use a 1 ohm resistor between the power supply and the PCA9685 board?
Leo..

When any motor starts it draws the "stall current" since, by definition, a stopped motor is "stalled". So if you're running three, 2.5A stall current motors your power supply needs to put out 3 × 2.5A or 7.5A plus whatever the rest of the electronics draws, plus a little headroom.
Now a breadboard is not able to carry 2.5A, and your power source leads need to be 16# or 14#.

You don't need to wire up an ammeter since there is one built in to your power supply. Yes, the ammeter goes in series with either power lead.

The stall condition is when the motor shaft is not turning, and in that condition, the motor typically draws 5 to 10X the free running current.

So, a brushed DC motor briefly draws the stall current, every time it starts moving.

In your case, with 3 heavy duty servos, the motor power supply should be rated to comfortably handle more than 3 x 3A, or at least 12 to 15 Amperes at 6V.

A small battery pack is hopelessly inadequate, but a decent "10C" NiMH battery pack for RC vehicles will work.

If you hold the servo shaft and keep it from moving and then command it to move, then the current it draws is the stall current. This will be the largest current the servo will ever draw. The specifications for your servos say stall current = 3A.

Hi, @cameronma
Welcome to the forum.

Can you post some images of your project?
So we can see your component layout.

Don't forget if you have a servo supporting a lever or head, like in your first picture, even though it is not moving, it will consume current to hold it in position against the force of gravity.

What current reading are you getting on the lab power supply?
image

Thanks... Tom.. :smiley: :+1: :coffee: :australia:

Those tiny Dupond wires are meant for signals, not for power.
You will have a massive voltdrop on the servos when they start to move.
Leo..

Hey Tom,

Sorry for the late reply. The current would fluctuate depending on which servo was moving, but it would usually be around 2-4A.