Nextion

From Let's Control It
(Redirected from Plugin75)
Jump to navigation Jump to search

This page explains the settings found on the ESP Easy Nextion device Plugin (Plugin75). It also provides details to the various command formats that are used to send Nextion button press information or other data. This wiki information has been updated to include the hardware UART serial features that were added late 2018.


Nextion TFT Touch Display Information

The Nextion TFT Touch Display is offered in two different product families, Basic and Enhanced. Display sizes for both families ranges from 2.4-inches (6cm) to 7.0-inches (18cm). The Enhanced version has all the capabilities of the basic model, but has more memory, faster processor, and GPIO. Please note that the examples shown in this wiki have been tested on the basic version.


Here's a short YouTube video that shows examples of what you can do with a Nextion display: https://www.youtube.com/watch?time_continue=6&v=FMWQ1dXZr2I

For a quick introduction to developing a Nextion application please visit: https://www.letscontrolit.com/wiki/index.php/NEXTIONDisplay


Important Information

In addition to the two product families, there are also region specific models. More specifically, there's the Chinese market TJC series (supported by tjc1688.com) and the NX model series (supported by iteadstudio.com) that's for the general global market. The TJC site is Chinese language, the ITEAD Studio site is English.

Nx model 400.jpg

To be blunt, unless you have a project that specifically requires the Chinese market TJC display, our recommendation is to use the global market NX series. Be aware that some sellers do not specifically mention the exact model number. If you are unable to confirm the model information then it is advisable to choose a different supplier.



Device Settings

Device: Display - Nextion [TESTING]

Name: Enter the device's name here (40 characters maximum). Note: Early versions of the plugin must use NEXTION as the device name. This restriction has been removed on [TESTING] builds after August 6, 2018.

Enabled: This checkbox must be selected to enable the Nextion plugin.


Sensor Settings

GPIO ★★ RX ← : Selects the ESP8266's RX signal pin. This connects to the Nextion's TX pin.

GPIO ★★ TX → : Selects the ESP8266's TX signal pin. This connects to the Nextion's RX pin.

Note: ★★ = "SS" is shown when Soft Serial is active; ** = "HW" when Hardware (UART) serial is active.


Enhanced Serial Communications, General Information

ESPEasy's bi-directional communication with the Nextion display can be performed two ways: Soft Serial (bit-bang) or Hardware Serial (UART). Both the Nextion and ESP8266 utilize 3.3V logic, so RX / TX voltage level conversion is not required.


Soft Serial is fixed at 9600 baud and it supports a variety of ESP8266 I/O pins. However, reliability of receiving characters sent from the Nextion may suffer due to ESPEasy's background interrupt conflicts. So using this method requires extra coding to ensure that ESPEasy correctly receives Nextion's serial data.


Hardware Serial is extremely reliable and can support a variety of baud rates. It is limited to the D7 (RX) and D8 (TX) pins. Furthermore, it requires disabling ESPEasy's serial log feature; This is automatically done when hardware serial is chosen. Most importantly, because it uses ESP8266's D8 pin a transistor buffer is required to isolate the ESP8266 from the Nextion's RX input circuity. Omitting the transistor will prevent the ESP8266 from booting correctly!


Advice Tip: Despite the extra work, the hardware serial method is strongly recommended.


Below is an example of the transistor's wiring on a NodeMCU board (consult your specific ESP8266 documentation for its pin-out details). The transistor can be nearly any general purpose PNP switching type, such as 2N3906 or PN2907.

Esp8266 buffer1 450.jpg

IMPORTANT: A buffer transistor is required when pin D8 is used as the serial Tx pin. Nextion +5V and GND power connections (required) are not shown.


Enhanced Serial Communications, Settings

Use Hardware Serial: Select this checkbox when hardware serial is wanted.


Note: When hardware serial is used do NOT enable the Serial Port on Tools->Advanced->Serial Settings. Do not alter the Baud Rate shown below the Tool->Advanced page's Serial Port Setting. D7 must be RX, D8 must be TX. If all these conditions cannot be met then soft serial must be used.

Important: When ESP8266 pin D8 is used the transistor buffer must be installed.


Baud Rate: Select required serial baud rate. This setting applies only to hardware serial.

Note: Nextion factory default is 9600 baud.


Line Command Statements

Line N: Up to ten different Nextion command statements can be created that automatically execute at each timer interval. This provides a convenient way to periodically populate your Nextion display with data from the ESPEasy system variables. System variables are discussed here: https://www.letscontrolit.com/wiki/index.php/ESPEasy_System_Variables


For example, entering statement

page7.t0.txt="IP: %ip%"

would send the ESPEasy IP address to Nextion's text attribute t0 on page 7. Or entering

page7.t1.txt="Signal Level: %rssi%"

would send the RSSI dBm value to text attribute t1 on page 7.


The Nextion plugin provides an optional conversion for the RSSI value that is designed specifically for Nextion's Progress Bar component. Instead of using the %rssi% system variable, the RSSI dBm value can be converted to a stepped 0-100 integer value by substituting rssibar. Here's an example that updates Progress Bar j1 on page 0:

page0.j1.val=rssibar


Be mindful that Nextion's Progress Bar component expects an integer value that ranges from 0 to 100 (it does not support float values). A device's value can be easily converted to integer precision by setting the Decimal entry to zero (0) in the Values section of a device plugin.


Interval Options Settings

Resend Values at Interval: When selected, the idx and value data is resent at each interval time. Typical applications would leave it unchecked (disabled). This setting does NOT affect the Command Statement (Lines) interval.


Data Acquisition Settings

Send to Controller: If selected the idx and value data will be automatically sent by the active controller using its configured protocol. The controller must be setup using ESPEasy's Controllers tab.

Interval: Enter the repeating interval time (in seconds); Set to zero (0) to disable the timer. At each interval time period the Nextion Command Statements are executed. If the Resend Values is enabled then idx and value data are also resent at the interval.


Values Settings

Data sent from the Nextion display is held in two variables, idx and value.

Name 1: idx is the main Index (key) variable. For example, it can be a unique number that is sent by a Nextion touch button that has been is pressed or released. But it is not limited to that purpose; It may be used for any data that needs to be passed from the Nextion display to ESPEasy.

Name 2: value is a sub-variable related to idx. For example, it could contain "1" when a specific Nextion button is pressed, or a "0" when the button is released. The value variable can be ignored if it is not needed.

Please see the Nextion Command Format Summary (below) for more details.


Nextion Command Format Summary

There are three different formats for sending data from the Nextion display to ESPEasy. They are named Touch Event, Pipe-S, and Pipe-U. You are free to choose the format for your application. You can freely mix the different formats in the same application.


What you do with the sent data is up to you. For example, use button press data from the Nextion to trigger actions in your home automation system that control your lights, appliances, and gadgets. Or send periodic data that reports the display's state status. These are just examples, since any Nextion related data can be sent.


Touch Event Format (Send Component ID)

Components in your Nextion application can send Touch Press Events and Touch Release Events. These actions automatically generate idx and value data if their corresponding Send ComponentID checkbox is selected.

During a Touch Press Event (that uses Send Component ID) the Nextion display passes several data bytes to ESPEasy that contains the Page Number, Component ID, and Press State. The plugin packs these three bytes into the two Nextion variables, idx and value that can be sent to your home automation system. Unpacking the two variables to restore the original data can be performed by your home automation system using simple integer math, as follows:

Page Number = (Nextion idx - 500) / 256

Component ID = (Nextion idx - 500) - (Page Number * 256)

Press State = value, where 0 = Press Release, 1 = Pressed


Example: Touch event idx = 1527, value = 0

(1527 - 500) / 256 = Page 4

(1527 - 500) - (4 * 256) = Component ID 3

Result: Component Page 4, Component ID 3, Press Release state


|s (Pipe-S) Format

The |s (Pipe-S) format has the same functionality as the Touch Event format. But it offers more flexibility because your application has the freedom to assign the idx and value data that is sent to ESPEasy. Data unpacking is not required, so it can be simpler to use. It's more powerful too, since Nextion code can be created that performs many of the if-then-else statements that would normally be done in your home automation rules files. For example, create a toggle switch function within Nextion, then use |s to send unique idx codes for its On and Off states.

The |s format is constructed as follows:

|s,i[idx],s[boolen value]

where [idx] = any valid number, including signed decimal.

and [boolen value] = On or Off


For example, to send idx = 12 and value = 1 the Nextion code would be written using two statements as follows:

print "|s,i12,sOn" // Send idx 12 and value 1 to ESPEasy

printh 0a // Required print termination character


|u (Pipe-U) Format

The |u (Pipe-U) format is similar to the |s format. Except idx AND value data can be any number, including signed decimal.

The |u format is constructed as follows:

|u,i[idx],n,s[value]

where [idx] = any valid number, including signed decimal.

and [value] = any valid number, including signed decimal.


For example, to send idx = 50 and value = -3 the Nextion code would be written using two statements as follows:

print "|u,i50,n,s-3" // Send idx 50 and value -3 to ESPEasy

printh 0a // Required print termination character


Nextion IDE Development / User MCU Input

The Nextion Plugin's Hardware Serial feature can be configured to enhance the Nextion Integrated Development Environment (IDE). A special plugin feature makes it possible to develop and test your Nextion application without a physical display panel. Instead you can utilize the Nextion IDE's User MCU Input feature and enable it to directly interface with the ESP8266's USB port. In case it's not perfectly clear, you can create your first working application before you spend a penny on a Nextion display!

Configure your development station as follows:

  1. Disable ESPEasy's Serial Log:
    1. Go to Tools->Advanced tab.
    2. Uncheck (disable) the Enable Serial Port checkbox.
    3. Submit changes.
  2. Configure ESPEasy's Nextion Plugin to use USB serial:
    1. Go to the Nextion plugin.
    2. Select GPIO HW RX to D9.
    3. Select GPIO HW TX to D10.
    4. Select Use Hardware Serial.
    5. Submit changes.
  3. Launch the Windows compatible Nextion IDE app.
    1. Load (or create) your Nextion application.
    2. Choose Debug to compile and run your Nextion application.
    3. At the bottom of the Debug screen enable User MCU input and select your ESP8266's USB port. If the Nextion display board is connected it will be ignored. It does NOT need to be removed.

That's all there is to using the Nextion IDE instead of a actual display board.