MEGA2560 cannot send messages to Nextion display

I've been searching for answers for the past few days and can't seem to make progress on this. I'm attempting a really simple test to update text on a Nextion display.

Hardware:
MEGA 2560
Nextion NX32224T024_011

Connections:
I have the nextion connected to +5V and GND.
Yellow wire from the Nextion (RX) connected to TX1 19 on the board.
Blue wire from the Nextion (TX) connected to RX1 18 on the board.

The display has a single page with two items, text ("t0") and a button ("b0").

The Arduino code looks like this:

#include <SoftwareSerial.h> //Include the library

SoftwareSerial mySerial(18, 19); // RX, TX

void setup() {
  mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}

void loop() { // run over and over
  // Write "test" in the text box t0
  mySerial.print("t0.txt=\"");
  mySerial.print("test");
  mySerial.print("\"");
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);

}

I've also tried this:

void setup() {
  Serial1.begin(9600); // set the data rate for the SoftwareSerial port
}

void loop() { // run over and over
  // Write "test" in the text box t0
  Serial1.print("t0.txt=\"");
  Serial1.print("test");
  Serial1.print("\"");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
}

I've followed half a dozen tutorials at this point, tried using the Nextion library, tried hooking up the Nextion to an ESP8266 and using esphome - nothing has worked.

Any advice is greatly appreciated. Thanks!

Hello duanechew,
++Karma; // For posting your code correctly on your first post.

Yellow wire from the Nextion (RX) connected to TX1 19 on the board.
Blue wire from the Nextion (TX) connected to RX1 18 on the board.

Those would be the wrong way round. See the photos of the connections in 'using Nextion displays with Arduino' at the top of the displays forum (right above where you made you post...)

Why are you using software serial on a board that has 3 hardware serial ports?

void loop() { // run over and over
  // Write "test" in the text box t0
  Serial1.print("t0.txt=\"");
  Serial1.print("test");
  Serial1.print("\"");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
}

That's to fast, it will swamp the serial port with too much data.

Please can I suggest you study my tutorial?

Thanks for the response!

I'm afraid I was mistaken above. I do indeed have the Nextion's yellow wire connected to RX1 18 and the blue wire to TX1 19.

As far as using software serial, it was an experiment after reading a response to another post (I believe written by yourself!). I admit I don't fully understand the usage of software serial.

I have in fact followed your tutorial but I get similar results. The Nextion displays both pages, which I can switch through using the Page 0 and Page 1 buttons. The program loads onto the Arduino without any errors, but there is no change to the Nextion display as instructed by the Arduino code.

For another example, here I've attempted to strip down your tutorial code to the most basic of functions - simple update the text on the Nextion display.

void setup() {
  //This is for the serial monitor. Remove the // if you need to use it.
  //Serial.begin(9600);
  
  //This is for serial port 1, which is the one used for the Nextion in this demonstration. You might need to change this depending on which serial port you are using for your display.
  Serial1.begin(9600);

  //For  demonstration
  HMI_startup_message();
}

void loop() {}


void HMI_startup_message() {
  Serial1.print(F("t0.txt=\""));
  Serial1.print(F("Nextion demonstration by Perry Bebbington. For support go to https://forum.arduino.cc/index.php?board=7.0"));
  Serial1.print(F("\""));
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
}

duanechew:
As far as using software serial, it was an experiment after reading a response to another post (I believe written by yourself!). I admit I don't fully understand the usage of software serial.

Serial ports require special hardware, as in, special electronics dedicated to providing the functionality of a serial port. On a Mega there are 4 such hardware serial ports, the first is used for the USB connection to your PC, the other 3 (1, 2 and 3) are free for you to use as you like.

Software serial uses software to provide the functionality of a hardware serial port but in software. Because it's in software it takes processor cycles away from whatever else you want your program to do and it cannot run anything like as fast as a hardware serial port.

duanechew:
I have in fact followed your tutorial but I get similar results. The Nextion displays both pages, which I can switch through using the Page 0 and Page 1 buttons. The program loads onto the Arduino witout any errors, but there is no change beyond the default Nextion display as instructed by the Arduino code.

My code works, I know this both because I tested it and, more importantly, if it didn't work someone would have told me ages ago.

Check your connections. Check that whatever wire you are using isn't faulty in some way.

Post some photos of how you have it wired up.
How to post an image

PerryBebbington:
Check your connections. Check that whatever wire you are using isn't faulty in some way.

Post some photos of how you have it wired up.
How to post an image

Thanks again for your input - I've updated my previous comment to include another example and a photo of the connections. I've swapped out the jumper wires as well but still no luck.

I'm not sure what else to try at this point. I'm almost convinced there is some sort issue with the display since I've tried interfacing with it from 4 different boards at this points.

I really appreciate your input. Your tutorial was by far the easiest to follow and understand off the many I've read up to this point!

https://forum.arduino.cc/index.php?action=dlattach;topic=698158.0;attach=375547

None of your photos show the connections to the Mega... How are you making the connections?

If you use my Nextion file and my code then you can be sure those are OK. That leaves the connections or the possibility of a faulty Nextion or faulty Mega.

Hopefully these photos will make it a bit more clear.

I do think it's possible the Nextion is faulty.

If I were use do:

Serial2.begin(9600);

instead of:

Serial1.begin(9600);

does that assign to pins TX2 16 and RX2 17 of the Mega? Just curious if I'm understanding that correctly.



...does that assign to pins TX2 16 and RX2 17 of the Mega? Just curious if I'm understanding that correctly.

Correct. You then have to change all your Serial1s to Serial2, and I can guarantee that when you do that you will miss at least one, which you won't be able to find.

Unless ITEAD are now supplying different cables to the ones I got with my Nextion displays you seem to have the end of the cable that is supposed to go to the Nextion connected to your Mega, that being the case how have you connected the other end to the Nextion?

Yellow wire in particular does not look connected very well to me.

PerryBebbington:
Correct. You then have to change all your Serial1s to Serial2, and I can guarantee that when you do that you will miss at least one, which you won't be able to find.

Too true! Thanks for the clarification on that.

You're right - the connector on this has been modified. I've purchased this as part of a kit to fit into an electrical box. https://www.haswitchplate.com/

I was hesitant to believe the work on this was faulty but perhaps I need to peel off the super glue and check the solders underneath.

I've swapped out the jumper wires a number of times and tried to be super diligent about the connections between the devices.

I suggest you take those wires off and replace them with some that can go bare ended into your Mega connectors without the bodge connection in the middle. Use a wire size that fits comfortably into the Mega connectors. If it's stranded then put a little bit of solder on it, just enough to keep the wires together.

That's all from me tonight, far too late for this kind of this now (UK time 23:19)