Problems with Basic ESC and Arduino

I’m currently installing T200 thrusters on my ROV and ran into a slight problem with my Arduino controlling the Basic ESCs.

As long as the Serial connection from the topside pc to the Arduino in the ROV is established everything works fine, but as soon as the arduino looses connection, the ESCs spin up to full throttle and only stop when the Arduino is re-connected.

My Software works as follows: The topside computer sends a constant stream of strings to the Arduino over a serial connection. ( strings like this one –> 1500;1200;1900) The Arduino then chops these strings up into the individual signals for the 3 Basic ESCs. The Arduino also sends a “ping” signal to the topside computer to show that it is still running and connected.

Sketch:

#include <Servo.h>
#include <Wire.h>

Servo servor;
Servo servol;
Servo servov;

unsigned long pingTimer;
boolean pinged;
void setup() {

servol.attach(9);
servor.attach(10);
servov.attach(11);

servol.writeMicroseconds(1500);
delay(1000);
servor.writeMicroseconds(1500);
delay(1000);
servov.writeMicroseconds(1500);
delay(1000);

Serial.begin(4800);

pinged = false;
pingTimer = millis();
}
void loop() {

if (pinged) {
pingTimer = millis();
pinged = false;

}

if (millis() - pingTimer >= 1000UL) {
Serial.println(“ping”);
pinged = true;
}

String servo1 = Serial.readStringUntil(‘:’);
String servo2 = Serial.readStringUntil(‘:’);
String servo3 = Serial.readStringUntil(‘:’);

int int_servo1 = servo1.toInt();
int int_servo2 = servo2.toInt();
int int_servo3 = servo3.toInt();

servol.writeMicroseconds(int_servo1);
servor.writeMicroseconds(int_servo2);
servov.writeMicroseconds(int_servo3);

}

 

Has anyone of you experienced a similar thing, or any suggetions how to work around this problem?

Thank you for your help, :slight_smile:

Chris

Try putting the lines “String servo1…”… “servov.write…” in an if statement.
if(Serial.available()) {
“String servo1…”

“servov.write…”
}

Serial.readUntil() is probably returning some value you are not expecting when the serial interface is not connected. This if statement will ensure that you are only adjusting the speed of the motors if there is data in the serial buffer.

-Jacob

Thank you very much for your help, Jacob. This seems to solve the problem.