I know Serial Communication between boards over the TX & RX has been talked about before and should be easy, but I'm just now trying it for the first time, and nothing is working.
I want my Mega 2560 to send data to my Leonardo, with the Mega using TX1 and RX1. The data I want to send for now is just a single digit value of "1" or "0" from a variable in the Mega to activate a conditional function on the Leonardo. For now I've just been trying to write a simple code to send and receive a number.
I first tried this example: https://iotguider.in/arduino/serial-communication-between-two-arduino-boards/
but that wouldn't work.
I've tried making my own:
Send:
void setup() {
Serial1.begin(9600); // or Serial.begin(9600);
}
void loop() {
Serial1.write(1); // or Serial.write(1)
delay(1);
}
Receive:
void setup() {
Serial.begin(9600);
}
void loop() {
int X = Serial.read();
Serial.println(X);
delay(1);
}
What part am I getting wrong? The Mega shows its TX light illuminated, but the Leonardo shows no activity. Only when the Serial Monitor for it is activated does the TX light illuminate, and the printed value is "-1". I have tried using Serial and Serial1 with the Mega and checking each of its TX/RX ports.
Thank you for any help.