This is the NEXTION HMI a Human Machine Interface device that provides a GUI control of instruments that feeds from your microcontroller. The Nextion is simplified interface to visualize the process between a human and machine, these device is useful on IOT projects or simply an display to your project instead using a traditional LCD or LED display. NEXTION included hardware and series of TFT boards along with a software editor to design your desired interface at the screen. The board uses a one serial communication port to communicate to your Arduino, RPI or AVR, and it works only RX/TX communication and let you avoid hassle of wirings, The NEXTION editor has an ability to provide a drag and drop component such as buttons, Pictures, toggle buttons, slider, progress bar, etc. to ensures that you spend less time in programming your development workloads with the help of WYSIWYG editor. As you can see the diagram we hookup a relay module work as a switch to any home, automotive, & industrial devices.
Required Components
- Arduino Microcontroller / Tenssy / NodeMCU (Arduino IDE Integration)
- USB TTL- UART Serial (CP2XX)/(PL2XX) will work
- Relay Module (4 to 8 channel)
- Jumper Wires / DuPont Wires
Wiring Guide
Uploading the HMI File with NEXTION GUI Editor
- Nextion editor can be download here > http://nextion.itead.cc/download.html
- Download the HMI File below
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
/* www.14core.com | 14CORE > Human Machine Interface Relay Commander */ #include "Nextion.h" int R1 = 2, R2 = 3, R3 = 4, R4 = 4, R5 = 5, R6 = 6; NexDSButton bt0 = NexDSButton(0, 1, "bt0"); NexDSButton bt1 = NexDSButton(0, 1, "bt1"); NexDSButton bt2 = NexDSButton(0, 1, "bt2"); NexDSButton bt3 = NexDSButton(0, 1, "bt3"); NexDSButton bt4 = NexDSButton(0, 1, "bt4"); NexDSButton bt5 = NexDSButton(0, 1, "bt5"); char buffer[100] = {0}; NexTouch *nex_listen_list[] = { &bt0, &bt1, &bt2, &bt3, &bt4, &bt5, NULL }; void setup(void) { nexInit(); bt0.attachPop(bt0PopCallback, &bt0); bt1.attachPop(bt0PopCallback, &bt1); bt2.attachPop(bt0PopCallback, &bt2); bt3.attachPop(bt0PopCallback, &bt3); bt4.attachPop(bt0PopCallback, &bt4); bt5.attachPop(bt0PopCallback, &bt5); dbSerialPrintln("setup done"); } void loop(void) { nexLoop(nex_listen_list); } void bt0PopCallback(void *ptr) { uint32_t dual_state; NexDSButton *btn = (NexDSButton *)ptr; dbSerialPrintln("Callback"); dbSerialPrint("ptr="); dbSerialPrintln((uint32_t)ptr); memset(buffer, 0, sizeof(buffer)); bt0.getValue(&dual_state); bt1.getValue(&dual_state); bt2.getValue(&dual_state); bt3.getValue(&dual_state); bt4.getValue(&dual_state); bt5.getValue(&dual_state); if(dual_state){digitalWrite(R1, HIGH);}else{digitalWrite(R1, LOW);} if(dual_state){digitalWrite(R2, HIGH);}else{digitalWrite(R2, LOW);} if(dual_state){digitalWrite(R3, HIGH);}else{digitalWrite(R3, LOW);} if(dual_state){digitalWrite(R4, HIGH);}else{digitalWrite(R4, LOW);} if(dual_state){digitalWrite(R5, HIGH);}else{digitalWrite(R5, LOW);} if(dual_state){digitalWrite(R6, HIGH);}else{digitalWrite(R6, LOW);} } |
Downloads
- Toggle Button | Download Link
- Push Button | Download Link
Download the GUI Editor software > http://nextion.itead.cc/download.html
Designer Starter Guide > http://wiki.iteadstudio.com/Nextion_Editor_Quick_Start_Guide
Super guideline. Everything included and very helpful. Thank you.
great Tutorial.
Some days ago i try to run/upload to Wemos D1 R2 ESP8266 and found some occured. Please help me to solve til it work. This Hardware and software i used :
– Nextion 3.2″ Standart/Basic
– Wemos D1 R2 ESP8266
– Arduino IDE
This is errors occured :
Arduino: 1.8.1 (Windows XP), Board: “WeMos D1 R2 & mini, 80 MHz, 921600, 4M (1M SPIFFS)”
sketch_apr03a:7: error: ‘NexDSButton’ does not name a type
NexDSButton bt0 = NexDSButton(0, 1, “bt0”);
^
sketch_apr03a:8: error: ‘NexDSButton’ does not name a type
NexDSButton bt1 = NexDSButton(0, 1, “bt1”);
sketch_apr03a:18: error: ‘bt0’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
C:\DOCUME~1\Me\LOCALS~1\Temp\arduino_modified_sketch_560165\sketch_apr03a.ino: In function ‘void setup()’:
sketch_apr03a:24: error: ‘bt0’ was not declared in this scope
bt0.attachPop(bt0PopCallback, &bt0);
^
C:\DOCUME~1\Me\LOCALS~1\Temp\arduino_modified_sketch_560165\sketch_apr03a.ino: In function ‘void bt0PopCallback(void*)’:
sketch_apr03a:41: error: ‘NexDSButton’ was not declared in this scope
NexDSButton *btn = (NexDSButton *)ptr;
^
sketch_apr03a:41: error: ‘btn’ was not declared in this scope
NexDSButton *btn = (NexDSButton *)ptr;
^
sketch_apr03a:49: error: ‘bt0’ was not declared in this scope
bt0.getValue(&dual_state);
^
exit status 1
‘NexDSButton’ does not name a type
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Thanks a lot for shared with me.
Please use this library.
http://www.14core.com/wp-content/uploads/2017/03/ESP8266WiFi.zip
http://www.14core.com/wp-content/uploads/2017/03/ESP8266WebServer.zip
http://www.14core.com/flashing-upgrade-eps8266-v1-firmware-with-espressif-flash-tool/
I was try to uninstall arduino also libraries then install again, put the libraries ESP8266WiFi.zip, ESP8266WebServer.zip and ITEADLIB_Arduino_Nextion-0.7.0 (stable version one). But still not working.
This is errors message :
Arduino: 1.8.1 (Windows XP), Board: “WeMos D1 R2 & mini, 80 MHz, 115200, 4M (1M SPIFFS)”
Touch_Nextion_6_Channel:7: error: ‘NexDSButton’ does not name a type
NexDSButton bt0 = NexDSButton(0, 1, “bt0”);
^
Touch_Nextion_6_Channel:8: error: ‘NexDSButton’ does not name a type
NexDSButton bt1 = NexDSButton(0, 1, “bt1”);
^
Touch_Nextion_6_Channel:9: error: ‘NexDSButton’ does not name a type
NexDSButton bt2 = NexDSButton(0, 1, “bt2”);
^
Touch_Nextion_6_Channel:10: error: ‘NexDSButton’ does not name a type
NexDSButton bt3 = NexDSButton(0, 1, “bt3”);
^
Touch_Nextion_6_Channel:11: error: ‘NexDSButton’ does not name a type
NexDSButton bt4 = NexDSButton(0, 1, “bt4”);
^
Touch_Nextion_6_Channel:12: error: ‘NexDSButton’ does not name a type
NexDSButton bt5 = NexDSButton(0, 1, “bt5”);
^
Touch_Nextion_6_Channel:18: error: ‘bt0’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
Touch_Nextion_6_Channel:18: error: ‘bt1’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
Touch_Nextion_6_Channel:18: error: ‘bt2’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
Touch_Nextion_6_Channel:18: error: ‘bt3’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
Touch_Nextion_6_Channel:18: error: ‘bt4’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
Touch_Nextion_6_Channel:18: error: ‘bt5’ was not declared in this scope
&bt0, &bt1, &bt2, &bt3, &bt4, &bt5,
^
C:\Documents and Settings\Me\My Documents\Arduino\Touch_Nextion_6_Channel\Touch_Nextion_6_Channel.ino: In function ‘void setup()’:
Touch_Nextion_6_Channel:24: error: ‘bt0’ was not declared in this scope
bt0.attachPop(bt0PopCallback, &bt0);
^
Touch_Nextion_6_Channel:25: error: ‘bt1’ was not declared in this scope
bt1.attachPop(bt0PopCallback, &bt1);
^
Touch_Nextion_6_Channel:26: error: ‘bt2’ was not declared in this scope
bt2.attachPop(bt0PopCallback, &bt2);
^
Touch_Nextion_6_Channel:27: error: ‘bt3’ was not declared in this scope
bt3.attachPop(bt0PopCallback, &bt3);
^
Touch_Nextion_6_Channel:28: error: ‘bt4’ was not declared in this scope
bt4.attachPop(bt0PopCallback, &bt4);
^
Touch_Nextion_6_Channel:29: error: ‘bt5’ was not declared in this scope
bt5.attachPop(bt0PopCallback, &bt5);
^
C:\Documents and Settings\Me\My Documents\Arduino\Touch_Nextion_6_Channel\Touch_Nextion_6_Channel.ino: In function ‘void bt0PopCallback(void*)’:
Touch_Nextion_6_Channel:41: error: ‘NexDSButton’ was not declared in this scope
NexDSButton *btn = (NexDSButton *)ptr;
^
Touch_Nextion_6_Channel:41: error: ‘btn’ was not declared in this scope
NexDSButton *btn = (NexDSButton *)ptr;
^
Touch_Nextion_6_Channel:41: error: expected primary-expression before ‘)’ token
NexDSButton *btn = (NexDSButton *)ptr;
^
Touch_Nextion_6_Channel:41: error: expected ‘;’ before ‘ptr’
NexDSButton *btn = (NexDSButton *)ptr;
^
Touch_Nextion_6_Channel:49: error: ‘bt0’ was not declared in this scope
bt0.getValue(&dual_state);
^
Touch_Nextion_6_Channel:50: error: ‘bt1’ was not declared in this scope
bt1.getValue(&dual_state);
^
Touch_Nextion_6_Channel:51: error: ‘bt2’ was not declared in this scope
bt2.getValue(&dual_state);
^
Touch_Nextion_6_Channel:52: error: ‘bt3’ was not declared in this scope
bt3.getValue(&dual_state);
^
Touch_Nextion_6_Channel:53: error: ‘bt4’ was not declared in this scope
bt4.getValue(&dual_state);
^
Touch_Nextion_6_Channel:54: error: ‘bt5’ was not declared in this scope
bt5.getValue(&dual_state);
^
exit status 1
‘NexDSButton’ does not name a type
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
I am using an Arduino MEGA with this code. I changed pins 2-6 on the 14core output to pins 34-38 on the MEGA. I can see functionality on the serial out of the Arduino seen below, but the command is not sending to the relay switch.. any suggestions?
[17recvRetCommandFinished ok
recvRetCommandFinished ok
setup done
[1755:0,1,bt0]
Callback
ptr=1755
recvRetNumber :0
recvRetNumber :1
recvRetNumber :1
recvRetNumber :1
recvRetNumber :1
recvRetNumber :1
yes because there is never declare the output’s , that’s the reason !
just input like that exmp. pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(R4, OUTPUT);
pinMode(R5, OUTPUT);
pinMode(R6, OUTPUT);
in section : void (setup)
Hi there!
Where can I find the Nextion library, because with my library doesn’t work?
Error message:
Nextion_relay:21: error: no ‘void NexTouch::sendCommand(const char*)’ member function declared in class ‘NexTouch’
void NexTouch::sendCommand(const char* cmd)
^
exit status 1
no ‘void NexTouch::sendCommand(const char*)’ member function declared in class ‘NexTouch’
Thanks for your answer!
hye can you give me the source coding?
Get the source code from here >
http://www.14core.com/wiring-the-hmi-nextion-tft-touch-display-on-6-channel-relay-module-with-microcontroller/
Great and interesting tutorial
but i always have this message :
⸮⸮⸮bkcmd=1⸮⸮⸮recvRetCommandFinished err
14:22:08.791 -> page 0⸮⸮⸮recvRetCommandFinished err
14:22:08.791 -> setup done
i don’t know what that mean ?
when i press my Nextion screen, the red TX led on my arduino switch on briefly
i change in the Nextion .h : serial1 to serial for working with UNO
i use other project to get information from Arduino to Nextion with success but on the other side Nextion to Arduino looks not good ?
Thanks if you can help, regards
code does not work