Uncategorized – Blog eTechPath https://blog.etechpath.com Tue, 03 Jan 2023 12:37:36 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png Uncategorized – Blog eTechPath https://blog.etechpath.com 32 32 How to interface Nextion HMI with Arduino Mega2560 and learn how to use Nextion editor and program tags in Arduino https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/ https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/#comments Wed, 14 Feb 2018 07:00:18 +0000 https://blog.etechpath.com/?p=513 About:
Nextion is a smart hardware HMI (Human Machine Interface) solution published by ITEAD that provides visualization and control interface between human and machine. Nextion HMI comes with simple serial interface and can be easily communicate with Arduino, raspberry pi and other serial Interface compatible hardware’s.
In this post, I will explain how to draw basic HMI screens, setting tag names and reading tags using Arduino.



Circuit Diagram:

NextionHMI_Arduino Mega2560
Circuit Diagram



Nextion HMI Arduino Mega 2560
Prototype




Nextion HMI Designing:
Watch bellow video for complete tutorial on how to operate Nextion HMI graphic designing software.






Arduino Code:
Note: I am using common anode RGB LED for output testing purpose. So I have written this code to operate common anode LED as output. If you want to drive relays instead of LED, you will need to change the code a bit.

/***************************************************************************************************************
*    Nextion HMI Basic Example : Three Buttons
*    Version 1.0
*    Created By: Pranay Sawarkar
*         Email: admin@blog.etechpath.com
*    All Rights Reserved © 2018 www.etechpath.com
*    
*    Download necessary libraries from the links mentioned in download section in the post,
*    Post Link: https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino
*
*************************************************************************************************************************/

#include "Nextion.h"
 
int S1 = 2, S2 = 3, S3 = 4;

NexDSButton bt0 = NexDSButton(0, 2, "bt0");
NexDSButton bt1 = NexDSButton(0, 3, "bt1");
NexDSButton bt2 = NexDSButton(0, 4, "bt2");
 
char buffer[100] = {0};
 
NexTouch *nex_listen_list[] = 
{
    &bt0, &bt1, &bt2,
    NULL
};
void setup(void)
{    
    pinMode(2,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
    digitalWrite(S1, HIGH);
    digitalWrite(S2, HIGH);
    digitalWrite(S3, HIGH);
    nexInit();
    bt0.attachPop(bt0PopCallback, &bt0);
    bt1.attachPop(bt1PopCallback, &bt1);
    bt2.attachPop(bt2PopCallback, &bt2);
    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);}
}
void bt1PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexDSButton *btn = (NexDSButton *)ptr;    
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));   
    bt1.getValue(&dual_state); 
    if(dual_state){digitalWrite(S2, LOW);}else{digitalWrite(S2, HIGH);}
}
void bt2PopCallback(void *ptr)
{
    uint32_t dual_state;
    NexSButton *btn = (NexDSButton *)ptr;
    dbSerialPrintln("Callback");
    dbSerialPrint("ptr=");
    dbSerialPrintln((uint32_t)ptr); 
    memset(buffer, 0, sizeof(buffer));
    bt2.getValue(&dual_state);
    if(dual_state){digitalWrite(S3, LOW);}else{digitalWrite(S3, HIGH);}
}





HMI with Arduino working video:

https://www.youtube.com/watch?v=2RTYilN8xvs



Downloads :

Nextion Library

Nextion HMI file

Nextion TFT file

HMI Images

Arduino Code

 

 

]]>
https://blog.etechpath.com/how-to-interface-nextion-hmi-with-arduino-mega2560-and-learn-how-to-use-nextion-editor-and-program-tags-in-arduino/feed/ 7