Difference between revisions of "NEXTIONDisplay"

From Let's Control It
Jump to: navigation, search
(Hardware)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= Introduction =
 
= Introduction =
The ESP8266 module can be used to control an Serial Nextion Display.
+
 
 +
[[File:WIP.gif]]
 +
 
 +
'''This page is under contruction.''' <br/>
 +
The OLED page is being used as a donor.
 +
 
 +
[[File:Beware.jpg]]
 +
 
 +
This is not an ordinary display. You cannot simply write data to it. You will first have to create an appropriate interface.<br/>
 +
This is a very easy process when using the free Itead IDE (just search for Nextion on the web).<br/>
 +
It has some good tutorials and once you have created your own display, it is very easy to present data and control devices with it.
 +
 
 +
The ESP8266 module can be used to control a serial Nextion display.
 
Due to its on-board intelligence and the presence of a touch panel, the display can be used to control devices.
 
Due to its on-board intelligence and the presence of a touch panel, the display can be used to control devices.
  
Line 6: Line 18:
  
 
= Hardware =
 
= Hardware =
The board is connected to a controller by means of 4 wires
+
The board is connected to a controller by means of 4 wires.
  
 
[[File:Nextion2.jpg]]
 
[[File:Nextion2.jpg]]
  
Connect the Nextion Display to a serial port and to +5 V and ground.
+
Connect the Nextion display to a serial port and to +5 V and ground.
The Nextion software module provides the use of a Software Serial port. So, it is not required to use the 'native'Tx and Rx ports of the controller.
+
The Nextion software module provides the use of a software serial port. So, it is not required to use the 'native'Tx and Rx ports of the controller.
This display works with 5V and can be connected directly to the ESP module.
+
This display works with 5V and can be connected directly to the ESP module. The Tx pin of the Nextion is regulated to 3.3v making it safe to directly connect.  
  
 
== Connections ==
 
== Connections ==
 
<span style="color:red">
 
<span style="color:red">
  
   LCD ESP-01
+
   LCD ESP
 
   GND GND
 
   GND GND
 
   VCC    VCC
 
   VCC    VCC
   SDA GPIO 0
+
   Tx GPIO port acting as Rx
   SCL GPIO 2
+
   Rx GPIO port acting as Tx
 +
 
 +
In order to get these displays to work properly you need to activate the pull-up of the Tx pin. A quick test is to set the pin to high (1) but for long turn you should enable the pull-up instead. If the pin is missing a pull-up you can add one yourself by soldering a 10k resistor from 3.3V to the pin.
 +
 
 +
 
 +
[[File:Nextion-WeMos.jpg]]
 +
 
 +
= Screen preparations =
 +
 
 +
Although this is not the place to go into too much detail of the Nextion Editor, the examples help to explain the possibilities of the plugin. Please bear in mind, that this is the result of my experiments, no more, no less.<br/>
 +
 
 +
<br/>
 +
 
 +
Let's assume you would like to have a control panel with several pages. Below is an example with 5 pages and some test pages. A front page, an info page and some switching pages.
 +
To make browsing between pages run smoothly without having to wait for databoxes to be filled, variables can be used.
 +
Several of them are declared and made global on the front page. The variables get their info from the ESPEasy in integer or text format.
 +
One timer, tm0, makes sure the control panel dims its backlight and go back to its start screen.
 +
Timer tm1 provides an update of the values once every 5000 msec.
 +
 
 +
Hereunder a step by step explanation.
 +
<br/>
 +
<br/>
 +
 
 +
[[File:Front-pre.PNG]]<br/>
 +
 
 +
During pre initialisation, timer tm0 is set to 0 msec and disabled. The backlight is set to faint with dim=10. This is the standby mode<br/>
 +
 
 +
<br/>
 +
<br/>
 +
 
 +
 
 +
[[File:Tim0.PNG]] <br/>
 +
 
 +
When timer tm0 fires, the backlight is set to very faint, the panel goes to page 0 (front page) and the timer is disabled. Again, this is the standby mode with an even lower brightness, to indicate the difference with start up.<br/>
 +
<br/>
 +
<br/>
 +
 
 +
[[File:Front-post.PNG]]<br/>
 +
 
 +
During the post initialisation of the page, after all boxes etc are made available, some data is written to various info boxes.<br/>
 +
-clock time panel t0 gets the "actual" time from variable vTime.<br/>
 +
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0. <br/>
 +
-solar indicator panel j1 gets the relative solar power value from variable va0.<br/>
 +
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.<br/>
 +
<br/>
 +
<br/>
 +
 
 +
[[File:Tim1.PNG]]<br/>
 +
 
 +
Timer tm1 is programmed to provide periodic update (once every 5000 msec. when tm1 fires, data is written to various info boxes.<br/>
 +
-clock time panel t0 gets the "actual" time from variable vTime.<br/>
 +
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0. <br/>
 +
-solar indicator panel j1 gets the relative solar power value from variable va0.<br/>
 +
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.<br/>
 +
<br/>
 +
<br/>
 +
 
 +
[[File:Front-release.PNG]]<br/>
 +
 
 +
Normally, the Nextion is in a standby mode. This means that a the Front page is active and the backlight is dimmed. ESPEasy sends updates to the Nextion, with stores them in the appropriate variables and boxes.<br/>
 +
After the Nextion gets a tough release trigger, some actions are carried out:<br/>
 +
-the backlight is set to 80% of the maximum brightness.<br/>
 +
-if timer tm0 is already enabled, page 1 is selected the tm0 of that pages is charged. <br/>
 +
this allows for a jump from the Front page, when it is touched for the second time within 10 seconds.
 +
-if this is the first time Front page is touched, its own timer tm0 is charged and enabled.
 +
<br/>
 +
<br/>
 +
 
 +
 
 +
 
 +
[[File:P1-pre.PNG]]<br/>
 +
<br/>
 +
<br/>
 +
 
 +
[[File:P1-post.PNG]]<br/>
 +
<br/>
 +
<br/>
  
Some displays feature a Reset or RST pin. At start-up those displays may show noisy pixels.
+
[[File:Switchesl.PNG]]<br/>
Resetting the display and thereafter the ESP will help.
+
<br/>
NodeMCU for instance, provides a RST pin. Connecting this pin to the RST pin of the OLED is a good way to synchronize operation.
+
<br/>
  
Other displays might already be connected to a ESP board. Many of these displays have their reset pin connected to a GPIO. Commonly the pin number 16 is used and in order to get those displays to work properly you need to activate the pull-up for that pin. A quick test is to set the pin to high (1) but for long turn you should enable the pull-up instead. If the pin is missing a pull-up you can add one yourself by soldering a 10k resistor from 3.3V to the pin.
+
[[File:Values.PNG]]<br/>
 +
<br/>
 +
<br/>
  
 
= ESP Easy =
 
= ESP Easy =
Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Display - OLED 1306" from the dropdown box.
+
Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Display - Nextion" from the dropdown box.
 +
 
 +
Now you first need to prepare your display. It needs to contain textboxes, numerical boxes etc.
 +
In the example below, I created variables vHO, vSold and vSolt. Data retrieved from a MQTT tasks can be written to it with:
  
Enter template texts into lines 1 to 8. Plain text will be shown on the display exactly as entered.
+
''page0.vHO.txt=[MQTT1#RFLWsTH_h]''
If you want to show a value, enclose <task name> and <value name> between brackets, separated by a hashtag.
 
  
So if you have a dallas sensor running, with taskname "Dallas", to get the temperature value, use this:
+
where page0.vHO.txt describes the variable in the Nextion display, that I created beforehand.
  
  [Dallas#Temperature]
+
Check this sample on how to get it done:
  
With release 057, some features were added. If you put %sysname% or %ip% or %systime% on a line in the table, the display will show either the name you gave the ESP module, its IP address or its time. The latter only when NTP is being deployed.
+
[[File:NextionSettings.PNG]]
  
 +
In the second example
 +
 +
[[File:NextionSettings2.PNG]]
  
Check this sample on how to get it done:
+
The idx and value fields are used to communicate button presses etc.
  
[[File:EasyConfigOLED.png]]
+
This info can be handled in the Rules:
  
 +
[[File:NextionRules.PNG]]
  
(The IDX field will be stuffed with '1', because it's needs a value. But nothing will be send with this device)
+
(The upper (MQTT) IDX field will be stuffed with '1', because it's needs a value. But nothing will be send with this device the second one is to write to a debug text box in Domoticz, but could also be 1)
  
 
= Commands =
 
= Commands =
Line 58: Line 154:
 
|-
 
|-
  
| OLED,<row>,<col>,<text>
+
| Nextion,
 
| -
 
| -
 
| Write text messages to OLED screen, ROW for row, COL for starting column, and Text for text.
 
| Write text messages to OLED screen, ROW for row, COL for starting column, and Text for text.
 
|-
 
|-
  
| OLEDCMD,<value>
+
| Nextion,<value>
| on, off, clear
+
|  
 
| Switch on or off the OLED or to clear the display. During the off state, the content will be updated according to the latest values or states.
 
| Switch on or off the OLED or to clear the display. During the off state, the content will be updated according to the latest values or states.
 
|-
 
|-
Line 70: Line 166:
  
 
= Special characters =
 
= Special characters =
 
{| class="wikitable sortable"
 
|-
 
! Name
 
! Character
 
! Code (generic)
 
! Code (html)
 
! Code (verbose)
 
! Extra information
 
|-
 
 
| Degree
 
| ˚
 
| {D}
 
| &amp;deg;
 
| degreeC<br>degree_C
 
| "degreeC" and "degree_C" will give you ˚C
 
|-
 
 
| Angle quotes (L/R)
 
| «<br>»
 
| {<<}<br>{>>}
 
| &amp;laquo;<br>&amp;raquo;
 
| -
 
| -
 
|-
 
 
| Greek mu
 
| µ
 
| {u}
 
| &amp;micro;
 
| -
 
| -
 
|-
 
 
| Currency
 
| €<br>¥<br>£<br>¢
 
| {E}<br>{Y}<br>{P}<br>{c}
 
| &amp;euro;<br>&amp;yen;<br>&amp;pound;<br>&amp;cent;
 
| -
 
| -
 
|-
 
 
| Math symbols
 
| <span style="color: #A3BABF">x</span>¹<br><span style="color: #A3BABF">x</span>²<br><span style="color: #A3BABF">x</span>³<br>¼<br>½<br>¾<br>±<br>×<br>÷
 
| {^1}<br>{^2}<br>{^3}<br>{1_4}<br>{1_2}<br>{3_4}<br>{+-}<br>{x}<br>{..}
 
| &amp;sup1;<br>&amp;sup2;<br>&amp;sup3;<br>&amp;frac14;<br>&amp;frac12;<br>&amp;frac34;<br>&amp;plusmn;<br>&amp;times;<br>&amp;divide;
 
| -
 
| -
 
|-
 
|}
 

Latest revision as of 12:21, 3 June 2018

Introduction

WIP.gif

This page is under contruction.
The OLED page is being used as a donor.

Beware.jpg

This is not an ordinary display. You cannot simply write data to it. You will first have to create an appropriate interface.
This is a very easy process when using the free Itead IDE (just search for Nextion on the web).
It has some good tutorials and once you have created your own display, it is very easy to present data and control devices with it.

The ESP8266 module can be used to control a serial Nextion display. Due to its on-board intelligence and the presence of a touch panel, the display can be used to control devices.

Nextion2.jpg

Hardware

The board is connected to a controller by means of 4 wires.

Nextion2.jpg

Connect the Nextion display to a serial port and to +5 V and ground. The Nextion software module provides the use of a software serial port. So, it is not required to use the 'native'Tx and Rx ports of the controller. This display works with 5V and can be connected directly to the ESP module. The Tx pin of the Nextion is regulated to 3.3v making it safe to directly connect.

Connections

 LCD 	 	ESP
 GND 	 	GND
 VCC    	VCC
 Tx		GPIO port acting as Rx
 Rx		GPIO port acting as Tx

In order to get these displays to work properly you need to activate the pull-up of the Tx pin. A quick test is to set the pin to high (1) but for long turn you should enable the pull-up instead. If the pin is missing a pull-up you can add one yourself by soldering a 10k resistor from 3.3V to the pin.


Nextion-WeMos.jpg

Screen preparations

Although this is not the place to go into too much detail of the Nextion Editor, the examples help to explain the possibilities of the plugin. Please bear in mind, that this is the result of my experiments, no more, no less.


Let's assume you would like to have a control panel with several pages. Below is an example with 5 pages and some test pages. A front page, an info page and some switching pages. To make browsing between pages run smoothly without having to wait for databoxes to be filled, variables can be used. Several of them are declared and made global on the front page. The variables get their info from the ESPEasy in integer or text format. One timer, tm0, makes sure the control panel dims its backlight and go back to its start screen. Timer tm1 provides an update of the values once every 5000 msec.

Hereunder a step by step explanation.

Front-pre.PNG

During pre initialisation, timer tm0 is set to 0 msec and disabled. The backlight is set to faint with dim=10. This is the standby mode




Tim0.PNG

When timer tm0 fires, the backlight is set to very faint, the panel goes to page 0 (front page) and the timer is disabled. Again, this is the standby mode with an even lower brightness, to indicate the difference with start up.


Front-post.PNG

During the post initialisation of the page, after all boxes etc are made available, some data is written to various info boxes.
-clock time panel t0 gets the "actual" time from variable vTime.
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0.
-solar indicator panel j1 gets the relative solar power value from variable va0.
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.


Tim1.PNG

Timer tm1 is programmed to provide periodic update (once every 5000 msec. when tm1 fires, data is written to various info boxes.
-clock time panel t0 gets the "actual" time from variable vTime.
-with command cov, the string containing solar energie value in vSold is converted to an int value in va0.
-solar indicator panel j1 gets the relative solar power value from variable va0.
-wifi indicator panel j0 gets the relative rssi power value from variable vRS.


Front-release.PNG

Normally, the Nextion is in a standby mode. This means that a the Front page is active and the backlight is dimmed. ESPEasy sends updates to the Nextion, with stores them in the appropriate variables and boxes.
After the Nextion gets a tough release trigger, some actions are carried out:
-the backlight is set to 80% of the maximum brightness.
-if timer tm0 is already enabled, page 1 is selected the tm0 of that pages is charged.

this allows for a jump from the Front page, when it is touched for the second time within 10 seconds.

-if this is the first time Front page is touched, its own timer tm0 is charged and enabled.


P1-pre.PNG


P1-post.PNG


Switchesl.PNG


Values.PNG


ESP Easy

Use the device tab on the ESP Easy webinterface and create a new task by editing one of the available tasks. Select "Display - Nextion" from the dropdown box.

Now you first need to prepare your display. It needs to contain textboxes, numerical boxes etc. In the example below, I created variables vHO, vSold and vSolt. Data retrieved from a MQTT tasks can be written to it with:

page0.vHO.txt=[MQTT1#RFLWsTH_h]

where page0.vHO.txt describes the variable in the Nextion display, that I created beforehand.

Check this sample on how to get it done:

NextionSettings.PNG

In the second example

NextionSettings2.PNG

The idx and value fields are used to communicate button presses etc.

This info can be handled in the Rules:

NextionRules.PNG

(The upper (MQTT) IDX field will be stuffed with '1', because it's needs a value. But nothing will be send with this device the second one is to write to a debug text box in Domoticz, but could also be 1)

Commands

Command Value Extra information
Nextion, - Write text messages to OLED screen, ROW for row, COL for starting column, and Text for text.
Nextion,<value> Switch on or off the OLED or to clear the display. During the off state, the content will be updated according to the latest values or states.

= Special characters =