Can't Get Nextion to Talk to Arduino Mega (and vice versa) [SOLVED]

Hello,

I am working on a project with a Nextion display, but I can't seem to get the Arduino to communicate with my Nextion screen at all. I am using an Arduino Mega (name brand) with a 5" Nextion Enhanced display. I have wired the Nextion to the Arduino via Serial1 (ports 18/19), and I am powering the display directly from the Arduino as well (I have attached an image of my setup below). I checked connectivity on all the wired connections.

I am just trying to change the word "Vacation!" to "hello" (in a simple text box, named t0), using the command t0.txt="hello" terminated properly with three 0xff. Below is my very short script.

//Created as a Nextion communication test

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Sending Change Message to Nextion");
  Serial1.begin(9600);
  delay(500);
  Serial1.print("t0.txt=\"hello\"");
  Serial1.print(0xFF);
  Serial1.print(0xFF);
  Serial1.print(0xFF);
    
}

void loop() {

}

The Serial print statement shows up fine on my computer, but the text box on the Nextion won't change. I have tried a second Arduino, tried using Serial2/3, and I even tried another Nextion (a 7" enhanced). Nothing is working. I have also tried to send information from the Nextion to the Arduino (Send Component ID), but I haven't been able to read any incoming info. I have tried a bunch of other stuff like changing the message I send to the Nextion and even adjusting the baud rate (to my knowledge it defaults to 9600), but none of these fixes are working either.

I have sorted through many forum posts about this, and I am basing my test code off of this excellent tutorial: Using Nextion displays with Arduino - Displays - Arduino Forum.

Any pointers would be greatly appreciated. I have also attached a picture of my nextion editor to show the names of the text boxes.

Thanks in advance! Let me know if you need more information.

Andrew

Arduino Setup.jpg

Nextion Editor.jpg

Ooops..

  Serial1.print(0xFF);
 Serial1.print(0xFF);
 Serial1.print(0xFF);

Isn't that exactly the same as what I have in my code?

Thanks,

Andrew

Hi Andrew,

Correct.
It's wrong, hence the 'ooops'.
Look at the examples.

1 Like

Thanks so much for the response!

So I changed my code to be exactly like the example in your tutorial (which is great, btw), but I still can't get any communication between the Arduino and the Nextion. I also added a functionality in loop() that will print any incoming serial data (I checked that code with the Serial monitor so I know it works). If I add send component ID to my button presses on the Nextion, but I am receiving nothing when I push the buttons. This is my updated code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Sending Change Message to Nextion");
  Serial1.begin(9600);
  delay(500);
  Serial1.print(F("t0.txt=\""));
  Serial1.print(F("stuff"));
  Serial1.print(F("\""));
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
    
}

void loop() {
  if(Serial1.available() > 0){
    int incoming = Serial1.read();
    Serial.println("Recieved: ");
    Serial.println(incoming);
  }
}

Any further help is greatly appreciated.

Thanks!

Andrew

Hello Andrew,
How to post an image
Arduino Setup.jpg
Nextion Editor.jpg

It's not clear on your photo because the Tx and Rx wires from the Nextion change colour off the top of the photo, but it looks like you have them crossed, which would explain both your problems.

The code looks OK to me.

Hi Perry,

Yep, that was the problem. Somehow I didn't realize that TX was supposed to be plugged into RX... noob mistake.

Thanks so much for the help!

Andrew