Hello all
Not the greatest programmer, so please bear with me.
I have a master Arduino 2560. This talks to a Mini-Pro and another Mega2560 via I2C.
This I2C link carried out all manner of tasks from controlling multiple LCD screens, sound modules and LED controllers.
All was well and it all appear to work fine.
Upon separating the Arduinos to begin installing them (about 3m apart), I became aware of multiple problems with the interconnecting screened lead picking up interference and messing up the comms.
Most noticeable was the LCD displays randomly showing odd graphics.
No amount of tweeking, error checking etc could cure the issue, so I decide to leave the I2C comms in place only for the LDC screens on a short local Arduino.
I was then going to instead link the 3x Arduinos using Serial1, Serial2 and Serial3 (I know the Mini-pro only has one Serial).
I have a serial link from the master Mega to the Mini pro and that seems to work fine.
But... I just cannot get Serial to Serial comms working between these two Mega's.
Serial3 outputs to Serial1 on the second Mega.
The code is HUGE, so I won't post the whole thing:
//Master Arduino 2560:
//Serial1 is for comms to Bluetooth module 19=RX and 18=tx
//Serial2 is for comms to PSU Mini Pro 17=RX and 16=TX
//Serial3 is for comms to Console/Joystick Mega2560 15=RX and 14=TX
byte Joydata1=50; //What text to display
byte Joydata2=50; //What value to display on the text
void setup() {
pinMode( 19, INPUT_PULLUP ); // fix Serial1
pinMode( 17, INPUT_PULLUP ); // fix Serial2
pinMode( 15, INPUT_PULLUP ); // fix Serial3
Serial1.begin(9600); //Start all the serial links
delay(20);
Serial2.begin(9600);
delay(20);
Serial3.begin(9600);
}
void loop() {
Serial3.write(150); //Start message value
delay(10);
Serial3.write(Joydata1); //What text to display
delay(10);
Serial3.write(Joydata2); //What text to display
delay(10);
}
//Receiving Mega code:
byte JoyData1; //What is received over the joystick serial comms.
byte JoyData2;
byte JoyCheck; //Needs to equal 150 to be a valid command
void setup(){
pinMode( 19, INPUT_PULLUP ); // fix Serial1
pinMode( 17, INPUT_PULLUP ); // fix Serial2
pinMode( 15, INPUT_PULLUP ); // fix Serial3
Serial1.begin(9600);
}
void loop(){
if (Serial1.available()>0) {Read_Serial1 ();} //Check for instruction from MEGA2560
}
void Read_Serial1 (){ //Read the serial data sent from the Mega2560
JoyData1=Serial1.read();
delay(10);
JoyData2=Serial1.read();
delay(10);
JoyCheck=Serial1.read();
Serial.println(JoyData1);
Serial.println(JoyData2);
Serial.println(JoyCheck);
Serial.println("------");
}
Any ideas? The seconds Mega receives nothing. I have tried all the serial ports (including software serial).