Communication between two Arduino Mega - Serial Communication

Hi, I am encountering a weird situation when making two Arduino Mega to communicate via UART.

// On my Mega 1
void setup()
{
 Serial3.begin(115200);
 Serial3.println("hi");

 delay(2000);
 //Serial3.begin(115200);
 Serial3.println("mega");
}

void loop()
{}

Using this coding, my Mega 2 receive ONLY "hi". But if I uncomment the second Serial3.begin(115200), then my Mega 2 receive BOTH "hi" and "mega".

This is weird. Why?

I've change a new Arduino Mega and no more having this problem.

Why would you use a second Serial3.begin() ?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for communication between Arduinos

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R