Easy Transfer using Serial 1, 2, and 3 at the same time Mega 2560 and Uno

I am running out of time - Please help if you can. P.S. I had problems with the I2C method - I would rather use direct wiring for the controllers.

The code below is for testing the communication only.

Data being sent is Int values between 0 and 99. The data instructs the sub-controllers to run script codes.

My project is using a Mega 2560 as the main controller and three Uno units as Sub-Controllers. Communication is using Easy Transfer with wiring connecting serial pins 1, 2, 3 on the Mega to the three Uno serial pins. I can get the program to work doing only one serial connection at a time - but I need to communicate on all three serial sets at the same time. Here is the TX program - note that I have modified it to use serial 1. What do I need to do to get Serial 2 and Serial 3 to work with Serial 1.

//   Program for recieving commands over serial TX RX

#include <EasyTransfer.h>

//create object
EasyTransfer ET; 

struct SEND_DATA_STRUCTURE{
 //put your variable definitions here for the data you want to send
 //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
 int Command;
 int pause;
};

//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

void setup(){
 Serial1.begin(9600);
 //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
 ET.begin(details(mydata), &Serial1);
 
 pinMode(13, OUTPUT);
}

void loop(){
 //this is how you access the variables. [name of the group].[variable name]
 mydata.Command = 10;
 mydata.pause = random(5);
 //send the data
 ET.sendData();
 
 //Just for fun, we will blink it out too
  for(int i = mydata.Command; i>0; i--){
     digitalWrite(13, HIGH);
     delay(mydata.pause * 100);
     digitalWrite(13, LOW);
     delay(mydata.pause * 100);
   }
 
 delay(5000);
}

Here is the RX code - do I need to change something here also to make everything work?

// Program for receiving commands over serial TX RX

#include <EasyTransfer.h>

//create object
EasyTransfer ET; 

struct RECEIVE_DATA_STRUCTURE{
 //put your variable definitions here for the data you want to receive
 //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
 int Command;
 int pause;
};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;

void setup(){
 Serial.begin(9600);
 //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 
 ET.begin(details(mydata), &Serial);
 
 pinMode(13, OUTPUT);
 
}

void loop(){
 //check and see if a data packet has come in. 
 if(ET.receiveData()){
   //this is how you access the variables. [name of the group].[variable name]
   //since we have data, we will blink it out. 
   for(int i = mydata.Command; i>0; i--){
     digitalWrite(13, HIGH);
     delay(mydata.pause * 100);
     digitalWrite(13, LOW);
     delay(mydata.pause * 100);
   }
 }
 
 //you should make this delay shorter then your transmit delay or else messages could be lost
 delay(250);
}

Thank You in advance for your help.

Hello,

Please modify your post and add tags around your codes.

I never used this EasyTransfer library. Maybe you simply need to create more EasyTransfer objects in the TX program?

EasyTransfer ET1;
EasyTransfer ET2;
EasyTransfer ET3;

...

Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);

ET1.begin(details(mydata), &Serial1);
ET2.begin(details(mydata), &Serial2);
ET3.begin(details(mydata), &Serial3);

...

ET1.sendData();
ET2.sendData();
ET3.sendData();

Or, maybe you could wire all Uno's RX to the same TX, since you seem to want to send the same data to all Unos?

You should find the examples in Serial Input Basics useful - probably the 2nd example. You could create a separate function for each of the Mega serial ports and they will take in whatever data arrives and store it in char arrays from where you can do other things with it.

...R