2 Servos, No go!

I'm having some trouble getting two servos (really a servo and an ESC) working at the same time. With both the ESC and servo running I get jitter in the servo and just some rumbling from the motor through the ESC. I have an RC car I am trying to control and I can control one half of the system at a time with no problems. I can turn the servo fine with a dedicated sketch. And in a separate project I can control the ESC fine. But when I tried to combine the two in a project it no longer worked for me. I'm sure this is a simple problem and I should be able to google it but I must not have the magic search words tonight. Just unrelated topics coming up. I'm thinking it may be a misunderstanding about timers, or the way Arduino implements servo control but I'll leave that to you guys. Perhaps the servo is sharing timers and so screwing both up?

I am not an EE and so can't diagram my wiring but I can explain it in words. I have power for the servo and ESC coming from the ESC's power line. It, like most ESC's, provides 5v power. I have then tied the grounds of the servo and ESC together with the ground of the Arduino. Then I have taken pins 9 and 10 and attached them to the ESC and servo's data line respectively. I tried using a NPN BJT to control the data line but found that was probably unnecessary from posts I've seen around the web.

#include <Servo.h> 
 
Servo esc;  // create servo object to control a servo
Servo steering;
                // a maximum of eight servo objects can be created 
void setup()
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  esc.attach(9);  // attaches the Electronic Speed Controller on pin 9 to the servo object
  steering.attach(10);  // attaches the steering servo on pin 10 to the second servo object
  
  esc.write(90);
  steering.write(90);
  Serial.println("Booting");  // prints hello with ending line break 
  delay(5000);
  Serial.println("Start");
} 
 
 
void loop() 
{
  Serial.println("1");

  for (int j = 0; j < 50; j++)
  {
    for(int i = 0; i < 7; i++)   // goes from 0 degrees to 180 degrees 
    {                            // in steps of 1 degree 
      esc.write(120);             // Go slowly forward
      steering.write(90);        // Turn straight
      delay(15);                 // waits 15ms for the servo to reach the position 
    }
  }
  
  Serial.println("2");
  
  for (int j = 0; j < 50; j++)
  {
    for(int i = 0; i < 7; i++)   // goes from 0 degrees to 180 degrees 
    {                            // in steps of 1 degree 
      esc.write(93);             // Go slowly forward
      steering.write(0);        // Turn straight
      delay(15);                 // waits 15ms for the servo to reach the position 
    }
  }
  
 Serial.println("3");

  for (int j = 0; j < 50; j++)
  {
    for(int i = 0; i < 7; i++)   // goes from 0 degrees to 180 degrees 
    {                            // in steps of 1 degree 
      esc.write(91);             // Go slowly forward
      steering.write(180);        // Turn straight
      delay(15);                 // waits 15ms for the servo to reach the position 
    }
  }
}

The strange for-loop structure is a remnant of what the original failed project looked like and my laziness in modifying it.

Generally there isn't enough power to connect two servos to an Arduino, and have the arduino power everything. You typically want a 2nd power supply that powers the servos/motors. You do want to connect the Arduino ground to the ground of the 2nd power supply.

Hi,

The connections you have described sound right to me - I assume that the ESC is being powered by a high current RC Battery - if not try one.

As for the code, as a first test, remove all of your code from loop and the code from setup after you initially attach the two servo objects.

By default the servo objects will now be sending 1500ms signals which represent 90 degrees - the center point.

If your wiring is good, the servo should be holding the center point, try and move it left and right and you should feel and hear it resisting.

As for the ESC, this is more difficult, most ESCs need to be calibrated to a radio on thier first use, yours may have been calibrated to a center point which is not exactly 1500, lets say it was calibrated to 1540. So your ESC is seeing a 40ms difference from what it thinks is the center point and so it sends a weak signal to the motor to turn, this signal is probably not enough to overcome the friction in the gearbox and so you hear a hum from the motor instead of seeing the wheels turn.

A little more about calibration here, but your best bet is to find the manual for your ESC and write a simple sketch to calibrate it to 1500 centered, 2000 max, 1000 min - only the why calibration section of this post is relevant to your application but have a look anyway -

Duane B

rcarduino.blogspot.com

Thanks for your replies!

Michael: The servo/ESC are actually being powered by the ESC's battery connection (a 7.2V 1800 mAh NiCD battery pack for RC toys). But yes you are correct that if I had used the Arduino for power it wouldn't have been sufficient.

Duane: As a reminder, the ESC works fine without the Servo running simultaneously. I can take this project, comment out the steering servo, and run the ESC, or comment out the ESC, and run the servo. It is only a problem when I attempt to run both simultaneously. I'm beginning to think it could be my circuit and that perhaps I will try and find a way to diagram electrical circuits when I get home from work.

I am familiar with calibration and appreciate the advice! I will do that before I count on this robot to stop when I tell it to! I actually have been working on this for a long time, with a different ESC (a Novak Fusion) that I could not get to work. It had an "arming" sequence that was unpublished which you apparently had to do on startup to operate it. It still didn't work reliably so I tossed it out and went with this other more basic ESC I had lying around.

In the meantime, does anyone see anything wrong? I don't know if I mentioned but I use an Uno (ATMega). Does it have the timer capabilities to run 2 servos on Pins 9, and 10?

Hi,

The servo/ESC are actually being powered by the ESC's battery connection

Battery connection or battery elimination circuit, its not going to make much difference in the short term, but will kill your servo eventually if its the battery.

Duane B

I have then tied the grounds of the servo and ESC together with the ground of the Arduino.

I ran into a similar problem with one of my rovers, and I finally traced it down to 1 too many ground connections. If everything is being powered from the same battery, then there is no need to tie the grounds together (so long as everthing is properly grounded), and doing so will likely cause a ground loop, which can then be a substantial source of noise (as it is essentially acting like an antenna).

Duane: You are correct, it is the BEC coming from the ESC's "servo-style" connector. I believe it's the same power source used by the receiver and thus the servo in a standard RC vehicle. The battery would definitely be a no-no! Thanks for the clarification.

jraskell: Oh boy, I had a problem with one of those in a high-altitude balloon once. Would cause the system to turn off randomly. Was fun when our balloon got to 15k feet and shut off for the rest of the flight! I will look into that. Right now the issue is that the USB is powering the Arduino/Ping Sensor and so I'd need to find a way to power them off the battery as well which I have yet to figure out as the battery is only 7.2V and thus I believe an incompatible source for Vin on the Arduino Uno. I may be wrong on that. I plan to work that out tonight.

Hi,

You can run the Arduino from the main battery if you get a low dropout regulator. Modern regulators can generate 5 v from as little as six volts.

Duane B