We are building an ROV. We want to control motors through serial from an Arduino. To set the serial we want to use a potentiometer (joystick in the future). The data from the potentiometer is being sent correctly to the Arduino because we see the numbers changing in the serial monitor. Unfortunately, the data sent to the motor control device (jrk 21v3) does not read the serial input at all. This is the board: Pololu - Jrk 21v3 USB Motor Controller with Feedback Here is the code we are using. We think the problem is that the motor control is not reading the serial data correctly.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(19,18); // RX, TX, plug your control line into pin 8 and connect it to the RX pin on the JRK21v3
int serialBytes [10];
int potPin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int motorPin = 18; // TX for motor
int motorPinRX = 19;// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
mySerial.begin(4800);
}// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
val = analogRead(potPin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 1, 1023, 0, 4095); // sca
serialBytes[0] = 0xC0 + (val & 0x1F); // Command byte holds the lower 5 bits of target.
serialBytes[1] = (val >> 5) & 0x7F;
// Serial.println(val);
// Serial.println(voltage);le it to use it with the servo (value between 0 and 180)
// float voltage = val * (5.0 / 1023.0);
mySerial.write(serialBytes[0]);
mySerial.write(serialBytes[1]);
Serial.print(serialBytes[0]);
Serial.println(serialBytes[1]);
Serial.println(val);delay(50); // delay in between reads for stability
}
What are we doing incorrectly?