Arduino Leonardo and Uno communication

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!

Serial.println("leo");

Does send 5 characters, not 4 (as you're receiving). The line end is a CR/LF combination.

On the Leonardo you're sending with a cadence 5 times as high as you're receiving on the UNO. After about 5 seconds the buffer will overrun and you'll get a strange result.

pylon:

Serial.println("leo");

Does send 5 characters, not 4 (as you're receiving). The line end is a CR/LF combination.

On the Leonardo you're sending with a cadence 5 times as high as you're receiving on the UNO. After about 5 seconds the buffer will overrun and you'll get a strange result.

Thanks !!

Got it to work !