ESC Hobbyking Red Brick and Arduino

Hello everyone,

I bought an Hobbyking Red Brick ESC 200A and I want to interface it with my Arduino. I know it works with the servo library.
The motor runs but not in his full range… If I use a modified Sweep example ( I just added a Arming part), the motor starts at servo.write(30). If I change the start value to 30 in the for() loop, the motor does just nothing, it waits again for a couple of 20 seconds before it starts … Is there something wrong in the Arming function or … ? I don’t know, it’s the first time I use an ESC with an Arduino.

Manual:
Manual PDF

Sketch:

/* Sweep
 by BARRAGAN <http://barraganstudio.com> 
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://arduino.cc/en/Tutorial/Sweep
*/ 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9); // attaches the servo on pin 9 to the servo object 
  myservo.write(0);
  delay(3000);
  myservo.write(180);
  delay(3000);
  myservo.write(90);
  delay(5000);
  Serial.begin(9600);
} 
 
void loop() 
{ 
  for(pos = 30; pos <= 150; 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' 
    Serial.println(pos);
    delay(1000);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 150; pos>=30; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    Serial.println(pos);
    delay(1000);                       // waits 15ms for the servo to reach the position 
  } 
}

Cheers,
Dylan

Servo test code that you can use to send servo command values to the arduino.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  Serial.println();
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}

Thanks Zoomcat! I could program now the ESC with your code :) The manual sucks by the way: Full up = 150 and not 180.

But now I can't get in the arming mode. I think there's something wrong with the manual because there are 2 different version. I will contact Hobbyking and let you now the result :)

Cheers, Dylan

Previous post on arming ESCs.

https://www.google.com/search?as_q=esc+arm&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fforum.arduino.cc%2Findex&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=

Thanks Zoomcat! The ESC armed and the motor works well! Thanks for your sketch, it was much easy to program the ESC then. Have some karma :)

Cheers, Dylan