Looking for some advice on running more than ESC at once. For my application I wish to speed control 4 ESCs/Motors from a single potentiometer. They are they same make ESC, so the programming/arming will be the same for all 4. I have successfully written code for a single ESC
#include "ESC.h"
#define LED_PIN (13) // Pin for the LED
#define POT_PIN (A0) // Analog pin used to connect the potentiometer
ESC myESC (9, 1000, 2000, 500); // ESC_Name (PIN, Minimum Value, Maximum Value, Arm Value)
int val; // variable to read the value from the analog pin
void setup() {
pinMode(LED_PIN, OUTPUT); // LED Visual Output
myESC.arm(); // Send the Arm value
digitalWrite(LED_PIN, HIGH); // LED High Once Armed
Serial.begin(9600); // Start Serial Monitor
delay(5000); // Wait for a while
}
void loop() {
val = analogRead(POT_PIN); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 1000, 2000); // scale it to use it with the ESC (value between 1000 and 2000)
myESC.speed(val); // sets the ESC speed according to the scaled value
Serial.println(val); // Print esc value
Serial.println(analogRead(POT_PIN)); // Print pot value
delay(15); // Wait for a while
}
Please can you help with some sample code or advice on how to control the 4 ESCs
Very much appreciate your help.
Regards Simon
If you are using the same potentiometer to control all of them, you would have to send the same signal to all of them.
Just connect the GND and SIGNAL all together and wire them to Pin 9 (as per example) to control them all at once.
NOTE: Do not connect the center 5V wire together otherwise you will burn their internal voltage regulator.
I had considered that but as the 4 motor are not equally spaced i.e. they have different length cables running from the Arduino to the ESCs I wondered if that would be ok. I am only talking 2 ESCs at 300mm and the other 2 at 800mm.
If I wanted to control the motors independently, is that possible?
Regards Simon
The signal sent from the Arduino to the ESC is a PWM or Pulse Width Modulation type.
It will change the HIGH time going from 0v to 5V so the cable length is not important. (unless you are making it WAY too long and loose voltage over it)
If you want to control them individually and use the library, just create multiple ESC on different PWM capable pins.
I haven’t tested but something like that:
#include "ESC.h"
#define LED_PIN (13) // Pin for the LED
#define POT_PIN (A0) // Analog pin used to connect the potentiometer
ESC myESC1 (3, 1000, 2000, 500); // ESC_Name (PIN, Minimum Value, Maximum Value, Arm Value)
ESC myESC2 (5, 1000, 2000, 500);
ESC myESC3 (6, 1000, 2000, 500);
ESC myESC4 (9, 1000, 2000, 500);
int val; // variable to read the value from the analog pin
void setup() {
pinMode(LED_PIN, OUTPUT); // LED Visual Output
myESC1.arm(); // Send the Arm value
myESC2.arm(); // Send the Arm value
myESC3.arm(); // Send the Arm value
myESC4.arm(); // Send the Arm value
digitalWrite(LED_PIN, HIGH); // LED High Once Armed
delay(5000); // Wait for a while
}
void loop() {
val = analogRead(POT_PIN); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 1000, 2000); // scale it to use it with the ESC (value between 1000 and 2000)
myESC1.speed(val); // sets the ESC speed according to the scaled value
myESC2.speed(val); // sets the ESC speed according to the scaled value
myESC3.speed(val); // sets the ESC speed according to the scaled value
myESC4.speed(val); // sets the ESC speed according to the scaled value
delay(15); // Wait for a while
}
Hi, i found this library very useful.
Previously, i have been using it to control an ESC to control a DC brushed motor, the ESC is micro type and showed below:
See first image
It works perfectly fine with DC brushed motor and the ESC for brushed motor.
Later, I upgraded my setup to DC brushless motor for better performance. I am using this kind of ESC:
See second image
I try to calibrate it and then run Ramp example. It did ramp up, but then the behavior hugely dependent on the delay.
When i remove delay(10) inside the loops for ramp up and ramp down, the signal ramp to quickly to 2000, and the motor can’t keep up with it. It is like given 10 ms to increase to that speed, if time out, proceed with the signal of even higher PWM. At the end, when the signal is ramp to 2000ms, it stop, it doesn’t stay at that speed during the long delay…
What and how can I do so that it will maintains at that speed or PWM when delay or other code are running, unless i use esc.stop() to stop it completely?
I’m not sure I understand your problems and questions here.
The ESC_Ramp example is build to ramp Up and Down and changing the 10ms delay will create issues.
If you need to have the motor stay at full speed, in that example, you have to change de delay between the two ramp section.
Here I added a comment aside the delay.
void loop() {
for (oESC = SPEED_MIN; oESC <= SPEED_MAX; oESC += 1) { // goes from 1000 microseconds to 2000 microseconds
myESC.speed(oESC); // tell ESC to go to the oESC speed value
delay(10); // waits 10ms for the ESC to reach speed
}
delay(1000); // delay after reaching full speed (2000us) and starting to ramp down
for (oESC = SPEED_MAX; oESC >= SPEED_MIN; oESC -= 1) { // goes from 2000 microseconds to 1000 microseconds
myESC.speed(oESC); // tell ESC to go to the oESC speed value
delay(10); // waits 10ms for the ESC to reach speed
}
delay(5000); // Wait for a while before restart
}
Hi @dialfonzo
Thanks for the quick reply.
However, my situation is like this. When i try to change the delay between ramp up and ramp down, the motor just stop for the microseconds mention inside delay, it doesn’t stay at that top speed during the delay, wondering what’s the issue. My ESC require a refresh rate of 50Hz, and since i know this RC_ESC library is based on Servo library and it should inherent the 50Hz refresh rate by default, or it isn’t?
Does delay affect the microseconds pulse that it send? Or should I do something to latch on the outputting of the oESC so that it continuously send like 2000ms pulse forever?
Hope that this explained my situation.
The delay which is present in a “for” section is the amount to time before the value get increased.
However in Arduino code delay() is a complete stop of the code.
I’m currently not setup to test an ESC but here is a code which do not use delay() but be careful since I didn’t test and I’ve used ChatGPT to produce the code.
I’ve ask ChatGPT to use millis() instead of delay() and include variable you can change for the Hold Time
This talk about RC speed controllers and the Arduino library was understandable and educational. The explanation of signal modulation and ESC calibration was really helpful to me it made many technical issues that I had previously missed clear. It’s interesting to note that I looked at a number of assistance sites after completing a university project that included embedded systems and real time control. It made me realize how important precise instructions are, whether you’re writing academically or programming a microcontroller. I discovered academic support platforms throughout my research period, which are very beneficial for specialized topics like write my nursing dissertation. It’s amazing how electronics related abilities like accuracy and organization apply as well to academic writing.