Communication with Nextion NX8048P070 issue

Hello.
I have used Nextion panels in the past. Today I got a small project that I need to acomplish using NX8048P070 panel and Arduino Mega controller. To refresh my memory I've download an example from EasyNextionLibrary arduino library extension.

I have downloaded the lib, example code and example project for the Nextion panel. Nextion project is attached.
WriteTextAndCommands.zip (23.4 KB)

I set it up to use Serial1. Connected the panel to Serial1 on Arduino Mega board....and nothing happened :frowning:
I was fighting for a day and half and still can't figure it out what is wrong. I tried to use different Serial ports, different Arduino boards. But result is still the same. I will appriciaete for any help!

The code I used:

#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary

EasyNex myNex(Serial1); // Create an object of EasyNex class with the name < myNex >
                       // Set as parameter the Hardware Serial you are going to use

void setup(){
  myNex.begin(9600); // Begin the object with a baud rate of 9600
                       // If no parameter was given in the begin(), the default baud rate of 9600 will be used
}

void loop(){
  myNex.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
  delay(50); // Some time for Nextion to execute the command
  /* Use writeStr(String, String) to change the text in a textbox  
   * Use BOTH parameters
   * In the first parameter, write the objectName.textAttribute example: t0.txt or b0.txt
   * In the second parameter, write the text you want to "print"
   * Any previous text on the textbox is deleted
   */
  myNex.writeStr("t0.txt", "You are now transferred to page0"); // The text in t0 is now this
  delay(2950);

  
  myNex.writeStr("page 1"); // Sending this command to change the page we are on Nextion using pageId
  delay(50); // Some time for Nextion to execute the command
  /* By writing \\r, you send Nextion the change line character < \r >
   * The second \ is required, in order to print the \ as character
   * and not as an escape character.
   */
  myNex.writeStr("t0.txt", "You are now transferred to page1\\r");
  // Avoid using very big text Strings in the same command, as Nextion will not recognise them.
  // Istead use a second command and in order to add to the existing text, use the + symbol, after the .textAttribute("t0.txt+").
  myNex.writeStr("t0.txt+", "This is the:\\rWriteTextAndCommands example");
  myNex.writeStr("t0.txt+", "\\rEvery 3000ms we change page");
  myNex.writeStr("t0.txt+", "\\rAnd we print a text to t0");
  delay(4950);
  
  myNex.writeStr("page page2");
  delay(50); // Some time for Nextion to execute the command
  myNex.writeStr("t0.txt", "You are now transferred to page2\\r");
  myNex.writeStr("t0.txt+", "Thank you\\rfor choosing my library!!!");
  myNex.writeStr("t0.txt+", "\\rEnjoy the library!!!");
  myNex.writeStr("t0.txt+", "\\r\\rAthanasios Seitanis");
  myNex.writeStr("t0.txt+", "\\rseithagta@gmail.com");
  delay(7950);
  
  myNex.writeStr("t0.txt", "Screen will go to sleep mode in");
  myNex.writeStr("t0.txt+", "\\r3...");
  delay(1000);
  myNex.writeStr("t0.txt+", "2...");
  delay(1000);
  myNex.writeStr("t0.txt+", "1...");
  delay(1000);
  myNex.writeStr("t0.txt", "S L E E P\\rSee you in 10 seconds!!!");
  delay(1000);
  
  myNex.writeStr("sleep=1"); // Screen goes to sleep mode
  delay(10000);
  myNex.writeStr("sleep=0"); // Screen exits sleep mode
  delay(100); // Give some time to Nextion to Exit sleep mode

}

For test purpose I tried to do next arduino code as well and it didn't work as well :frowning:

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

void loop() {
  Serial1.print("t0.txt=");
  Serial1.print("test message");
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  delay(5000);
}

I am familiar with Nextion displays but not the Easy Nextion library. From your description I suspect a wiring issue or a problem with your Nextion configuration, although I don't see anything wrong with the HMI file you uploaded.

Please share a schematic of your connections (hand drawn and photographed is fine) and a photo or 2 clearly showing your wiring.

Thanks.

EDIT... just checking something I might have missed...

EDIT^2
You have to send text in quotes, which you are not doing. Try:

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

void loop() {
  Serial1.print(F("t1.txt=\""));
  Serial1.print(F("test message"));
  Serial1.print(F("\""));
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  delay(5000);
}

You are right. I saw my mistake after I posted. I have tried:

void setup() {
  Serial1.begin(9600);
  delay(500);
}

void loop() {
  Serial1.print(F("t0.txt=\""));
  Serial1.print(F("test message"));
  Serial1.print(F("\""));
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  delay(5000);
}

And it didn't work :frowning: Wiring picture below.


I'm breaking my head now, I also tried to order another same display to test it and it didn't work out. Let me know if you see smth wrong with wiring.
I will bring from my home my personal arduino uno and 2.4" nextion to do more testing.

Thank you but your photo does not show your wiring, specifically I cannot see:
Any source of power for either the display or the Mega
Where the yellow wire hidden behind the other wires goes.
Where the wires that go off the photo go.

Please provide a photo that clearly shows ALL the wiring.

Another yellow is common ground.
Arduino was powered up from USB. Touch panel powered from 5V DC power supply.


I hope it's better showing my wiring connection.

I don't see anything obviously wrong but those wires you are using have a reputation for bad connections. I suggest you use a multimeter to check for open circuits.

Also try powering the Mega from the same power supply as the Nextion, with 5V on the 5V pin. Alternatively power the Nextion from the Mega.

See my Nextion tutorial at the top of the Display section of the forum for other ideas.

EDIT...
I've had an another look at your photo, as far as I can see the yellow wire to the PSU is not connected to the same place as the wire for the negative output from the PSU, so is probably not providing the common ground you think it is.

Yes, it was commond ground issue. I have no idea how. I will go with valtmeter over all prototype wiring tomorrow.
I have powered everything from same USB source. and it did transfer a message. I've tried to modify a bit to see some sequencial update on the screen.

int counter = 0;
void setup() {
  counter = 0;
  Serial1.begin(9600);
}

void loop() {
  counter++;
  Serial1.print(F("n0.val="));
  Serial1.print(String(counter));
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  delay(5000);
}

I wrote next logic and it did send an first message and have updated the data on the screen but not updates after.

OK, good :slight_smile: However, you need to know how or why so you don't make the same mistake again. Based on what I can see in the photo it's because you connected the yellow wire to the DC OK connection of the PSU, not to the 0V connection. However, I am not entirely sure I can see the connection clearly.

I don't know what that does or even if it is a valid use of String (I suspect not). Remove the String.

I do not use number boxes on Nextion, there is no need. Use a text box and send the value as text. This is covered in my tutorial.

I will redo the wiring and will provide the update. Becacause in the project I have 2 mega boards and 1 nextion panel. Mega boards needs to be powered up from 12V power supply, at least it was initial plan and have internal step down convertor 12V to 5V. Worst case I will change everything to 120V and install 5V power supply inside to provide power for arduino boards and HMI panel.

About weird update issue. I have added extra Serial to see execution on the arduino board and for some reason it solve the problem. Have no idea why so far, and I need to find out why it's working only when I do Serial Monitoring from PC. As soon I close Serial Monitoring on PC it stops updating the HMI. It's not a mystery, I'm just doing something wrong that I am not aware of.
Updated code:

int counter = 0;
void setup() {
  counter = 0;
  Serial1.begin(9600);
  Serial.begin(9600);
  Serial.println("Start");
}

void loop() {
  counter++;
  Serial1.print(F("t0.txt=\""));
  Serial1.print(String(counter));
  Serial1.print(F("\""));  
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial1.write(0xff);
  Serial.println(counter);
  delay(5000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.