Nextion communication with arduino mega 2560

Hi guys, I have been trying to have my arduino communicate with the nextion.

This is my code

#include <EasyNextionLibrary.h>
EasyNex myNex(Serial1);

void setup() {
  Serial.begin(9600);
  myNex.begin(9600);
  myNex.writeStr("t0.txt", "Hello");
}

void loop() {
  // Your loop code here
}

After putting the code in the arduino, I set my NX3224F024_011 to have an empty textbox

Please help me

@PerryBebbington

Regarding the connection between the Mega and the Nextion, are you cross connected rx>tx and tx>rx? What pins are you using for Serial1 on the Mega? Is the ground of the Nextion connected to the ground of the Arduino? How is the Nextion being powered?

Are there multiple pages in your HMI program on the Nextion. Are you on the correct page when you try to write the text box?

I would give the Nextion some time to start before sending the text.

#include <EasyNextionLibrary.h>
EasyNex myNex(Serial1);

void setup() {
  Serial.begin(9600);
  myNex.begin(9600);
  delay(500);
  myNex.writeStr("t0.txt", "Hello");
}

void loop() {
  // Your loop code here
}

Hi
Thanks for replying

I only have one page
Its just for testing
I originally intend to make a page where 2 analog input will show value of the input.
a button below it where once pressed, the values on both analogs will freeze

But before doing any of tht, I couldn't even get the communications right
All of the pins connecting are correct
I cross connect the rx and tx as u mentioned
I am using serial1
The nextion is on

But not showing the text "Hello"

In my Nextion I set it as "newtext", the objname is t0

What pins are you using for Serial1 on the Mega? Is the ground of the Nextion connected to the ground of the Arduino? How is the Nextion being powered?

You did not answer these questions. If the grounds are not connected the communication will fail like you are seeing.

Did you try adding the delay( ) as suggested?

Did you ever change the baud rate of the Nextion from the default 9600?

If the issue is not the grounds or the delay( ) please make a zip file of your HMI program and attach it to your post.

Nextion | Arduino
GND | GND
5V | 5V
RX | TX1(PIN 18)
TX | RX1(PIN 19)

I tried adding the delay
the baud is 9600
Its still the same

TEST1.zip (19.0 KB)

Try taking the delay to 2000. I was testing with my hmi code and I was not reliably writing on startup with 500ms.
I'll take a look at your hmi code next.

I don't have a Mega for testing, but your arduino and hmi code are working for me with a Nano Every and Serial 1.

I would suspect a wiring issue. If you are using dupont cables, try replacing them as they can be flakey.

Thanks
I got it back alrdy
I don't know how. But I got it
Thanks