Problem with multiple Arduino comms

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).

You need a more comprehensive system for sending and receiving. Have a look at the 3rd example, and the parse example in Serial Input Basics

The way you are trying to do it in the code in your Original Post there is no means for the receiving Arduino to identify the different pieces of data.

...R

SteveRC2017:
Thanks for that link, but I can't say I understand how that works. Its complicated to Mr newbie here

If you explain what you are having trouble with I will try to help.

...R

Hi,

I²C (Inter-Integrated Circuit), pronounced I-squared-C or I-two-C, is a multi-master, multi-slave, packet switched, single-ended, serialcomputer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication.

I2C is a board level communication system, 3m is stretching the friendship for what it is designed for. ie intra-board.

Tom.... :slight_smile:

TomGeorge:
Hi,I2C is a board level communication system, 3m is stretching the friendship for what it is designed for.

Yes, but there is more than one I2C standard.
Arduinos should be able to do Fastmode+ (30mA/4000pF).

OP might have used the wrong wiring and/or pull up resistors.
Leo..

What sort of wires were used (Pf/m), and how were clock and data connected.
In line or star, and what was the total length.
Did you use extra pull up resistors, and where.
Post a diagram.
Leo..