--- Solution ---
UPDATE: The below solution is NOT 100% reliable, sometimes I have to repeat the 90-10-20 process quite a few times up until I have a proper the ESC properly armed/calibrated. And when I say a few times I mean up to quite a few minutes with battery unplug/re-plug in-between. But now that the craft is mostly finished (I probably just need to tweak the aft side of the skirt), I'll revise my code yet again and see what I can do about it.
In the end the solution was a mix of the regular RC usage instructions:
"Full throttle (stick up); power up ESC & *beeps* ; Throttle 0% (stick down) *beeps* & it's ready to GO!"
& the interactive serial code... once I seen that inserting:
*beeps* 90 <enter> 10 <enter> 20 *beeps* <40 would start the motor at the minimum and progressively incremented it up to 90> ...
...I decided to implement this interation using remote buttons instead of the previously attempted loops...
1x Button for <10> (throttle 0%)
1x Button for <90> (throttle 100%)
and 2x button for increment/decrement by 10 units within that range.
At setup() I set lift fan velocity to 90 (max) and then I just went directly to 10 by pushing the respective button...
...and pushing the increment button after that... eventually led to me hearing the calibration/arming beep. I had however, to be persistant and try this procedure a few times, because either implementation isn't that good and/or I just had some timing issues in the first iterations.
--- Original post ---
I've been trying to control a brushless motor (EMAX CF2812) via ESC with arduino, but so far I've had limited sucess. I've managed to start the motor, but I can't seem to get reproducible results.
The first success I've got was by following the instructions here. From there I also got the following code:
/* * This code is in the public domain. * (Do whatever you want with it.) */// Need the Servo library
#include <Servo.h>// This is our motor.
Servo myMotor;// This is the final output
// written to the motor.
String incomingString;// Set everything up
void setup()
{
// Put the motor to Arduino pin #9
myMotor.attach(9);// Required for I/O from Serial monitor
Serial.begin(9600);
// Print a startup message
Serial.println(“initializing”);
}void loop()
{
// If there is incoming value
if(Serial.available() > 0)
{
// read the value
char ch = Serial.read();
/
If ch isn’t a newline
(linefeed) character,
we will add the character
to the incomingString
/
if (ch != 10){
// Print out the value received
// so that we can see what is
// happening
Serial.print("I have received: ");
Serial.print(ch, DEC);
Serial.print(’\n’);
// Add the character to
// the incomingString
incomingString += ch;
}
// received a newline (linefeed) character
// this means we are done making a string
else
{
// print the incoming string
Serial.println(“I am printing the entire string”);
Serial.println(incomingString);
// Convert the string to an integer
int val = incomingString.toInt();
// print the integer
Serial.println("Printing the value: ");
Serial.println(val);
/
We only want to write an integer between
0 and 180 to the motor.
/
if (val > -1 && val < 181)
{
// Print confirmation that the
// value is between 0 and 180
Serial.println(“Value is between 0 and 180”);
// Write to Servo
myMotor.write(val);
}
// The value is not between 0 and 180.
// We do not want write this value to
// the motor.
else
{
Serial.println(“Value is NOT between 0 and 180”);
// IT’S a TRAP!
Serial.println(“Error with the input”);
}
// Reset the value of the incomingString
incomingString = “”;
}
}
}
It allows to interactively send signals (ints) to control the ESC. After a bit I’ve got some success by sending first a value of 10, followed by 55 (I believe I might have heard the arming beep then) and then I got the motor actually spinning with a value of 120. After a few more tests it seemed like that I would need a value equal or above 100 to make it spin. So, after analyzing the above code I’ve tried to write a stripped down code to programatically control the ESC, the code can be found below:
#include <Servo.h>Servo esc;
void setup()
{
delay(1000);
esc.attach(9); // attaches the servo on pin 9 to the servo object
//delay(1000);
Serial.begin(9600);
esc.write(10);
delay(1000);
//esc.write(90);
}void loop()
{
esc.write(100);
//delay(3500);
//esc.write(0);
//delay(10000);
}
At first, with this code or small variations I got success in making the motor run, alas today when I’ve tried again (with variations) no such luck. When back to the interactive code and managed to make the motor work with a sequence of inputs: 10, 90, 100, 0. However, after stopping the motor (sending zero) I was unable to start it again even with sending values above 100 without resetting the arduino…
So, does anyone can shed some light on what is happening here? How can I “tame” this beguilling ESC?
Further info:
Regarding ESC documentation the beep list found here seems to be the best that can be found.
Also rumaged the web for answers, but couldn’t find anything that I could either wrap my head around or very enlightening :s