Calibration of ESC after connecting to Arduino

I'm trying to connect an Arduino to an Electronic Speed Control and failing horribly. I'll explain what I've done so far, and then I'll explain the problem.

Before we get there, here's the list of parts I'm using:

-Arduino Uno (genuine)

-6V to 8.4V rated 18300 RPM 350 g-cm brushed motor.

-Traxxas XL-5 brushed motor ESC. 1600 Hz is the highest PWM signal it accepts, if I'm not wrong.

-Venom 4200mAh NiMH 8.4V battery pack (will replace soon with a 7.2V).

So I first connected the ESC to the motor. The connection is this bullet lead connection (the connection seems intact), and then the ESC to the Arduino. I connected the white wire to pin 9 and the black wire to ground. If I'm not wrong, this is the standard servo motor setup. I then plugged the Arduino into my computer, which has an intact USB port. Lastly, I connected the battery pack to the ESC.

Now I've tried to upload some basic code to try and calibrate my ESC, but it just plain our refuses to work. Under no circumstances will the motor run.
The code I'm using just sends the signal sent by the signal monitor.

I'm a complete noob to Arduino, so I don't know what could be wrong. The program I have in mind needs to be able to run while not connected to the computer, activate when a push-button switch is activated, run the motor for a certain distance (which involves an encoder, right?), and then stop.

Any pointers or things I could be doing wrong?

Thanks!

I tried this code:

   #include <Servo.h>

   int value = 0;
   Servo myservo;
   void setup() {
       firstESC.attach(9);    // attached to pin 9
       Serial.begin(9600);    
   }
   void loop() {
       myservo.writeMicroseconds(value);
       if(Serial.available()) 
           value = Serial.parseInt();    // Parse an Integer from Serial
   }

and the one here:

   #include <Servo.h>
   #define MAX_SIGNAL 2000
   #define MIN_SIGNAL 700
   #define MOTOR_PIN 9
   Servo motor;
   void setup() {
       Serial.begin(9600);
       Serial.println("Program begin...");
       Serial.println("This program will calibrate the ESC.");
       
       motor.attach(MOTOR_PIN);
   
       Serial.println("Now writing maximum output.");
       Serial.println("Turn on power source, then wait 2 seconds and press any key.");
     
       motor.writeMicroseconds(MAX_SIGNAL);
   
       // Wait for input
       while (!Serial.available());
       Serial.read();
   
       // Send min output
       Serial.println("Sending minimum output");
       motor.writeMicroseconds(MIN_SIGNAL);
   }
   void loop() {  
   }

^shamelessly copied from the internet

Have you armed the ESC using a RC transmitter? All you have to do is mimic the arming sequence in
software.

I doubt any ESC will arm if started up with maximum throttle.

Start with zero throttle, wait several seconds and then inch it up slowly.

Not really sure what you mean. I'm using the instructions, which can be found here: https://traxxas.com/sites/default/files/KC1761-R01_3018R-XL5_INST_140430-EN.pdf

  1. Connect a fully charged battery pack to the XL-5.

  2. Turn on the transmitter (with the throttle at neutral as described above).

  3. Press and hold the EZ-Set button (A). The LED will first turn green and then red. Once the LED turns red, immediately release the EZ-Set button. The red LED will turn off after three seconds.

  4. Next, the LED will blink RED ONCE. Pull the throttle trigger to the full throttle position and hold it there (B).

  5. After three seconds, the LED will blink RED TWICE. Push the throttle trigger to the full reverse/brake position and hold it there (C).

  6. When the LED blinks GREEN ONCE, programming is complete. The LED will then shine green or red (depending on Low-Voltage Detection setting) indicating the XL-5 is on and at neutral (D).

  7. To turn the XL-5 off, press the EZ-Set button until the green LED turns off.

I've tried doing this. I used the first program and have gotten to the portion where the led is red and does not blink. However, my motor has not ran during any of this calibration procedure. Even more worryingly, if I try to load the sweep example, the light blinks green every 750ms or so. What do I do?

Very simple servo control code you can try. Note that RC rx typically output pulses in an equivalent range to ~45 deg to 135 deg with 90 deg value being neutral. not sure what command functions as high/low on an RC system. You might try the below.

  1. send 90 to arduino

  2. send 45 (or 135)

  3. send 135 (or 45)

  4. send 90 to arduino

  5. try various values between 45 and 135

edit: use the search box in the upper right of this page to search the forum for "ESC" for many previous post on the subject.

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

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 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

Oh, that last idea helped a ton:

so now I'm using this code

#include <Servo.h>

Servo myservo;

void arm()
{
//arm speed controller, modify as necessary for your ESC

Serial.println("Arming");
setSpeed(30);
delay(2000);

setSpeed(90);
delay(2000);

Serial.println("Armed");
setSpeed(30);
delay(2000);

}

void setSpeed(int speed)
{
// speed is from 0 to 100 where 0 is off and 100 is max speed
// the following maps speed values of 0-100 to angles from 0-180

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

}

void setup()
{

Serial.begin(115200);
myservo.attach(9);
arm();

}

void loop()
{
int speed;

Serial.println("Sweeping up");
for(speed = 37; speed <= 90; speed+= 1)
{
  
  setSpeed(speed);
  Serial.println(speed);
  delay(100);
  
}

setSpeed(30);
delay(1000);

Serial.println("Sweeping down");
for(speed = 90; speed >37; speed -=1)
{
  
  setSpeed(speed);
  Serial.println(speed);
  delay(100);
  
}

Serial.println("30 halting...");
setSpeed(30);
delay(5000);

}

So what is this doing? The biggest thing I see here is that the serial is not 9600, but rather 115200. Does that make a difference?

And so now what do I do? Like I said, I'm a complete noob at arduino, so how would I get this program to start on the press of a button? And after this program is complete, what would I do to make it move?

I'm facing the same problems with my XL5. Were you able to get it to work?

Your first example doesn't compile at all, the second uses a min throttle way below the minimum any
RC device uses (700us) which will probably lock-out the ESC immediately. Try 1000us for min throttle.