Hi, Im trying to send some sensor data and motor commands over serial between an Uno and a Mega2650.
Im attempting to use bill porters Easy Transfer library. Im using the following code:
#include <EasyTransfer.h>
//Mega
//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 A;
int B;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
void setup(){
Serial.begin(9600);
Serial3.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), &Serial3);
}
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.
Serial3.print(mydata.A);
Serial3.print(',');
Serial3.println(mydata.B);
}
//you should make this delay shorter then your transmit delay or else messages could be lost
delay(250);
}
//Uno
#include <EasyTransfer.h>
//create object
EasyTransfer ET;
struct SEND_DATA_STRUCTURE{
int A;
int B;
};
//give a name to the group of data
SEND_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);
}
void loop(){
//this is how you access the variables. [name of the group].[variable name]
mydata.A = random(5);
mydata.B = random(5);
//send the data
ET.sendData();
delay(5000);
}
However when running and testing the code, I can see data being sent on the serial window from the Uno but not receiving any at the Mega. Any suggestions?