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

Downloads

Download the GUI Editor software > http://nextion.itead.cc/download.html
Designer Starter Guide > http://wiki.iteadstudio.com/Nextion_Editor_Quick_Start_Guide

Wiring The HMI NEXTION TFT Touch Display on 6 Channel Relay Module with Microcontroller
Facebooktwitterredditpinterestmail
Tagged on:                             

JLCPCBPCBgogoPCBway4pcb

15 thoughts on “Wiring The HMI NEXTION TFT Touch Display on 6 Channel Relay Module with Microcontroller

  • at
    Permalink

    Super guideline. Everything included and very helpful. Thank you.

    Reply
  • at
    Permalink

    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.

    Reply
      • at
        Permalink

        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.

        Reply
  • at
    Permalink

    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

    Reply
    • at
      Permalink

      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)

      Reply
  • at
    Permalink

    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!

    Reply
  • at
    Permalink

    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

    Reply
  • at
    Permalink

    Hi All,
    I tried to simulate this program for controlling my relay in Nextion HMI. Here I am using ESP32 Micro Controller. Earlier I had this problem ‘NexDSButton’ does not name a type and then I copied the files from unstable Nextion version to my stable Nextion version 7.0 and then this problem didn’t occur.
    Now my problem whenever I press the toggle button in my nextion display the relay is not turning on or off. Below I have attached my code,
    #include “NexDualStateButton.h”
    #include “Nextion.h”

    #include “DHT.h”

    #define DHTPIN 27
    #define DHTTYPE DHT22

    DHT dht(DHTPIN, DHTTYPE);
    int R1 = 2;
    uint32_t dual_state ;

    NexText tTempC = NexText(0, 4, “tTempC”);
    NexText tHumidity = NexText(0, 6, “tHumidity”);
    NexDSButton bt0 = NexDSButton(1, 2, “bt0”);

    char buffer[100] = {0};

    NexTouch *nex_listen_list[] =
    {
    &bt0,
    NULL
    };

    void bt0PopCallback(void *ptr)
    {
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;

    dbSerialPrintln(“bt0PopCallback”);
    dbSerialPrint(“ptr=”);

    dbSerialPrintln((uint32_t)ptr);
    memset(buffer, 0, sizeof(buffer));

    bt0.getValue(&dual_state);

    if(dual_state>0)
    {
    digitalWrite(R1, HIGH);
    }
    else
    {
    digitalWrite(R1, LOW);
    }

    }
    void setup(void) {
    dht.begin();
    Serial.begin(9600);
    pinMode(R1, OUTPUT);

    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);

    Serial.println(“DHT Sensor Reading”);
    dbSerialPrintln(“setup done”);

    }

    void loop(void) {

    nexLoop(nex_listen_list);
    float t = dht.readTemperature();

    float h = dht.readHumidity();

    if (isnan(h) || isnan(t)) {
    Serial2.println(F(“Failed to read from DHT sensor!”));
    return;
    }

    static char temperatureCTemp[10];
    dtostrf(t, 6, 2, temperatureCTemp);
    tTempC.setText(temperatureCTemp);

    char hTemp[10] = {0};
    utoa(int(h), hTemp, 10);
    tHumidity.setText(hTemp);

    Serial.print(F(“Humidity: “));
    Serial.print(h);
    Serial.print(F(“% Temperature: “));
    Serial.print(t);
    Serial.print(“°C “);
    //Serial2.print(F(“tTempC.txt=”));

    //Serial.print(“”);
    //Serial.print(F(“tHumidity.txt:\ “));
    //Serial.print(h);
    //Serial.write(0xff);
    //Serial.write(0xff);
    //Serial.write(0xff);

    }

    I am looking for a solution. Kindly help me to sort out this problem. Can you please send me your Arduino coding and your HMI file to the following mail id: [email protected]
    Thanks in Advance.

    Reply
  • at
    Permalink

    Hi all,
    I tried to control the relay switching in nextion using esp32. I used a dual state button to control the relay but whenever I tried to control the relay there is some delay to pass the control signal to the relay. Like for example when I press the dual state button in nextion HMI to turn off the relay there is some delay of 10 to 15 seconds to turn off the relay. I am looking for help to solve this issue. Here I have atta ched my Arduino code below,
    #include “NexDualStateButton.h”
    #include “Nextion.h”

    #include “DHT.h”

    #define DHTPIN 27
    #define DHTTYPE DHT22

    DHT dht(DHTPIN, DHTTYPE);
    int R1 = 2;
    uint32_t dual_state ;

    NexText tTempC = NexText(0, 4, “tTempC”);
    NexText tHumidity = NexText(0, 6, “tHumidity”);
    NexDSButton bt0 = NexDSButton(1, 2, “bt0”);

    char buffer[100] = {0};

    NexTouch *nex_listen_list[] =
    {
    &bt0,
    NULL
    };

    void bt0PopCallback(void *ptr)
    {
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;

    dbSerialPrintln(“bt0PopCallback”);
    dbSerialPrint(“ptr=”);

    dbSerialPrintln((uint32_t)ptr);
    memset(buffer, 0, sizeof(buffer));

    bt0.getValue(&dual_state);

    if(dual_state>0)
    {
    digitalWrite(R1, HIGH);
    }
    else
    {
    digitalWrite(R1, LOW);
    }

    }
    void setup(void) {
    dht.begin();
    Serial.begin(9600);
    pinMode(R1, OUTPUT);

    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);

    Serial.println(“DHT Sensor Reading”);
    dbSerialPrintln(“setup done”);

    }

    void loop(void) {

    nexLoop(nex_listen_list);
    float t = dht.readTemperature();

    float h = dht.readHumidity();

    if (isnan(h) || isnan(t)) {
    Serial2.println(F(“Failed to read from DHT sensor!”));
    return;
    }

    static char temperatureCTemp[10];
    dtostrf(t, 6, 2, temperatureCTemp);
    tTempC.setText(temperatureCTemp);

    char hTemp[10] = {0};
    utoa(int(h), hTemp, 10);
    tHumidity.setText(hTemp);

    Serial.print(F(“Humidity: “));
    Serial.print(h);
    Serial.print(F(“% Temperature: “));
    Serial.print(t);
    Serial.print(“°C “);
    //Serial2.print(F(“tTempC.txt=”));

    //Serial.print(“”);
    //Serial.print(F(“tHumidity.txt:\ “));
    //Serial.print(h);
    //Serial.write(0xff);
    //Serial.write(0xff);
    //Serial.write(0xff);

    }

    Reply
  • at
    Permalink

    Fantastic Tutorial!!! I am pretty new to the Nextion screen and have tried a few other tutorials and was not successful. But this worked like a PERFECTLY!!! Thank You!!

    Does anyone know how to change the words on the buttons? Or can anyone point be to a tutorial to do this?

    Thank You ~Randy~

    Reply
  • at
    Permalink

    Hello,
    please help me. I used your code on Ardunio Mega. Unfortunately my relay switching is not working. I can see communication on the serial port but no response. I found here in the questions , that it is necessary to add pinMode(R1, OUTPUT); to void setup. Unfortunately that didn’t help either. Is it possible to advise ? I am a complete beginner and can’t move on. Thanks a lot with regards

    serial com
    recvRetCommandFinished ok
    recvRetCommandFinished ok
    setup done
    [1760:0,2,bt0]
    [1760:0,2,bt0]
    [1760:0,2,bt0]

    program

    #include “Nextion.h”

    int S1 = 30, S2 = 31;

    NexDSButton bt0 = NexDSButton(0, 2, “bt0”);
    NexDSButton bt1 = NexDSButton(0, 3, “bt1”);

    char buffer[100] = {0};

    NexTouch *nex_listen_list[] =
    {
    &bt0, &bt1,
    NULL
    };
    void setup(void)
    {

    pinMode(S1, OUTPUT);
    pinMode(S2, OUTPUT);

    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);

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

    if(dual_state){digitalWrite(S1, LOW);}else{digitalWrite(S1, HIGH);}
    }

    Reply

Leave a Reply to Randy L Cancel reply

Your email address will not be published. Required fields are marked *