Arming ESC from arduino

Hi,

I am trying to correctly program my ESC from hobby king (http://www.hobbyking.com/hobbyking/store/__14872__H_KING_35A_Fixed_Wing_Brushless_Speed_Controller.html) to control my brushless motor. I have attached the instruction manual for the ESC.
As it says in the Fly your H.King ESC section, it says to arm the ESC, I have to throw the throttle in low position and wait until I hear the double-tone confirming that the ESC has been armed here is my below code from this forum post I found:http://forum.arduino.cc/index.php?topic=20594.0

#include <Servo.h> 

Servo myservo;

void arm(){

 setSpeed(0); 
 delay(1000); 
}

void setSpeed(int speed){
 int angle = map(speed, 0, 100, 0, 180);
 myservo.write(angle);    
}

void setup()
{
 myservo.attach(10);
 arm();  
}


void loop()
{
 
}

I have even tried to put the arm() in the loop, and even putting a delay of 3 seconds, but it still does not arm correctly. I have tried uploading the code, and then connecting my ESC and motor, and even reuploading the code will the ESC and motor are connected, but to no avail. The only code where I have got the motor to successfully run is the code below from the same forum post, but obviously it is just a test and not how the motor should really run:

// this uses the Arduino servo library included with version 0012 

// caution, this code sweeps the motor up to maximum speed !
// make sure the motor is mounted securily before running.

#include <Servo.h> 

Servo myservo;

void arm(){
 // arm the speed controller, modify as necessary for your ESC  
 setSpeed(0); 
 delay(1000); //delay 1 second,  some speed controllers may need longer
}

void setSpeed(int speed){
 // speed is from 0 to 100 where 0 is off and 100 is maximum speed
 //the following maps speed values of 0-100 to angles from 0-180,
 // some speed controllers may need different values, see the ESC instructions
 int angle = map(speed, 0, 100, 0, 180);
 myservo.write(angle);    
}

void setup()
{
 myservo.attach(9);
 arm();  
}


void loop()
{
 int speed;

 // sweep up from 0 to to maximum speed in 20 seconds
 for(speed = 0; speed <= 100; speed += 5) {
   setSpeed(speed);
   delay(1000);
 }
 // sweep back down to 0 speed.
 for(speed = 95; speed > 0; speed -= 5) {
   setSpeed(speed);
   delay(1000);
 }
 setSpeed(0);  
 delay(5000); // stop the motor for 5 seconds
}

I have not found any more documentation on this electric speed controller, and I am unsure of what to do at this point. Any help would be appreciated in at least just getting the ESC to arm. When trying to get the ESC to arm, should I not be sending a 0?

Thanks

IkennaOkafor: When trying to get the ESC to arm, should I not be sending a 0?

probably not......my understanding is that the servo library's 0 to 180 degree range correlates to about a .6 millisecond pulse at 0, and to 2.4 milliseconds at 180. most ESC's I've dealt with(quite a few) require about a 1 ms pulse to arm and remain armed at zero throttle. much lower and it considers there to be no signal and does not arm. increasing the pulse from near 1ms will start the motor with maximum throttle typically being called for around 2 ms.

I've a hunch if you try changing the line in your code from

int angle = map(speed, 0, 100, 0, 180);

to

int angle = map(speed, 0, 100, 39, 140);

that your esc will arm.......let us know

but if it does arm.....I'm not sure what you are going to do with it then? Are you trying to control the speed of the motor using Arduino, or are you trying to program the esc's internal settings?

You can use servo.writeMicroseconds() to be more precise than using degrees.

I’m using ESC’s too and have noticed that by just playing around with the speed signal sent the motor usually activates.

The below code has worked on 2 ESC’s for me so far.

"#include <Servo.h>

Servo myservo;

int pos = 0;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(50);
delay(1000);
myservo.write(60);
delay(1000);
myservo.write(70);
delay(1000);
myservo.write(80);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(100);
delay(1000);
for(pos = 0; pos < 179; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 179; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
delay(10000);
myservo.write(50);
}

void loop()
{
myservo.write(50);
delay(1000);
myservo.write(60);
delay(1000);
myservo.write(70);
delay(1000);
myservo.write(80);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(100);
delay(1000);
for(pos = 0; pos < 179; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 179; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
delay(10000);
myservo.write(50);
} "

Just adjust the code for whatever pin your using.

I think typical hobby RC equipment uses a microsecond range of 1000us to 2000us, and not the 500us to 2500us range which the RC servos may be capable of using. The ESCs may be limited to the 1000us to 2000us control range.