Establish Serial Comunication between Arduino and ESP32 in a simple way
Budget: $10 – $30 USD
I have an arduino Mega and an ESP32 Pico in my project. I have multiple variables (around 300) in my arduino mega. These are a mix Boolean, Int and double. I want to transmit these variable from the Mega to ESP32 for some processing and transmit them back from ESP32 to Mega as well. The ESP32 and MEGA are connected via Serial3 (RS485) of Mega and Serial2 (RS485)of ESP32. Currently i am able to communicate between the 2 but the issue is that i am unable to segregate the data in independant variables and rather sending as serial data which is very difficult to distinguish and hence multiple checks are to be done back and forth to identify the data and the variable. I want to create a small library for me which i can use in such a way as below:
MEGA CODE:_____________________________
//DECLARATIONS
int intVariables[100];
bool boolVariables[100];
double doubleVariables[100];
//IN LOOP()
if(someEvent){
intVariables[0] = 1000;
intVariables[1] = 2000;
intVariables[2]= 3000; ... and So On..
boolVariables[0] = true;
boolVariables[1] = true;
boolVariables[2]= false; ... and So On..
doubleVariables[0] = 100.25;
doubleVariables[1] = 123.25;
doubleVariables[2]= 254.12; ... and So On..
}
if(someOtherEvent){
int x = intVariables[3] ;
int y = intVariables[4] ;
int z = intVariables[5]; ... and So On..
bool xb = boolVariables[6] ;
bool yb = boolVariables[7] ;
int zb = boolVariables[8]; ... and So On..
double xd = doubleVariables[6] ;
double yd = doubleVariables[7] ;
double zd = doubleVariables[8]; ... and So On..
}
ESP32 CODE:________________________________________________________
//DECLARATIONS
int intVariables[100];
bool boolVariables[100];
double doubleVariables[100];
//IN LOOP()
if(someOtherEvent){
intVariables[0] = 1000;
intVariables[1] = 2000;
intVariables[2]= 3000; ... and So On..
boolVariables[0] = true;
boolVariables[1] = true;
boolVariables[2]= false; ... and So On..
doubleVariables[0] = 100.25;
doubleVariables[1] = 123.25;
doubleVariables[2]= 254.12; ... and So On..
}
if(someEvent){
int x = intVariables[3] ;
int y = intVariables[4] ;
int z = intVariables[5]; ... and So On..
bool xb = boolVariables[6] ;
bool yb = boolVariables[7] ;
int zb = boolVariables[8]; ... and So On..
double xd = doubleVariables[6] ;
double yd = doubleVariables[7] ;
double zd = doubleVariables[8]; ... and So On..
}
I hope this is clear. Please feel free to clarify if anything is not clear. Thanks.
MEGA CODE:_____________________________
//DECLARATIONS
int intVariables[100];
bool boolVariables[100];
double doubleVariables[100];
//IN LOOP()
if(someEvent){
intVariables[0] = 1000;
intVariables[1] = 2000;
intVariables[2]= 3000; ... and So On..
boolVariables[0] = true;
boolVariables[1] = true;
boolVariables[2]= false; ... and So On..
doubleVariables[0] = 100.25;
doubleVariables[1] = 123.25;
doubleVariables[2]= 254.12; ... and So On..
}
if(someOtherEvent){
int x = intVariables[3] ;
int y = intVariables[4] ;
int z = intVariables[5]; ... and So On..
bool xb = boolVariables[6] ;
bool yb = boolVariables[7] ;
int zb = boolVariables[8]; ... and So On..
double xd = doubleVariables[6] ;
double yd = doubleVariables[7] ;
double zd = doubleVariables[8]; ... and So On..
}
ESP32 CODE:________________________________________________________
//DECLARATIONS
int intVariables[100];
bool boolVariables[100];
double doubleVariables[100];
//IN LOOP()
if(someOtherEvent){
intVariables[0] = 1000;
intVariables[1] = 2000;
intVariables[2]= 3000; ... and So On..
boolVariables[0] = true;
boolVariables[1] = true;
boolVariables[2]= false; ... and So On..
doubleVariables[0] = 100.25;
doubleVariables[1] = 123.25;
doubleVariables[2]= 254.12; ... and So On..
}
if(someEvent){
int x = intVariables[3] ;
int y = intVariables[4] ;
int z = intVariables[5]; ... and So On..
bool xb = boolVariables[6] ;
bool yb = boolVariables[7] ;
int zb = boolVariables[8]; ... and So On..
double xd = doubleVariables[6] ;
double yd = doubleVariables[7] ;
double zd = doubleVariables[8]; ... and So On..
}
I hope this is clear. Please feel free to clarify if anything is not clear. Thanks.