Git Product home page Git Product logo

seithan / easynextionlibrary Goto Github PK

View Code? Open in Web Editor NEW
113.0 9.0 30.0 417 KB

A simple library for Nextion display that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. The library uses a custom protocol that can prove to be a powerful tool for advanced users as it can be easily modified to meet one’s needs.

License: MIT License

C++ 86.14% C 13.86%
nextion

easynextionlibrary's Introduction

Easy Nextion Library

Description

A simple library that uses only four functions. You can easily benefit from Nextion's wide range of features and advantages in just a few easy steps. The library uses a custom protocol that can prove to be a powerful tool for advanced users as it can be easily modified to meet one’s needs. This is an attempt to give a very simple method to use Nextion monitors for beginners at programming and at the same time to be a strong and reliable method that can be capable of satisfying the needs of the advance programming. The handling of Nextion should be as simple and at the same time as professional as a display of this kind deserves.

I have invested time and resources providing open source codes, like this one. Please do not hesitate to support my work! If you found this work useful and has saved you time and effort, just simply paypal me at this Link: [email protected]

You can find more examples, tutorials and projects with Nextion on my website seithan.com or at my YouTube channel Thanasis Seitanis

Installation

First Method

  1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
  2. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
  3. Then search for EasyNextionLibrary using the search bar.
  4. Click on the text area and then select the latest version and install it.

enter image description here

Second Method

  1. Download the latest release of EasyNextionLibrary.
  1. Extract the .zip file
  2. Copy the EasyNextionLibrary folder, to: ....\Arduino\libraries\

NOTE: .HMI files for Nextion Editor are also included in every example's folder. All .HMIs are set for 2.8" Basic screens, so as to be easier to modify it for bigger screens.

The main functions

  • begin();
  • writeNum();
  • writeStr();
  • readNumber();
  • trigger();
  • readStr(); Added with version 1.0.4

And the public variables:

  • currentPageId (Data Type: Integer)
  • lastCurrentPageId (Data Type: Integer)

Functions for user custom command protocol

  • readByte(); Added with version 1.0.5
  • easyNexReadCustomCommand() Added with version 1.0.5 and the public variables for user custom command protocol Added with version 1.0.5
  • cmdGroup (Data Type: Byte)
  • cmdLength (Data Type: Byte)

Details, examples and explanation on custom protocol, can be found on my website at:

4-step Example

  1. Include EasyNextionLibrary and create an object of EasyNex class
#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary

EasyNex myNex(Serial); // Create an object of EasyNex class with the name < myNex > 
                       // Set as parameter the Hardware Serial you are going to use
  1. Begin the object and give the desired baud rate as a parameter. Also, initialize the built-in LED as output
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 
  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output                     
}
  1. Place the NextionListen() function in the loop.
void loop(){
  myNex.NextionListen(); // This function must be called repeatedly to response touch events
                         // from Nextion touch panel. Actually, you should place it in your loop function.
}
  1. Select one of the 50 predefined trigger() functions and use it as a simple void function (nothing returned). Declare the void function by simply writing:
void trigger0(){
[ put your code here !!!!]
}
  • Write the code you want to run in there.
    The trigger0() function will run every time the following sequence of bytes (in HEX format) 23 02 54 00 comes to Arduino's Serial. To do that, write in the Touch Release Event of the button b0, this command: printh 23 02 54 00
void trigger0(){

  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); 
  if(digitalRead(LED_BUILTIN) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(LED_BUILTIN) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}

Enjoy the Easy Nextion Library!! Please do not forget the LED on :)

Full Example Code

/*
 * FourStepExample.ino - Simple example code
 * Copyright (c) 2020 Athanasios Seitanis < [email protected] >. 
 * All rights reserved. EasyNextionLibrary is licensed under the MIT License
 * https://opensource.org/licenses/MIT
 */
#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary

EasyNex myNex(Serial); // 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 
                     
  pinMode(LED_BUILTIN, OUTPUT); // The built-in LED is initialized as an output                     
}

void loop(){
  myNex.NextionListen(); // This function must be called repeatedly to response touch events
                         // from Nextion touch panel. Actually, you should place it in your loop function.
}

void trigger0(){
  /* Create a button on Nextion
   * Write in the Touch Release Event of the button
   * this command:    printh 23 02 54 00
   * Every time the button is pressed, the trigger0() function will run
   * and the code inside will be executed once
   */
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); //If LED_BUILTIN is ON, turn it OFF, or the opposite
  if(digitalRead(LED_BUILTIN) == HIGH){
    myNex.writeNum("b0.bco", 2016); // Set button b0 background color to GREEN (color code: 2016)
    myNex.writeStr("b0.txt", "ON"); // Set button b0 text to "ON"
    
  }else if(digitalRead(LED_BUILTIN) == LOW){
    myNex.writeNum("b0.bco", 63488); // Set button b0 background color to RED (color code: 63488)
    myNex.writeStr("b0.txt", "OFF"); // Set button b0 text to "ON"
  }
}

Function documentation

The various combinations of attribute choices provide a wide range of expected behaviors with many combinations.
This combined with the Nextion Instruction Set creates the opportunity for very powerful HMIs.

NOTE: As these commands are using the Serial port to read and write, it is more preferred not to run them in the loop() without delay(); or some other method of not running them with the frequency of the loop and use them only when it is needed. Using them in a loop, a delay in the loop can be noticed, especially when reading from the Serial. A Serial buffer overflow can also be caused. Also NOTE: (from the Nextion Editor Guide)

In an HMI project a page is a localized unit. When changing pages, the existing page is removed from memory and the > > requested page is then loaded into memory. As such components with a variable scope of local are only accessible while the page they are in is currently loaded. Components within a page that have a variable scope of global are accessible by prefixing the page name to the global component .objname. As an Example: A global Number component n0 on page1 is accessed by page1.n0 . A local Number component n0 on page1 can be accessed by page1.n0 or n0, but there is little sense to try access a local component if the page is not loaded. Only the component attributes of a global component are kept in memory. Event code is never global in nature.

Function trigger();

Associated Library's Code Example: Trigger and FourStepExample

Description: This is the most important function of the library. And this is because, it gives you the ability to use the predefined functions and run your code from there. These predefined functions are named trigger0(), trigger1(), trigger2()... up to trigger50(). You can use them as a simple void function out of the loop, in which you will have written a block of code to run every time it is called. You can call those trigger() functions and run the code they contain anytime by simply writing in a Nextion Event the command: printh 23 02 54 XX , where XX the id for the triggerXX() in HEX. For example in a button's Touch Release Event, write:

Command Function
printh 23 02 54 00 trigger0()
printh 23 02 54 01 trigger1()
... ...
printh 23 02 54 0A trigger10()
... up to ... up to
printh 23 02 54 32 trigger50()

In Arduino code, declare a void trigger() function with the predefined name you want to use and put your code there. Declare the void function by simply writing:

void trigger0(){
[ put your code here !!!!]
}

Example:

#include "EasyNextionLibrary.h"

EasyNex myObject(Serial);
void setup(){
  myObject.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
  myObject.NextionListen();
}
void trigger0(){
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

1st NOTE: To change the predefined names of the trigger() functions, there are details inside the trigger.cpp file and you can add up to 255 functions of this kind. 2nd NOTE: You can send the same printh command, to call the same function, from more than one component from any page, depending on your needs

See Appendix at the end of the document for numbers in HEX table

Function begin();

Parameters: begin(unsigned long) unsigned long: unsigned long baud = 9600 (default) if nothing is written in the begin() function

Description: The begin() method of the class in which we pass the initialization data to the objects.

Syntax:

myObject.begin(115200); // for baud rate 115200

Function writeNum();

Associated Library's Code Example: ReadAndWriteNumber

Parameters: writeNum(String, uint32_t)

  • String = objectname.numericAttribute (example: "n0.val" or "n0.bco".....etc)
  • uint32_t = value (example: 84)(number from 0 to 4,294,967,295)

Description: For writing numbers in numeric attributes in components of any kind (variables, textboxes, etc.).

  • We can change the shown value of a number box
  • We can change the value of a numeric attribute of the design editing commands. Those commands are used to change the attribute of the components (button, text box, timer, numeric etc.) while Nextion is running.
Command Result on n0 comp. Syntax
n0.val=30 Sets n0 component’s shown value to 30 myObject.writeNum("n0.val", 30);
va0.val=30 Sets va0 variable's value to 30 myObject.writeNum("va0.val", 30);
n0.bco=63488 Sets background color to red myObject.writeNum("n0.bco", 63488);
n0.font=0 Sets font to font style with Id = 0 myObject.writeNum("n0.font", 0);
n0.pco=1055 Sets font color to blue myObject.writeNum("n0.pco", 1055);
n0.format=0 Sets value format to decimal myObject.writeNum("n0.format", 0);
With the same way you can change the xcen, ycen, length and isbr

TIP: In a timer component, at the attribute < en >, you can start or stop the timer by writing 0 or 1. Also, at the attribute < tim >, you can set the time the timer is going to repeat the commands written in timer's User-code event.

myObject.writeNum("tm0.en", 0);     // 0 = stop, 1 = start
myObject.writeNum("tm0.tim", 1000); // repeat code every 1000ms

Syntax:

myObject.writeNum("n0.val", 30);    // Set the value of numeric n0 to 30
myObject.writeNum("n0.bco", 63488); // Set background color of n0 to 63488(red)
myObject.writeNum("n0.font", 0);    // Set font to font style with ID 0
myObject.writeNum("n0.pco", 1055);  // Set font color to blue
myObject.writeNum("n0.format", 0);  // Set value format to decimal

NOTE: Only attributes shown in green in the Editor can be both read and changed by user code at runtime. Attribute panel

Send floating-point numbers, a number that has a decimal point.

Or send a number on a textbox

Description: Nextion DOES NOT SUPPORT float numbers. Instead, it uses integer math and does not have real or floating support. The Xfloat component is used for signed 32-bit integer values. The .vvs0 sets the number of digits shown to the left of the decimal (useful for leading zeros). The .vvs1 sets the number of digits shown to the right of the decimal.

You can send Floating-point numbers with these two ways:

  • On a Xfloat component after you convert the float to int and multiply it by 10, the Xfloat component will put a comma , (decimal point) automatically after the last digit if attribute vvs1 is set to 1.

Example:

int tempInt = temperature*10;      // Convert the float to int. Multiply it x10                       
myNex.writeNum("x0.val", tempInt); // Write it to x0 Xfloat component on Nextion

it is obvious that if you want 2 decimal places, you will set the attribute vvs1 to 2 and you will multiply by 100

  • On a Textbox component after you convert the float value to String

Example:

String tempString = String(temperature, 1); // Convert the float value to String, with 1 decimal place
myNex.writeStr("t0.txt", tempString);       // Write the String value to t0 Textbox component

Function writeStr();

Associated Library's Code Example: WriteTextAndCommands

Parameters:

  • writeStr(String, String). To change the .txt attribute in components String No1: objectname.textAttribute (example: "t0.txt" or "b0.txt") String No2: value (example: "Hello World")

  • writeStr(String). To send Designing and System Commands String: The command to send on Nextion

Description: For writing text in Nextion. The two ways the command can be used:

First Usage of the command: Use writeStr( String, String ) to change the text in a textbox Use both parameters to write text in textboxes.

  • 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"

1st Syntax:

myObject.writeStr("t0.txt", "Hello World"); // Change t0 text to "Hello World"

Any previous text on the textbox is deleted

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+").

myObject.writeStr("t0.txt", "You are now transferred to page2\\rThank you\\rfor choosing my library!!!");
myObject.writeStr("t0.txt+", "\\rEnjoy the library!!!");
myObject.writeStr("t0.txt+", "\\r\\rAthanasios Seitanis\\[email protected]");
  /* 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.
   */

Second Usage of the command: Use writeStr( String ) to send Designing and System Commands according to the instructions of Nextion's Instruction Set. Use only the first parameter to send a command to Nextion. The commands must be syntaxed according to Nextion's Instruction Set.

2nd Syntax: Design Commands Example:

myObject.writeStr("page page0"); // Sending this command to change the page we are on Nextion using pageName
myObject.writeStr("page 1"); // Sending this command to change the page we are on Nextion using pageId
myObject.writeStr("cir 100,100,30,RED"); // Renders a hollow Red circle with circle center at (100,100)

System Commands Example:

myObject.writeStr("dim=50"); // Set the current brightness level to 50%
myObject.writeStr("sleep=1"); // sleep=1 (Enter sleep mode) or sleep=0 (Exit sleep mode)

NOTE: When you decide to exit the sleep mode on Nextion, use a small delay of 50ms, in order to give Nextion some time to Exit sleep mode. WARNING: DO NOT send commands that causes data return over Serial to MCU, unless you know what you are doing. Commands that cause data return over serial: print, prints, printh, sendme, get, rept, rdfile, twfile TIP: Write in the debug mode the command to check if it is written correctly

Function readNumber();

Associated Library's Code Example: ReadAndWriteNumber

Parameters: readNumber(String)

  • String: objectname.numericAttribute (example: "va0.val" "n0.val", "n0.pco", "n0.bco"...etc)

Description: We use it to read the value of every components' numeric attribute from Nextion (value, bco color, pco color...etc)

In case the function fails to read the new value, it will return the number 777777. The reasons of getting 777777: (from release 1.0.2 and above)

  • Waiting bytes have not come to Serial timeout
  • Command start character is not found in Serial timeout
  • The waiting length of the byte package has not come to Serial
  • Bytes on Serial are not the expected The chances of getting a wrong value is one in a million. You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value. You can check it with an if() statement, in which you will ignore the value of 777777 and you can run the readNumber() again or set a safe value or use the last good known value method.
uint32_t number = 0;
uint32_t lastnumber = 0;

number = myNex.readNumber("n0.val");   // We read the value of n0 and store it to number variable
    
if(number != 777777){       // 777777is the return value if the code fails to read the new value
  lastnumber = number;
  
} else if(number == 777777){
    number = lastNumber;
}

Syntax:

unsigned long x = myObject.readNumber("n0.val"); // Store to x the value of numeric box n0
unsigned long x = myObject.readNumber("va0.val"); // Store to x the value of the variable va0
unsigned int y = myObject.readNumber("b0.bco"); // Strore to y the color number of the background of button b0

NOTE: Only attributes shown in green in the Editor can be both read and changed by user code at runtime. To

Function readStr();

Associated Library's Code Example: ReadString

Parameters: readStr(String)

  • String: objectname.textAttribute (example: "t0.txt", "va0.txt", "b0.txt"...etc)

Description: We use it to read the value of every components' text attribute from Nextion (txt etc...)

In case the function fails to read the new value, it will return the text ERROR. The reasons of getting ERROR: (from release 1.0.4 and above)

  • Serial buffer occupied timeout
  • Waiting bytes have not come to Serial timeout
  • Command start character is not found in Serial timeout
  • The end of the command has not come to Serial

The chances of getting a wrong value is one in a million. You can use this, fail return value, feature in your code, in case you handle sensitive value data, to confirm that you have the right value. You can check it with an if() statement, in which you will ignore the value of ERROR and you can run the readStr() again or set a safe value or use the last good known value method.

String text = "";
String lastText = "";

text = myNex.readStr("t0.txt");   // We read the value of t0 and store it
    
if(text.equals("ERROR") == false){       // ERROR is the return value if the code fails to read the new value
  lastText = text;
  
} else if(text.equals("ERROR") == true){
    text = lastText;
}

Syntax:

String x = myObject.readStr("t0.txt"); // Store to x the value of text box t0

Library Public Variables

Associated Library's Code Example: ChangePagesAndSentFloatValues

1st Variable: currentPageId A variable that stores the ID number of the current page loaded on Nextion. It is VERY important that Nextion and Arduino are synced and when you send data, the data goes to the right page.

NOTE: In order to update this variable with the current Id of the page, you must write the Preinitialize Event of every page: printh 23 02 50 XX , where XX the id of the page in HEX.
For page0: printh 23 02 50 00 for page9: printh23 02 50 09 for page10: printh 23 02 50 0A

See Appendix at the end of the document for numbers in HEX table

It can be called by writing:

int x = myObject.currentPageId; // Store to x the currentPageId

Example:

if(myObject.currentPageId == 0){
  myObject.writeStr("t0.txt", "You are on page0!");
}else if(myObject.currentPageId == 1){
  myObject.writeStr("t0.txt", "You are on page1!");
}

2nd Variable: lastCurrentPageId This variable stores the last value of currentPageId before currentPageId is changed. We use it to check if the page we are on has changed, in order to send refreshing screen data to the components of the page.

After that, it can be set to equal with the currentPageId, in order not to send unnecessary data for refreshing the components.

if(myObject.currentPageId != myObject.lastCurrentPageId){
  if(myObject.currentPageId == 0){
    [send the data to refresh the page0]
  }else if(myObject.currentPageId == 1){
    [send the data to refresh the page1]
  }
  myObject.lastCurrentPageId = myObject.currentPageId;
}

Find more on the Library's Example: ChangePagesAndSentFloatValues TIP: You can read the ID of the current Loaded page at anytime, without the use of the Library's commands using the dp system command

int x = myObject.readNumber("dp"); // Store to x the ID of the current Loaded page

Function easyNexReadCustomCommand()

easyNexReadCustomCommand() has a weak attribute and will be created only when user declares this function in the main code. More for custom protocol and commands https://seithan.com/Easy-Nextion-Library/Custom-Protocol/ Our commands will have this format: # len cmd id id2 and we must send them from Nextion as HEX with the printh command. For example: printh 23 03 4C 01 01

  • # start marker, declares that a command follows
  • len declares the number of bytes that will be received
  • cmd declares the task of the command or command group
  • id declares the properties of the command
  • id2 a second property for the command

When we send a custom command with the above format, the function NextionListen() will capture the start marker # and the len (first 2 bytes) and it will wait until all the bytes of the command, as we have declared with the len byte, arrive to the Serial buffer and inside the timeout limits. After that, the function will read the next byte, which is the command group and the function readCommand() takes over and through a switch command tries to match the _cmd variable that holds the command group value with the statements of the cases. If we do NOT have a match with the predefined, cmd of P for page and T for triggers, it will continue to the default where we store the _cmd and _len to the public variables cmdGroup and cmdLenght as we are going to need access to them from the main code in the next step. Next we call the the easyNexReadCustomCommand() with the precondition and ONLY if we have declared the function in the main code. From this point we can handle the assign of cmdGroup and IDs from the easyNexReadCustomCommand() in the user code, where we can go on with a switch case for the cmdGroup, the one that we have stored the _cmd for public use and we can call it with myObject.cmdGroup. This is why we made cmdGroup a public variable.

As an example, we use 2 arrays (tables) of integers, where we are going to change the value of the position (element) with custom commands.

 int dataL[4] = {0,0,0,0}; //values 0 or 255, because we use only one byte
 int dataS[4] = {0,0,0,0}; // values from 0 to 255, because we use only one byte

The format is the known: # len cmd id id2

  • where the id referred to the position (element) of the array we want to write on
  • And id2 carries the value to be written on the element of array.

The custom command from Nextion: printh 23 03 4C 00 0A

  • 4C is the Hex for letter L and we refer to the array dataL[]
  • 00 Hex of Dec number 0 used as the index for each array element
  • 0A Hex of Dec number 10 is the value we are going to write on element 0

After the command is executed by our code, the values on dataL[] array will be

  • dataL[4] = {10,0,0,0}

Same for the dataS[] intead that cmd is the 53 in Hex for letter S

void easyNexReadCustomCommand(){

  int arrayPlace; // temp variable
  int value;      // temp variable
  
  switch(myNex.cmdGroup){
    
    case 'L': // Or <case 0x4C:>  If 'L' matches
    // we are going to write values in specific places in the dataL[] table
    // read the next byte that determines the position on the table
    arrayPlace = myNex.readByte();
    
    // read the next byte that keeps the value for the position
    value = myNex.readByte();
    
    // update the array with the new values
    dataL[arrayPlace] = value;  
    
    break; 

    case 'S': // Or <case 0x53:>  If 'S' matches 
    
    // we are going to write values in specific places in the dataS[] table
    // from Nextion printh 23 03 53 00 00
    // read the next byte that determines the position on the table
    arrayPlace = myNex.readByte();
    
    // read the next byte that keeps the value for the position
    value = myNex.readByte();
    
    // update the array with the new values
    dataS[arrayPlace] = value;  
    
    break;
  }  
}

Usefull Tips

Manage Variables You can read/write the variables as any other component.

Use readNumber() to read the value of a numeric variable.
Example: myNex.readNumber("va0.val");
BUT: myNex.readNumber("sys0");

Use writeNum() to change the value of a numeric variable.
Example: myNex.writeNum("va0.val", 255);
BUT: myNex.readNumber("sys0", 375);

Use readStr() to read the text of a String variable.
Example: myNex.readStr("va0.txt");

Use writeStr() to change the text of a String variable.
Example: myNex.writeStr("va0.txt", "Hello World"); For this to happen, the variables you want to read/write must be at the page you are currently on.
Otherwise, if the variables are of global scope, you will need to use a prefix with the page name that the variables are at.
Example:
myNex.readNumber("page0.va0.val"); // If the variable is at page0
The same goes for the other functions as well.

Compatibility

  • Arduino
  • ESP

Tested MCUs:

  1. Arduino NANO
  2. Arduino MEGA 2560
  3. Arduino UNO
  4. WeMos D1 mini ESP8266

Releases:

Release 1.0.6

  • Corrected line 264 of EasyNextionLibrary.cpp, where the "=" should be "==".
if(_endOfCommandFound == true)

Thank you Denis, Gixy31

Release 1.0.5

  • Updated readNumber() function for faster response and more accurate reading.
  • Added the readByte() function for reading Serial buffer from user code
  • Added easyNexReadCustomCommand() function with a weak attribute and will be created only when user declares this function in the main code. The motivation to move this function out of the library's files, comes from Ricardo Reis thanks to his issue #15
  • Added public variables cmdGroup and cmdLength ONLY for read custom commands, stores the command group ID and the length of the command

Release 1.0.4

  • Added the readStr() function for reading a String from Nextion

Release 1.0.3

Two more examples were added.

  • The first one demonstrates how to use EasyNextionLibrary with waveforms.
  • The second one demonstrates how to use EasyNextionLibrary with progress bars

Release 1.0.2

  • Remove the private function readCommand() from the main EasyNextionLibrary.cpp file. A new file is created named readCustomCommands.cpp, in order to make easier the modifications for it when using the custom protocol.
  • Return Error code added and to other cases of readNumberFromSerial(). When failing to read a number, we return the number 777777 instead. The cases of having a 777777 return:
    • Waiting bytes have not come to Serial timeout
    • Command start character is not found in Serial timeout
    • The waiting length of the byte package has not come to Serial
    • Bytes on Serial are not the expected
  • The function readNumberFromSerial() is improved, making reading values more accurate, due to hardware or Serial problems.

Licence

This library is licensed under MIT X11 license. Copyright (C) <2020> Athanasios Seitanis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Athanasios Seitanis or the name of EasyNextionLibrary shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Athanasios Seitanis. Also, prior written permission is required if this software or any part of it or any modifications of it, are used for commercial purposes.

By using this software, you agree with the above terms and conditions as they are. The owner of the software has the right to change the terms of this license at any time without a prior notification.

Appendix

Numbers in HEX:

DEC HEX - DEC HEX - DEC HEX - DEC HEX
0 00 - 16 10 - 32 20 - 48 30
1 01 - 17 11 - 33 21 - 49 31
2 02 - 18 12 - 34 22 - 50 32
3 03 - 19 13 - 35 23 - 51 33
4 04 - 20 14 - 36 24 - 52 34
5 05 - 21 15 - 37 25 - 53 35
6 06 - 22 16 - 38 26 - 54 36
7 07 - 23 17 - 39 27 - 55 37
8 08 - 24 18 - 40 28 - 56 38
9 09 - 25 19 - 41 29 - 57 39
10 0A - 26 1A - 42 2A - 58 3A
11 0B - 27 1B - 43 2B - 59 3B
12 0C - 28 1C - 44 2C - 60 3C
13 0D - 29 1D - 45 2D - 61 3D
14 0E - 30 1E - 46 2E - 62 3E
15 0F - 31 1F - 47 2F - 63 3F

easynextionlibrary's People

Contributors

seithan avatar zer0-bit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easynextionlibrary's Issues

Unable to read/write values from/to Nextion

First of all like many people posting here many thanks for this super library. It allows many people like me who is not impressed by the Nextion library and forum which is non existant to be able to use the Nextion displays.

I have been using the EasyNextionLibrary with an ESP32 for many months without any issues other then fixing normal development bugs. With all the good documentation I was able to develop a complex application using the library with the trigger() functionality.

I have been able to read/write values from/to variables using the readNumber/writeNum without any problem. Suddenly I can't read/write anymore. When reading a number with the following code: TempToReach = yNex.readNumber("nTempToReach.val"), I get an error. Same thing when trying to write with: myNex.writeNum("nDateYear.val", RTCYear); the value is not updated on the Nextion like it was before.

What is strange is that I know the communication between the Nextion and the ESP32 works because I put Serial.print commands in the ESP32 code and I print when I get to the ESP32 after the Nextion executes the printh 23 02 54 XX.

Any idea what may have cause this functionality to cease functioning after so many months? I tried many small tutorial files with the same issue.

Turkish Characters

Hello I use this func myNex.writeStr and its can not send turkish characters, How can I fix it ? And Thanks for this beautiful library :) it is very simple to use it ı think better than iteadlib.

Unable to Read Strings Back (readStr())

Seithan;

I've run into the same problem as in issue #24. As you suggested there, I modified the EasyNextionLibrary.cpp for ERROR, ERROR1, ERROR2, and ERROR3 and now I'm getting ERROR2 each time I try to read back a string (line 129, if 0x70 is not detected). The odd thing is that I was able to read them back previously, but I must have changed something unwittingly and messed things up.

  • I lengthened the wait time on line 128 from 100UL to 200UL, but it made no difference.
  • I have checked that the commons (GND) are the same for both the Nextion and the MKRZero board (actually a P1AM-GPIO board).
  • I've tried different baud rates, 4800 to 19200, but that doesn't seem to make any difference either.
  • The signals to/from the Nextion are passing through 3.3V to 5V level shifters.

Thanks for your time in this. Otherwise a great library

Software Serial Pin definition

Hi
Im trying to use your library but where are you defining your software serial pin allocations/definitions?
surley it suppose to be in the main example and not hidden in library somewhere? im trying to use it on a NANO that does not have multiple serials so need to use other pins

Read data from EEPROM of nextion to arduino and store as float or veriable.

Thanks for this great work it help me alot and save my time.

I am working on a project where I store all variable and float reading on nextion EEPROM. No I want to read that data over the serial with below command so every time when run the setup it will store all variable on arduino from nextion. because I am facing the issue when I read directly from nextion with "myNex.read Number" it missed first variable .

rept 30,20 // sends 20 bytes from EEPROM addresses 30 to 49 to serial// byte of data is not ASCII text of byte value, but raw byte

Thanks,

How to read page name

Now i need the printh Line for reading that the page was changed.
How can i do it without printh 23 02 50 01 ?

How is it possible to send the page name like this:
print "#2P"
print pages.txt
printh 0xFF .....

void loop(){
myNex.NextionListen();
if(myNex.currentPageId != myNex.lastCurrentPageId){
newPageLoaded = true;
currentpage = myNex.readStr("pages.txt");
myNex.writeStr("t1.txt",currentpage);
newPageLoaded = false;
myNex.lastCurrentPageId = myNex.currentPageId;
lastpage = currentpage;
}
}

Bildschirmfoto 2020-08-19 um 14 51 12

NEXTION is not displaying the data sent to it

I am working on a project using an ESP32-S3 and Nextion display. I found your library and felt is was a perfect fit for my minimal coding skills. Everything works when using the NEXTION simulator, but when I interface with the display nothing I send gets displayed.
I submitted a detailed explanation in a request for help on the arduino forum and was wondering if you can talk a look and LMK if you have any advice/suggestion on how to fix my problem. The details start with post #3. The link is:
https://forum.arduino.cc/t/esp32-s3-and-nextion-7-intelligent-display/1091880/

(solved) Collect sleep information

Hi,
I've discovered your awesome library and I have a request.
To stop sending commands for refreshing values to Nextion, I'd like to be informed when Nextion is in sleep mode.
I've seen that the display sends 0x86 but I haven't found how to collect it wih your library

How to read NEXTION special returns with EasyNex ?

Hi Seithan,
I find your library very simple and very practical to use. She is great!
But I have a question: for an application, I need both custom commands and also tactile feedback from the Nextion (65 xx xx xx FF FF FF) and special feedback from the screen (such FE FF FF FF or 04) for using twfile.
How could these Nextion returns be easily integrated into the EasyNex library?

Thank you in advance for your reply.
Have a good day.
Joel

interrupt

Hi
When I wont to save in eeprom, sometimes I got an error. Save at wrong location and not right number
It is possible that library use some interrupts? I try to use nointerrups() command, but in this case also EEPROM function doesn't work

Read Variables

Hello,

I don´t see a function to read/write Nextion´s variables.
Is there a way to make it work?
Thanks

not running with nextion NX3224T024_011 and wemos d1

Hello, i have used example "Trigger" with a wemos d1 and a nodemcu, both with nextion NX3224T024_011, but i have gone crazy no change, buttons do nothing.
Nextion take 5v from an external source.
I have connected to rx and tx pins and serial to 9600
i tryed to use a previous version of library 1.04 and 1.03 but no success.
So i don't know if there is i'm missing.. Any help is appreciated.

#T on triger Serial.println

Hello,

I Use Easy Nextion Library@^1.0.6, baud 115200. Send data to display works ok, but receive (by press button on disple f.e.) not works.

For example in triger0 I have Serial.println("button pressed"), but in terminal from ESP32 print this:

image

Next messages from terminal ESP32 are ok, but all from triggers it print only #T .

I dont know why. Plese help me.

Many thaks,

Jan

input buffer overflow

I found that if the Nextion generates too much input and the serial input buffer backs up. It looks like this is not detected properly and the Arduino crashes and reboots. Library probably writes past the end of an arrray.
Here is how I created the problem.
I put a half second sleep in my main loop - to test for problems.
I then opened a page on nextion with a couple of buttons that call trigger functions trigger0 and trigger1.
Trigger0 and trigger1 just update a text box and change the color of the button.

rapidly hitting the buttons caused trigger calls to be queued up and slowly processed one per half second.
I was impressed that many were queued and that everything kept working.
but with rapid button pressing (10 or twenty quick presses). The arduino crashed. I repeaded this several times and it consistently crashes.

I would have expected that button pushes would eventually just get dropped. Ideally the error would be caught and an error function called to log the error. But it would be ok to just detect the overflow and drop commands.

Thanks for the nice library - really helpful as its much nicer to use that others.

Invalid reading from Nextion

Hi
I try to read data from display. If I'm on main page0 it work OK
xx = myNex.readNumber("popravi_prog.n11m.val"); Serial.println(xx);
but if I'm on some other page I got an "xxx" number.
n11m is mark as global. Also in nextion debuger work OK.

Example with len superior of 02

I cannot find any example with second parameter (len) superior of 02
I tried to do this to catch the next 3 bytes:

Nextion button:

printh 23 03 4c 01 01

C++ code:

    case 'L':
      Serial.println(_serial->read());
      break;

the above code reports 01 only, and not the entire combination like "01 01"

Is there anything to combine both in single variable?
Or how do you do in your cases?

EDIT: when first posted I said it reports twice but I was wrong. It is reporting only once

Cannot use software serial

When compiling on a arduino micro i do get this error

no matching function for call to 'EasyNex::EasyNex(SoftwareSerial&)'

I am wondering do i have to change this line in easyNextionLibrary.h
EasyNex(HardwareSerial& serial); ???
any advice would be appriciated

Using Serial2 on ESP32 with redefined pins

Hi there,

I need to connect to redefined Serial2 pins. Standard-pins would be 16/17 for UART2, but I need to be using 5/14. My attempt is as follows, but doesn't seem to work... Any ideas? :)

#include "EasyNextionLibrary.h"
#define RXD2 5
#define TXD2 14

EasyNex nextion(Serial2);

void setup() {
  Serial.begin(115200); //USB
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); //Nextion
  nextion.begin(9600);
}

Crashes on ESP32

Hello, this library on ESP 32 sometimes crashes:

Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x00000000  PS      : 0x00060230  A0      : 0x800e1ba0  A1      : 0x3ffcfb10
A2      : 0x3ffc4e20  A3      : 0x00000000  A4      : 0x63fd4400  A5      : 0x00000000  
A6      : 0x00000fff  A7      : 0x00060f23  A8      : 0x800e1c32  A9      : 0x00000054
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00005317  A13     : 0x00004c80  
A14     : 0x00050023  A15     : 0x3ffbb554  SAR     : 0x0000000a  EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000  LBEG    : 0x4000c28c  LEND    : 0x4000c296  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

Backtrace: 0x00000000:0x3ffcfb10 0x400e1b9d:0x3ffcfb30 0x400d64a5:0x3ffcfb50 0x400febdd:0x3ffcfc00 0x40090f1a:0x3ffcfc20
  #0  0x00000000:0x3ffcfb10 in ?? ??:0
  #1  0x400e1b9d:0x3ffcfb30 in EasyNex::NextionListen() at .pio\libdeps\Windows\Easy Nextion Library\src/EasyNextionLibrary.cpp:278
  #2  0x400d64a5:0x3ffcfb50 in loop() at src/main.cpp:1172
  #3  0x400febdd:0x3ffcfc00 in loopTask(void*) at C:\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
  #4  0x40090f1a:0x3ffcfc20 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

On main.cpp 23 is #include <Wire.h> and on main.cpp 1172 is myNex.NextionListen(); .

With connected Nextion diplay it crash sometimes, when i disconnected Nextion displat it carsh wery offen (cca every five minutes). Please how fix it? Thanks.

FR Reed Touch Coordinates

Thanks for the great work in this library and i have to ask for help. In my project i need to handle touch coordinates enabled with command: sendxy=1
The returned data is:
67 (02 DA)x (00 D2)y (01 or 00 pressed and released) FF FF FF
Could you please help me to implement that future in the existing library class.

I try to put this code but not working correctly
`
// public variables
uint16_t touchX;
uint16_t touchY;
boolean EasyNex::NextionListen(){
.
.
.
if(_start_char == 'g'){ // And when we find the character #
for(int i = 0; i < 5; i++){ // If the command is 'R' (read Number) go on read the number and store them in the numeric buffer
_numericBuffer[i] = _serial->read();
}
delay(3);

      int _checkNextByte = _serial->peek();  // We take the four bytes. Are they the correct ones we expected?
                                             // Or we have some unwanted data (garbage data) that comes to the Serial.
                                             // To ensure that, we check what is the next byte on Serial.
                                             // If everything is as it should be, the next byte must be a '#',
                                             // which means a command is following, or the Serial must be empty.
                                             // In this way, we lower the chances of having a bad reading.
                                             // But nothing is completely unavoidable.
      
      
      
      if(_checkNextByte == 35 || _checkNextByte == -1){ // Check the next byte. 35 = '#',  -1 = empty Serial
        
        // We can continue with the little endian conversion
        _numberValue = _numericBuffer[4];
        _numberValue <<= 8;
        if (_numberValue == 1){
          isPressed = true;
        }else{
          isPressed = false;
        }
        _numberValue = _numericBuffer[3];
        _numberValue <<= 8;
        _numberValue |= _numericBuffer[2];
        _numberValue <<= 8;
        touchX = _numberValue;
        _numberValue = _numericBuffer[1];
        _numberValue <<= 8;
        _numberValue |= _numericBuffer[0];
        touchY = _numberValue; 
        _waitingForNumber = true;         // Means that we found the correct number and we are going to send it         
        
      }else{  // Else if the Serial is not empty, and the next byte is not 35, then this data doesn't belong to us
        _tmr1 = millis();
        while(_checkNextByte != 35){  // So we send them back where they came from.
          _serial->read();
          _checkNextByte = _serial->peek();
          if((millis() - _tmr1) > 5UL){ 
            break;
          }
        }
        _waitingForNumber = true;     // means that a readNumber command found and we have the number stored
        _numberValue = 777777;        // The false return value of bad reading.
        return _numberValue;
      }
}
  if(_start_char == '#'){            // And when we find the character #
  _len = _serial->read();          // Create local variable (len) / read and store the value of the second byte
                                   // <len> is the lenght (number of bytes following) 
  _tmr1 = millis();
  _cmdFound = true;
  
  while(_serial->available() < _len){     // Waiting for all the bytes that we declare with <len> to arrive              
    if((millis() - _tmr1) > 100UL){         // Waiting... But not forever...... 
      _cmdFound = false;                  // tmr_1 a timer to avoid the stack in the while loop if there is not any bytes on _serial
      break;                            
    }                                     
  }                                   
  if(_cmdFound == true){                  // So..., A command is found (bytes in _serial buffer egual more than len)
    _cmd1 = _serial->read();              // Read and store the next byte. This is the command group
    readCommand();                        // We call the readCommand(), 
                                          // in which we read, seperate and execute the commands
		}
	}
}

return _cmdFound;
}

`

HardwareSerial selection

Hi, as in title, i was wondering if there's any possibility to switch to other HardwareSerial ports and map pins on it, i'm using an ESP32 and would be nice to try Hardware Serial 2 (with pin 32 and 33) because i'm already using the first serial as monitor for testing on usb.

Thanks

Custom objectnames

Hello, I was just wondering if this lib supported Custom objectnames?

for example:
myNex.writeStr("SomthingStupid.txt", "Hello World");

readNumber() not working with SoftwareSerial

As SoftwareSerial is more felxible and doesn't block Serial for debugging i changed the library to use SoftwareSerial.

EasyNex::EasyNex(SoftwareSerial& serial)

I get the trigger1 events as well i can write numbers or strings. But readNumber() is not working at all. Always returns 777777

Already tried playing with the timeouts, but still no luck.

Would you add support for SoftwareSerial or help to find the cause of readNumber() not working?
Appreciate your hard work!

ESP32 serial communication issue with Nextion

I am having trouble writing data from ESP32 serial2 to Nextion. I can receive hits from the Nextion but don't seem to be able to write anything is this anything you have come across?

Change value of multiple numbers

First off, I'm very impressed with your library. It is the by far the best Nextion library I have used so far. Unfortunately, I'm experiencing a very elementary problem. I have 2 numbers on the Nextion display (on the same page).

When I run these two lines, n0 updates as expected:

myNex.writeNum("n0.val", nex_temp);
myNex.writeNum("n0.val", nex_temp);

When I run these two lines, neither n0 or n1 update:

myNex.writeNum("n0.val", nex_temp);
myNex.writeNum("n1.val", nex_temp);

When I run these two lines, n2 updates as expected:

myNex.writeNum("n2.val", nex_temp);
myNex.writeNum("n2.val", nex_temp);

I seemingly can't write to more than one number.

Where is the zip file on Github

I was trying to download your library from Github but can't find the zip file that you say I should see using the second download method that you specify in your Readme.md file.
Am I missing something?

problem with myNex.writeStr("tX.txt+") ?

Hi,
im using an NX4827T043 and with the following code:

     myNex.writeStr("t9.txt", "DoW");
     myNex.writeStr("t9.txt+", " hours"); 
     myNex.writeStr("t9.txt+", " mins");
     myNex.writeStr("t9.txt+", " dd/mm/yyyy");     

the full text should be displayed, but i obtain this output:

photo_2021-03-22_22-17-11

The full code can be found in :
https://github.com/VicenteYago/AdvancedWeatherStation/blob/seithanM/src/OW2nextion/OW2nextion.ino

lines 173-176.

Btw, i want to say that I tested all the available libraries, and this is the best one in quality and documentation. Good work!

GIVE THIS ERROR

libraries\EasyNextionLibrary\EasyNextionLibrary.cpp.o (symbol from plugin): In function `EasyNex::callTriggerFunction()':

(.text+0x0): multiple definition of `EasyNex::callTriggerFunction()'

sketch\ARFTHERM.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

myNex.readNumber()

In my case i have a Variable in nextion(ntu).
ntu.val=489
In Arduino code:
uint32_t number = 0;
number = myNex.readNumber("ntu.val");
Serial.println(number);

But the output(Serial.println(number);) is "4294967066".
Not the real val(489).

ESP32 Crash

When using your code in arduino to run a ESP32, any trigger events over 09 causes the MCU to crash and reset,
i have a print 23 02 54 0A (Trigger 10) from my display button, and void trigger0A() in my code and the MCU resets when the button is pressed on the screen. any susgetions as to where i am going wrong or is this a bug?

Now Fixed. I was not uisng trigger10() in my arduino code, And it was late....

Thanks you by the way for a great bit of code. :)

serial baud rate

with this command the screen works but slowly, myNex.begin(9600)
i tried to write myNex.begin(115200);
but screen can' read anything.
thanks

You are my saver.. thanks

Hey !!! Guy. really you are my saver..
I had some problem esp32 connect nextion.
even follow nextion ITEADLIB... it is pretty has a lot of issues. and unstable.
So, I was thinking about giving up this product.
There were many cases where it went well and suddenly stopped working,
Sometimes, communication was impossible at all.
By the way, I found your documentation and this helped me a lot with the project I was trying to do.
So, it seems that I once again gained hope for development.
First of all, I really really appreciate your efforts. Thanks
ESP32 work well and No problem.
I tested whole day and night.

TriggerX where X > 9 cause kernel panic followed by reboot

// Demonstrate crash when triggerxx where xx < 9
// Possible cause: hexadecimal case statements in callTriggers.cpp dont't compile correctly for ESP32 starting on line 67
// See core dump towards the bottom for cryptic details
// -- mikeseiler2 (at) gmail.com

#include "EasyNextionLibrary.h"

EasyNex myNex(Serial2); // 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 // !! change to 115200 on next upload
// If no parameter was given in the begin(), the default baud rate of 9600 will be used
Serial.begin(115200);
myNex.writeStr("page page0"); // rename this with the next refactoring
}

void loop() {
delay(1); // read every milliseconds
myNex.NextionListen(); // This function must be called repeatedly to response touch events
// from Nextion touch panel. Actually, you should place it in your loop function.
}

void trigger0(){ // OK
Serial.println(0);
}

void trigger1(){
Serial.println(1); // OK
}

void trigger2(){
Serial.println(2); // OK
}

void trigger3(){
Serial.println(3); // OK
}

void trigger4(){
Serial.println(4); // OK
}

void trigger5(){
Serial.println(5); // not tested
}

void trigger6(){
Serial.println(6); // not tested
}

void trigger7(){
Serial.println(7); // OK
}
void trigger8(){
Serial.println(8); // OK
}

void trigger9(){
Serial.println(9); // OK
}
/*
Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000000 PS : 0x00060f30 A0 : 0x800d1236 A1 : 0x3ffb1f30
A2 : 0x3ffc00b4 A3 : 0x00000000 A4 : 0x00003df2 A5 : 0x00005980
A6 : 0x00060f20 A7 : 0x00000000 A8 : 0x800d10e0 A9 : 0x3ffb1f10
A10 : 0x3f400f5c A11 : 0x00000000 A12 : 0x3ffb8274 A13 : 0x00000000
A14 : 0x3ffb82a9 A15 : 0x3ffb0060 SAR : 0x0000000a EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c28c LEND : 0x4000c296 LCOUNT : 0x00000000

Backtrace: 0x00000000:0x3ffb1f30 0x400d1233:0x3ffb1f50 0x400d1019:0x3ffb1f70 0x400d0d0b:0x3ffb1f90 0x400d1ab1:0x3ffb1fb0 0x40088215:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac

*/

void trigger10(){
Serial.println(10); //CRASH !!!
}

void trigger11(){ // CRASH !!!
Serial.println(11);
}

void trigger12(){ // CRASH !!!
Serial.println(12);
}

Sending string to textbox on nextion

Hello,
first of all thank you for the library. Made my first steps much easier :-)
Second, maybe my problem is not with your library, in that case sorry for troubling you!

Setup: NX3224T024, NodeMCU with ESP8266.
Display is on, Triggers created by Buttons on the Nextion are executed. From the ESP8266 i am connected to my MQTT broker -> communication is up and running both ways.

When i try to read a global variable from the nextion, i only get ERROR.
When i try to write text into a textbox, it only works with a string but not with a variable created. If i send the variable back over MQTT i get the proper value...

Function (callback from MQTT PubSubClient)

void callback(String topic, byte* payload, unsigned int length) {
String payloadStr;

//convert payload to String
for (int i = 0; i < length; i++) {
payloadStr += (String)payload[i];
}
payloadStr = payloadStr.substring(1,payloadStr.length() -1); //removing the "" from the string
myNex.writeStr("tempOut.txt", "6.9"); <-- this works
myNex.writeStr("tempIn.txt", payloadStr); <-- this does not work
}
if i change the two write commands, the other textbox is filled with the "6.9"...

Thanks
Erik

Reduce Execution Time for NextionListen()

First, I love your library!!!

One thing I have noticed is that NextionListen() takes almost 1000ms to execute. Here is the code I'm using in the loop() to calculate the execution time.

    int hz1 = millis();
    myNext.NextionListen();
    Serial.println("NextionListen..." + String(millis()-hz));

NextionListen...975

Is there a way to reduce the execution time for NextionListen?

I'm running on a Arduino Compatable ESP32 at 80MHz

Thanks for any help

Errors handling when writing to incorrect nextion objects

First - Great library :)
I think I found an issue though. If you write to an incorrect object it screws things up and you get random behavior like not capturing button presses, etc.
I did a writeNumber("b0",10); instead of the correct writeNumber("b0.val",10);
There is no easy way to catch the error, and I might have expected that write would just not happen.
But Nextion display gives and error back "1A FF FF FF" which I think causes your routine to get lost.
It would be great if your library could catch these error codes and call a user routing "Nextion_error()" or something like that in a similar way that you call trigger0() functions. It would be great if you passed the string that was sent to the nextion that caused the error to this error routine "Nextion_error(String)". That way the error handler could then help with debug.

Intermittent triggerX() detection and currentPage

Hi!

Hope you can help, I've been working on a digital dash project and came across your library which makes things WAAAY cleaner for my use.

Firstly, a quick summary of the hardware/software:

  • Arduino UNO R3
  • Nextion 7" Intelligent series screen NX8048P070_011
  • Nextion editor v 1.65.0

Firstly, I was having trouble getting the currentPage value, and when trying to get it using the global dp variable it was REALLY slow, so abandoned that and went looking for a different solution.

My idea was to trigger a function by getting the Nextion to send a hex string as documented such as :

printh 23 02 54 01

as per:

Screenshot 2022-12-29 at 15 18 27

01 for page 1, 02 for page 2 on the button touch release event. That appears to work fine in the Nextion simulator/debug, and sometimes it works OK when changing page, the Arduino picks it up and will set the global Arduino Int to the current page, which I push out to the Nextion for testing inside the loop().

Sketch as an example:


#include "EasyNextionLibrary.h"

EasyNex myNex(Serial);

int currentPage=1;

void setup() {
  myNex.begin(115200);  
  delay(500);  // This delay is just in case the nextion display didn't start yet, to be sure it will receive the following command
}

void loop() {  
  myNex.NextionListen();
  myNex.writeStr("gearposition.txt", String(currentPage)); // these two fields are extant in the dash, just using for debug here
  myNex.writeNum("pageNum.val", currentPage);
}

void trigger1(){
  currentPage=1;
}
void trigger2(){
  currentPage=2;
}
void trigger3(){
  currentPage=3;
}

I've reduced the code to a minimum above (and have tried this here as well) with the same results, it doesn't always update the page number, I'll sometimes end up with page three showing '1' or '2', page one showing '2' or '3' etc.

Am I doing something wrong? Any ideas?

Thanks very much!

Peter.

Trigger limit 50 ?

Hello Mr. Seithan, first I come to congratulate this magnificent library is the best, I would like to know in the Trigger function, its limit is 50? because mine only works up to 50, if so, how to increase?

Sorry for my english.

How to change globals variables?

Please how can change globals variable in nextion? In HMI I create variable var1 and set vscope as global. But when I send myNex.writeNum("var1.val=",123); it is not function. Why?

Crashes when nextion display disconnected

Hello,

please how check what is Nextion Display wired / connected to Arduino / ESP32? I try declare global variable on display and try somethink this:

in loop:

if (myNex.readNumber("page0.va0.val") == 44) { //test připojení nextion displeje, v global proměnné page0.va0.val je uloženo 44
            myNex.NextionListen();
        }

and when I need write to display:

if (myNex.readNumber("page0.va0.val") == 44) { //test nextion connection- in global variable page0.va0.valis save number 44
            if (Serial2.availableForWrite()) {

but it seems that ESP32 crashes when display is not connected. Please do you have any ideas?

Thanks Jan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.