I am working with 4 brushless motors, everytime I try to ramp up the motors using a joystick one or two motors suddenly stops. When I lay off the joystick they reconnect and start working again until I turn up the speed.
Really trying to figure out if it is bad code or a wiring issue before I start going down that road.
#include <Servo.h>
Servo ESC; // create servo object to control the ESC
Servo ESC2;
Servo ESC3;
Servo ESC4;
int potValue; // value from the analog pin
void setup() {
// Attach the ESC on pin 9
ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds)
ESC2.attach(3,1000,2000);
ESC3.attach(6,1000,2000);
ESC4.attach(13,1000,2000);
Serial.begin(9600);
}
void loop() {
potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
potValue = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo library (value between 0 and 180)
ESC.write(potValue - 90); // Send the signal to the ESC
ESC2.write(potValue - 90);
ESC3.write(potValue - 90);
ESC4.write(potValue - 90);
Serial.println(potValue);
Serial.read();
}
It always seems to vary, I just tested 4-5 times, I got up to a potValue of 180, the power dips a little up/down and then the motors cease, followed by a few beeps from the ESC.
Perhaps it is because of the ESC, I have not done anything besides take them out and hook them up, maybe they need to be tuned?
I have it in my desk variable PS and have it at 7.4V, average pull of 3ishA when I have the joystick at 180. I have clocked it dipping down to lowish 6V, 6.2V.
ESCs needs vast amounts of current in reserve, 20A or more might be needed from the supply - they are designed to be powered from powerful LiPo packs which can easily source 50 or 100A.
I think what's happening as soon as the current spikes hit the supply's current limit the voltage drops out and resets everything.
You might try using microseconds instead of degrees since you’re controlling speed, not angle.
#include <Servo.h>
Servo ESC; // create servo object to control the ESC
Servo ESC2;
Servo ESC3;
Servo ESC4;
int potValue; // value from the analog pin
void setup() {
// Attach the ESC on pin 9
ESC.writeMicroseconds(1500); // zero speed
ESC2.writeMicroseconds(1500);
ESC3.writeMicroseconds(1500);
ESC4.writeMicroseconds(1500);
ESC.attach(9);
ESC2.attach(3);
ESC3.attach(6);
ESC4.attach(13);
Serial.begin(9600);
}
void loop() {
potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
// scale it to use it with the servo library (value between 0 and 180)
potValue = map(potValue, 0, 1024, 1000, 2000);
ESC.writeMicroseconds(potValue); // Send the signal to the ESC
ESC2.writeMicroseconds(potValue);
ESC3.writeMicroseconds(potValue);
ESC4.writeMicroseconds(potValue);
Serial.println(potValue);
Serial.read();
}