Questions on Arduino Communication and motor programming.

Hey Everybody,

First off my project is an underwater ROV utilizing Arduino MEGA 2560, Arduino ethernet shield, ethernet switch, and raspberry pi for telecommunicating live video (I will be implementing the live video if I do not run out of time).

I just wanted to get some input and advice regarding capabilities to communicate between two Arduino’s. I am currently working on finishing my Senior Capstone project where me and my partner are building an Underwater ROV. My question is centered around communicating commands sent into one Arduino on land via a joystick and sending those commands that were input to the land Arduino into a laptop computer and from the laptop to the second Arduino which will be underwater. The way that I am anticipating sending commands from the computer to the Arduino underwater is through the use of a CAT5-E ethernet cable which will connect from the computer to the components underwater.

Currently I don’t have any joysticks to be able to control the forward/reverse, left/right, and vertical movement of the vehicle. So considering that I am on a very short time constraint I came to the conclusion if the joysticks I ordered do not arrive in time that my best bet is going to be to attempt to control the motors through the Arduino Serial Monitor prompt. The code that I developed compiles fine (after tumultuous debugging through trial and error) but I just wanted to get anyone on this sites opinion regarding whether the code I developed will be compatible with the Serial Monitor prompt to allow me to control the motors, I will post the code I made below! If anyone has any better ideas of how to communicate via the serial monitor based on inputs that I send to it then I would be very happy to hear these and I would take these into very close consideration!

Finally, I also had one more question for you guys too if anyone has the time. This questions revolves around how to use an ethernet switch to send /receive signals from Arduino and raspberry pi to a computer via an ethernet connection. I have an ethernet POE switch which I am hoping to implement in the design to hopefully allow for this capability.

I would appreciate any feedback whether these ideas are feasible or if they are just completely unrealistic. I welcome constructive criticism and if you have any better ideas of how I could make these connections (within the next 2-3 weeks would be preferred) I would be very glad to hear them.

Thank you very much guys and gals!

-Vaughn

P.S. This is my Arduino code to control the motors as I indicated above!

 #include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

const int servoRight = 8;		//initializing servo pins
const int servoLeft = 7;
const int servoUP = 6;
const int servoDOWN = 5;

void setup() {
  
Serial.begin(9600); 			//turn serial on

servo1.attach(8);			//set servo1 pin 8
servo2.attach(7);			//set servo2 pin 7
servo3.attach(6);			//set servo3 pin 6
servo4.attach(5);			//set servo4 pin 5




// send "stop" signal to ESC.

servo1.writeMicroseconds(1500);
servo2.writeMicroseconds(1500);
servo3.writeMicroseconds(1500);
servo4.writeMicroseconds(1500);

delay(5000);	// 5 sec delay to allow the ESC to //recognize the stopped signal

}

void loop() {

if (Serial.available()) {

char a = Serial.read(); //stores first value of the serial input as a character
char b = Serial.read(); //checks if same as necessary input
char c = Serial.read(); // for int values only
char d = Serial.read(); //for int values only
  

// Turning Left, input of TL in serial monitor means Turn Left

Serial.write(a);
Serial.write(b);
Serial.write(c);
Serial.write(d);

if ((a == '1') && (b == '5')) { 
servo1.writeMicroseconds(1500);	//dont move
servo2.writeMicroseconds(1500);
}
//turn left command
else if ((a == 'T') && (b == 'L')) {
servo1.writeMicroseconds(1700);   
servo2.writeMicroseconds(1500);
Serial.write("TL");
}

//turn right command
if (b == 'R') {                
servo1.writeMicroseconds(1500);
servo2.writeMicroseconds(1700);
Serial.write("TR");
}

// Forward command
if (b == '6') {
servo1.writeMicroseconds(1600);	//slow forward
servo2.writeMicroseconds(1600);
}
else if (b == '7') {
servo1.writeMicroseconds(1700);	//faster forward aql5064@psu.edu
servo2.writeMicroseconds(1700);
}

//reverse command
else if (b == '4') {
servo1.writeMicroseconds(1400);	//slow reverse
servo2.writeMicroseconds(1400);
}
else if (b == '3') {
servo1.writeMicroseconds(1300);	//faster reverse
servo2.writeMicroseconds(1300);
}

// Up and Down (Vertical Movement)

else if (b == '6') {          
servo3.writeMicroseconds(1600);
servo4.writeMicroseconds(1600);
}
else if (b == '7') {          
servo3.writeMicroseconds(1700);
servo4.writeMicroseconds(1700);
}
else if (b == '4') {          
servo3.writeMicroseconds(1400);
servo4.writeMicroseconds(1400);
}
else if (b == '3') {          
servo3.writeMicroseconds(1300);
servo4.writeMicroseconds(1300);
}
}

//if no commands given

else {
servo1.writeMicroseconds(1600); // if no forward command
servo2.writeMicroseconds(1600); // then just go straight
servo3.writeMicroseconds(1500); // if no vertical command
servo4.writeMicroseconds(1500); // stay level
}
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

servo1 should be attached to pin 8 I do not know why a smiley face showed up instead.

Sorry and thanks!

-Vaughn