Hello, I have a project that I am currently working on that requires me to fully program an ESC with an Arduino. All it really needs to do right now is go forward. I understand they need to be calibrated, so in my code I have an arm() command set to pulse the minimum length, then the maximum, then test.
BTW, I found this code on GitHub purely for testing ESCs.
STRANGE PART: I have made multiple different codes, using different pulses, different ways of calibration etc. However, after SUCCESSFULLY running all of these kinds of codes. The next test the ESC/motor will refuse to work. I truly have no idea what the problem is, the connections are fine and the battery is charged an obviously the code is fine if it works one seconds then doesnt the next. Should I just replace the ESC?
CODE:
#include <Servo.h>
// ---------------------------------------------------------------------------
// Customize here pulse lengths as needed
#define MIN_PULSE_LENGTH 1330 // Minimum pulse length in µs
#define MAX_PULSE_LENGTH 2000 // Maximum pulse length in µs
// ---------------------------------------------------------------------------
Servo motA;
char data;
// ---------------------------------------------------------------------------
/**
* Initialisation routine
*/
void setup() {
Serial.begin(9600);
motA.attach(4, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
displayInstructions();
}
/**
* Main function
*/
void loop() {
if (Serial.available()) {
data = Serial.read();
switch (data) {
// 0
case 48 : Serial.println("Sending minimum throttle");
motA.writeMicroseconds(MIN_PULSE_LENGTH);
break;
// 1
case 49 : Serial.println("Sending maximum throttle");
motA.writeMicroseconds(MAX_PULSE_LENGTH);
break;
// 2
case 50 : Serial.print("Running test in 3");
delay(1000);
Serial.print(" 2");
delay(1000);
Serial.println(" 1...");
delay(1000);
test();
break;
}
}
}
/**
* Test function: send min throttle to max throttle to each ESC.
*/
void test()
{
for (int i = MIN_PULSE_LENGTH; i <= MAX_PULSE_LENGTH; i += 5) {
Serial.print("Pulse length = ");
Serial.println(i);
motA.writeMicroseconds(i);
delay(200);
}
Serial.println("STOP");
motA.writeMicroseconds(MIN_PULSE_LENGTH);
}
/**
* Displays instructions to user
*/
void displayInstructions()
{
Serial.println("READY - PLEASE SEND INSTRUCTIONS AS FOLLOWING :");
Serial.println("\t0 : Send min throttle");
Serial.println("\t1 : Send max throttle");
Serial.println("\t2 : Run test function\n");
}