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
}