Hi @XCOLLIER -
By data wires, I think you’re talking about the PWM Servo signals that each ESC receives? If you want to only send power and a single pair of wires down your tether, you could develop code running on your two Arduinos to communicate the desired throttle levels.
Basically, the surface Arduino would read your control input and send a serial message down your tether that contains a list of the throttle positions for your motors, and the subsea Arduino would read and send those throttle signals to a dedicated GPIO PWM output pin for each ESC/T200.
If your tether isn’t too long, a 5V TTL serial link should be fine, but you may need an RS485 adapter to get lengths beyond 15-20 meters?
The Arduino Servo and Serial library should be helpful. I asked ChatGPT for help and got this, it might save you some time? The usual disclaimers of exercising caution with AI generated code apply!
To achieve this task, you’ll need two separate Arduino sketches. The first Arduino will read the positions of two analog-output joysticks and send the calculated throttle levels through Serial1. The second Arduino will receive this data and use it to control four servo motors using the setMicroseconds
method of the Servo
library.
Arduino 1: Reading Joysticks and Sending Data
#include <Arduino.h>
// Joystick pins
const int joystick1X = A0; // X-axis of Joystick 1
const int joystick1Y = A1; // Y-axis of Joystick 1
const int joystick2X = A2; // X-axis of Joystick 2
const int joystick2Y = A3; // Y-axis of Joystick 2
void setup() {
// Start the serial communication
Serial1.begin(115200);
}
void loop() {
// Read joystick values (range from 0 to 1023)
int j1x = analogRead(joystick1X);
int j1y = analogRead(joystick1Y);
int j2x = analogRead(joystick2X);
int j2y = analogRead(joystick2Y);
// Convert joystick values to throttle levels (range from 1000 to 2000)
int throttle1 = map(j1x, 0, 1023, 1000, 2000);
int throttle2 = map(j1y, 0, 1023, 1000, 2000);
int throttle3 = map(j2x, 0, 1023, 1000, 2000);
int throttle4 = map(j2y, 0, 1023, 1000, 2000);
// Send throttle levels as a comma-separated string
Serial1.print(throttle1);
Serial1.print(",");
Serial1.print(throttle2);
Serial1.print(",");
Serial1.print(throttle3);
Serial1.print(",");
Serial1.println(throttle4);
// Short delay to stabilize communication
delay(10);
}
Arduino 2: Receiving Data and Controlling Servos
#include <Arduino.h>
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
void setup() {
// Start the serial communication
Serial1.begin(115200);
// Attach the servos
servo1.attach(9); // Connect the first servo to pin 9
servo2.attach(10); // Connect the second servo to pin 10
servo3.attach(11); // Connect the third servo to pin 11
servo4.attach(12); // Connect the fourth servo to pin 12
}
void loop() {
if (Serial1.available()) {
// Read the incoming data as a string
String data = Serial1.readStringUntil('\n');
// Split the string into four throttle levels
int commaIndex1 = data.indexOf(',');
int throttle1 = data.substring
(0, commaIndex1).toInt();
int commaIndex2 = data.indexOf(',', commaIndex1 + 1);
int throttle2 = data.substring(commaIndex1 + 1, commaIndex2).toInt();
int commaIndex3 = data.indexOf(',', commaIndex2 + 1);
int throttle3 = data.substring(commaIndex2 + 1, commaIndex3).toInt();
int throttle4 = data.substring(commaIndex3 + 1).toInt();
// Set the servo positions
servo1.writeMicroseconds(throttle1);
servo2.writeMicroseconds(throttle2);
servo3.writeMicroseconds(throttle3);
servo4.writeMicroseconds(throttle4);
}
}
This setup ensures that the first Arduino reads the joystick positions, maps them to a range suitable for servo control (1000 to 2000 microseconds), and sends them over Serial1. The second Arduino listens on Serial1, receives the throttle levels, and sets the position of four servos accordingly.
The delay(10)
in the first sketch is a minimal delay to stabilize the communication. You can adjust it based on your specific requirements and the performance of the system.
Remember, the performance of this setup also depends on the hardware capabilities of the Arduinos and the quality of the serial connection.