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
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
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);
}