Control Multiple ESC with a single UNO, problem

Hello, I am trying to run to BLDC motors at either end of a balance to work on a single axis PID loop tutorial I found on youtube.

I have the hardware built, and was testing the motors to be sure they were spinning in the correct direction.
I used a potentiometer to vary the writeMicroseconds value to the Servo object and found that both ESCs turned on about 1250 us . There as some small variation but not much.
The issue develops when I try to write the values to two ESC in the same program.

When I run the program , only one ESC will spin reliably. The 2nd will not turn or won't start until much higher in the potentiometers range. If they are both spinning, they will sputter and slow down without a change in speed value from the potentiometer.

There is also a behavior, in which one will operate flawlessly while the speed input is in a lower range, while the other lags and sputters, but when the speed input gets above a cetain value(example 1450 Microseconds) they swap and the second starts working great wile the first begins to slow and sputter. They are receiving the same value over writeMicroseconds().

Occasionally, after many seconds, they will briefly be near the same speed. But this occurs rarely.
If I disconnect each ESC's control pin individually, each runs exactly as expected, very smooth from 1250 us to 1800us. I swapped the PWM pins , to see if it was related to who received the writeMicroseconds() value first, but the problem remained.

I am using a 12V 30A power supply to run this , and if it were a power issue, I would expect the two ESC to work fine in the low speed ranges, then sputter when the speeds approached the high end.

I am using the Little Bee 20A ESC. I must be getting old because I cannot decipher the beeps. I hear a three tone rising signal, the two lower tones.

#include <Servo.h>//Using servo library to control ESC

Servo esc; //Creating a servo class with name as esc
Servo esc1; //Creating a servo class with name as esc1

int escPin = 12;
int escPin1 = 13;
int minPulseRate = 1000;
int maxPulseRate = 1800;
int throttleChangeDelay = 50;

void setup()

{
Serial.begin(9600);
//Init escs
  initEscs();
delay(1000);
  startUpMotors();
delay(4000);   // Deay for 4 seconds to let ESC power UP correctly
while(Serial.available() == 0) { }  //-snip-  // Wait for operator input before going to the loop()
startUpMotors();


}

void loop()

{

int val; //Creating a variable val
val= analogRead(A0); //Read input from analog pin a0 and store in val
int mappedValOne= map(val, 0, 1023,1250,1700); //mapping val to minimum and maximum(Change if needed)
Serial.print(val);   // Write to the serial monitor so I can see what is happening
Serial.print("\t");
Serial.print("New ESC One Speed is : ");
Serial.println(mappedValOne); 


writeTo2Escs(mappedValOne);
delay(throttleChangeDelay);  // delay so we don' t make changes tooo quickly
}

//Change velocity of the 2 escs at the same time
void writeTo2Escs(int throttle) {
  esc.writeMicroseconds(throttle);
  esc1.writeMicroseconds(throttle);
 
}


//Init escs
void initEscs() {
  esc.attach(escPin, minPulseRate, maxPulseRate);
  esc1.attach(escPin1, minPulseRate, maxPulseRate); 
  //Init motors with 0 value
  writeTo2Escs(0);
}

//Start the motors
void startUpMotors() {
  writeTo2Escs(maxPulseRate );
  delay(1000);
  writeTo2Escs(minPulseRate );
  delay(1000);
}

Try moving the ESC off pin13 as that is the pin connected to the onboard LED.

...R

PS ... To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Thanks for the reply. I just realized I needed to click the picture on the "How to use this forum" link to actually see all the instructions.

I had originally used pins 9 & 10 for the PWM output.

After having so many problems, and reading through a slew of BLDC control pages, I learned that pins 9 and 10 used Timer 1 and could conflict with an AnalogRead() function, although I had no AnalogRead() function in the program .

I switched over to 12 & 13 hoping to alleviate this if that was the issue.

It may be worth my time to use a Mega, that has additional timers and dedicate one to each ESC.

Timer1 has nothing to do with analogRead() - all the details are in the Atmega 328 datasheet.

The Servo library uses Timer1 for all the servos (or ESCs) that it controls.

Have you tried my suggestion of changing from pin 13 to any other pin (except 0 and 1)?

And you have not updated your Original Post to make the code more readable.

...R

I'm not sure it directly affects your problem but why do you need to run startUpMotors() twice?

And why in initEscs() do you try to write a pulse of 0 microseconds to the ESCs? That's not actually what it will do because the Servo library protects you from yourself, but it still looks wrong.

Steve

So Robin2 , thanks for your continued help on this .
First, there is not an Update Previous Post button on this message board that I can find. I looked on the "How to use this Forum " page, and did not see anything remotely referring to" how to edit an old post".

The list of topics is :

  1. Register and sign in
  2. Choose an appropriate forum section
  3. Choose the correct language
  4. Do some research before posting
  5. Click on the New Topic button
  6. Make a meaningful subject line
  7. If you are posting code or error messages, use "code" tags
  8. You can add attachments
  9. You can insert images
  10. Post in proper sentences
  11. Tips for getting the most out of your post
  12. Don't "message" technical questions to people
  13. Forum etiquette
  14. Once you have a response
  15. More tips
  16. X-Y problem

While using this forum may seem like old hat to you, for those of us who have never used this before , some features are not obvious. I would love to add the code tags to my previous posts, but I don't know how to access the previous posts to do that. It took some searching and experimenting to figure out how to do it.

Anyway, I did change the PWM outputs. now I am using a Mega and using Pin 6 (Timer 4) and Pin 44(Timer 5)

So far, no luck. The two motors are still behaving as if they are fighting over resources. Ieven swapped out one for a brand new one out of the bag.

@slipstick, you are correct, that second startUpMotors() was in there because i copied instead of cut.
When I normally start the ESC's I get the da-da-dat........dat-da tone back.
If I remove the initEscs();routine, I don't get the .....dat-da tone, and the motors won't start at all.

An interesting behavior, from about 1250us to 1500us the escPin motor is very powerful relative to the escPin1 motor. Then about 1510 us, the escPin start to back off, and the escPin1 overpowers the other side , controlling the balance of the two. As I increase the pulse width to 1530us and above, the escPin almost shuts down. Then, about every ten seconds , escPin1 seems to power down for a second, the balance shifts and then escPin1 comes back on line. I don't have any imu code in this build, it is strictly turning the motors on and getting them to spin using the potentiometer.

Thanks for the interest

nikom74:
So Robin2 , thanks for your continued help on this .
First, there is not an Update Previous Post button on this message board that I can find.

At the bottom right of all of your Posts there is Quote Quick Edit More. and More expands to Modify Remove

Anyway, I did change the PWM outputs. now I am using a Mega and using Pin 6 (Timer 4) and Pin 44(Timer 5)

So far, no luck. The two motors are still behaving as if they are fighting over resources. Ieven swapped out one for a brand new one out of the bag.

Why have you this obsession with different Timers when I told you that the Servo library just uses Timer1

Make it simple for people to help you. Try the two ESCs on Pins 6 and 7 - they will work on an Uno or Mega.

Post a link to the datasheet for your ESCs (or the two datasheets if they are different).

Have you connected the ESC GND to the Arduino GND?

...R

Turns out I had bought some questionable ESCs, Little Bee 20A. And I had propellers larger than my 2206 motors were rated.
Lots of great learning doing this project.
2206 1900KV Motor s can use 5" or 6" blades.
I replaced the blades and was able to get the system working if I turned the speed up very slowly. However eventually one of the ESC would stop working. I monitored the 12V line going to the ESC and it would get very noisy. One option was to use some 100 uF capacitors across the input voltage, but I was using a 12V 12Ahr battery already. I bought 4 new Emax 12A ESCs , wired them in and they work great, all the way up to 7Amps per motor, which is all I need. Above that and my test bench start to lift off the ground, very cool.
I borrowed a good oscope from work, and the PWM signals from the Arduino look perfect and track exactly what I am commanding.
Time to move on to the PID control