ESC Serial Monitor Control

Hi All,

I have got a code that works on getting my ESC (MV30002) to work on controlling the brushed motor i have, it works by me inputting numbers into the ‘serial monitor’. is there anyway i can get numbers to automatically enter into the serial monitor, which will allow the esc to ‘arm’, ‘move forward’ and ‘reverse’. Having done research, i have found that arrays may work but i have no experience with using them so if someone can assist it would be much appreciated.

#include <Servo.h>
Servo myservo;

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  delay(1);
  myservo.write(10);
  delay(5000);

}

void loop() {
  while (Serial.available()>0)
  {
    int val= Serial.parseInt();
    
    Serial.println(val);
    myservo.write(val);

esc_control_speed.ino (320 Bytes)

I would try to help, but I cannot open .ino files on my device. If you post the code in code tags as described in the how to use this forum-please read stickies every one can see it.

I suspect a simpler solution for the user would be to create functions within your Arduino code that contain the detailed instructions for the ESC. Then from the Serial Monitor you could have simple commands such as 'A' or 'F' or 'R' for Arm, Forward and Reverse. That way the user would not have to remember any of the technical details.

...R

I understand that but when the code is running to my esc, i type the val '100' and it arms the esc. above '100' to go forward and below to reverse and '100' again to stop. My plan is to make this an autonomous vehicle i need to remove the aspect of the user typing the value in the serial monitor and get a code working which will input the values and get it to work for set times

I don’t think you mean “input” at all but that you want the program to automatically send commands to the motors without needing any specific user input. In that case just write a sequence of myservo.write() commands with the appropriate values.

For initial testing you could perhaps do the timing with delay() commands between the writes but in a real program you’ll almost certainly need to use the millis() technique because you’ll obviously want to be reading sensors at the same time as controlling the motors so it’s worth at least learning about that.

Steve