How to send data from Nano to Mega using Serial Communication

Hello,

I need to send data from Nano to Mega directly. Mega is connected to the PC. Nano is connected via TX1 and RX0 to Mega TX1 and RX1.

In Mega I use Serial1.available() to check if data are available but they are not.

Any ideas?

Nano is powered from Mega, Mega is powered from external PowerSource.

Nano is connected via TX1 and RX0 to Mega TX1 and RX1.

And ground?

I hope you mean Nano TX1 to Mega RX1 and Nano RX0 to Mega TX1.

In Mega I use Serial1.available() to check if data are available but they are not.

What are you using, on the Nano, to make data available on the Mega? Or trying to, anyway.

Nano is powered from Mega

You need to explain how and why.

Have you got the RX/TX wires the correct way round? Try swapping them on one end (nano/mega) only and try again.

I suggest using either the 2nd or 3rd example in Serial Input Basics to receive the data on the Mega and make the code in the Nano comply with that.

…R

PaulS: And ground?

Ground is mutual.

PaulS: I hope you mean Nano TX1 to Mega RX1 and Nano RX0 to Mega TX1.

I have tried both variants. If I join Nano TX1 + Mega TX1 and Nano RX0 + Mega RX1 both arduinos are working (i can see blinking LEDs)

When I join Nano TX1 to Mega RX1 and Nano RX0 to Mega TX1 then Mega freeze.

PaulS: What are you using, on the Nano, to make data available on the Mega?

void setup() { Serial.begin(9600); }

void loop() { Serial.println("test"); delay(1000); }

PaulS: Nano is powered from Mega You need to explain how and why.

I have situation when i need only one USB cable connect with PC - cable from Mega. Mega is powered not from USB but from power source. Nano is not connected to the PC but with Mega.

But I have tried both variants ... both arduinos connected via USB to PC but with the same results = no communication.

(I have not yet tried the examples from Robin2 suggestion.)

I have tried both variants. If I join Nano TX1 + Mega TX1 and Nano RX0 + Mega RX1 both arduinos are working (i can see blinking LEDs)

Connecting the output pin from the Nano to the output pin from the Mega does not make sense.

When I join Nano TX1 to Mega RX1 and Nano RX0 to Mega TX1 then Mega freeze.

How do you know this?

PaulS: Connecting the output pin from the Nano to the output pin from the Mega does not make sense.

I agree. But i have seen actually both information on internet and I was (or I still am) confused. (For example here on Schematic https://www.arduino.cc/en/Tutorial/MultiSerialMega ) That is reason why I tried both ways.

PaulS: ... Mega freeze. How do you know this?

At Mega side I have simple code:

void setup() { pinMode(13, OUTPUT); // system led Serial.begin(9600); Serial1.begin(9600); }

void Loop() { i++;

digitalWrite(13, HIGH); delay(300); digitalWrite(13, LOW); delay(300);

if (Serial1.available()) { s = Serial1.readString(); Serial.println(s); } else Serial.println("notinhg"); }

So I can see LED blinking. In this case it is not blinking.

Ok, I have progress.

After Robin2 suggestion I have repalced Serial.readString() with Serial.read() and it works.

So is SW issue and now it solved.

Thank you guys.