Arduino to Arduino Serial Communication

Hi all,

I know this is a common question on how to communicate between two arduino's using serial, but i can't figure what is going on. I've attached my schematic portion on how the two are connected. I can confirm that there is an electrical connection between the two. I've connected TX to the RX between the two.

There's a lot of code online with one sender and one receiver. Ive tried most of them without any luck.

Receiver code

void setup() {
  // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {
  
   Serial.println(Serial.read());

}

Sender Code

void setup() {
  // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {
  
   Serial.write("test");

}

i've tried using atoi, serial.readbyte(), Serial.print() with no luck.

the output from the receiver side is either -1 for int or 0 for string even though i transmit different values.

i'm not sure if since the atmega32u4 has its USB priority, would it effect any data. on the arduino website it says

The Arduino Leonardo board uses Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX).

ive also tried swapping serial1 as write and read without any luck.

does anyone have any idea whats going on?

thanks a bunch!

You can communicate between two Arduinos (UNO type with just one serial port) using the serial ports and monitor the action using the serial monitor A look at the Arduino schematic to understand the connection between the USB serial connection and the tx/rx pins on the board is helpful. In the below two discussions has some code and information on what is going on. The tx/rx pin connections can be confusing, but it worked when I experimented with it a long time back.

https://forum.arduino.cc/index.php?topic=340105.5;imode

https://forum.arduino.cc/index.php?topic=233906.5;wap2

Hi,

Thanks for your response.

I solved it using serial1. Turns out I forgot to initialize it.

You should also check Serial.available() before you try to read from the serial port.

And you need to connect the grounds of the two boards (if they aren't already)