Home        Store        Docs        Blog

Using Arduino Software Serial for control again


(Richard) #1

I deleted my first post on this subject after a bug showed up. I fixed it and here it is working well through 170 feet of cat3 tether. This is only requires one wire for 3 thruster control as opposed to three. Baud speed is 2400.

//Transmit

void loop() {
xVal = analogRead(xPin);
yVal = analogRead(yPin);
zVal = analogRead(zPin);
xVal = map(xVal,384,641,0,255);
yVal = map(yVal,384,643,0,255);
zVal = map(zVal,0,1023,0,255);
mySerial.write(xVal);
mySerial.write(yVal);
mySerial.write(zVal);
delay(100);
}

//Receive

void loop() {
if (mySerial.available() == 3) {
xVal = mySerial.read();
yVal = mySerial.read();
zVal = mySerial.read();

xVal = map(xVal,0,255,1100,1900);
rightMotor.writeMicroseconds(xVal);

yVal = map(yVal,0,255,1100,1900);
leftMotor.writeMicroseconds(yVal);

zVal = map(zVal,0,255,1100,1900)
vertMotor.writeMicroseconds(zVal);
}
}


(Richard) #2

I get an approximate 2 Hz oscillation/pumping up an down in motor RPM with the above program. Any ideas?