Hi everyone,
I'm trying to communicate between arduino Leonardo and Uno but i'm getting some strange data on my serial monitor.
My goal is only to send two diferent messages between both arduinos.
The Uno sends "uno" and Leonardo send "leo"
on arduino Uno I get everything just fine but on Leonardo both menssages are strange, sometimes they manage to appear corretly but most of the times they are just incomplete with missing/strange characters
code of leonardo:
char leo[4] = "leo"; //String data
char mystr[4];
int a=0;
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
if(a==0){
Serial1.write(leo,4); //Write the serial data
a=1;
}
else{
Serial1.readBytes(mystr,4); //Read the serial data and store in var
Serial.println(mystr);
a=0;
}
delay(500);
}
code of Uno:
char mystr[4]; //string recebida do outro arduino | neste caso "Hello" mystr[6]
char uno[4]="uno"; //string escrita e enviada por este arduino | neste caso "ola" ola[4]
int a=0;
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
if(a==0){
Serial.write(uno,4); //Write the serial data
a=1;
}
else{
Serial.readBytes(mystr,4); //Read the serial data and store in var
Serial.println(mystr);
a=0;
}
delay(2500);
}
thanks for your help!