Controlling 60 A ESC. New Coder please help

Hello community,

I am having difficulty programming my Arduino MEGA 2560 to control the PWM signal sent to my ESC to control my 770Kv motor. So far I have been using serial monitor and commanding different PWM values but after I command a certain value, the PWM returns to 0 and the throttle is not sustained, I have tried building an array of all commanded PWM values and if the serial signal is not available the code would refer back to the most recent PWM value and send it to the ESC but that was not a reliable method. Any help would be greatly appreciated. The current code is below.


#include <Servo.h>
Servo ESC;

void setup()
{
Serial.begin(9600);
ESC.attach(9,1000,2000); //PWM Pin Connection Port on Arduino
delay(1);
ESC.write(0); //Activates ESC
delay(5000); //Wait time before commanding throttle values
}

void loop()
{
while(Serial.available() > 0)
{
int val = Serial.parseInt(); //reads integer vals from serial monitor input
Serial.println(val); //Print throttle value
ESC.write(val); //Write throttle value to ESC
}
}

"770 kv motor."

Is that 770,000 volt motor ?

No that is simply a rating associated with this motor. It has to do with voltage and rpm. # of volts given to the motor * Kv rating = theoretical motor RPM.

My guess is that you have Serial Monitor set to "Newline". Try changing it to "No line ending".

Steve

Simple servo test code that might work with your ESC assuming it accepts servo type control pulses.

// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// 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);
}

void loop() {

  while (Serial.available()) {

    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
      delay(3);
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);
    int n = readString.toInt();
    Serial.println(n);
    myservo.writeMicroseconds(n);
    //myservo.write(n);
    readString="";
  } 
}