Skip to main content

Nextion Display with STM32duino



                    Nextion Display is a Human Machine Interface HMI solution combining an onboard processor and memory touch display with Nextion Editor software for HMI GUI project development.
In this tutorial we learn everything about nextion display screen, interact nextion with stm32. We make two part of this project in first part we create screen for nextion display and other one interacting it with STM32 board.
     

  Nextion have library for Arduino. but its very memory consuming and also complicated, so it’s better to do with USART Rx/Tx, we are developing project without any library. We are developing this project in two part. One side nextion display screen creates and its programming. Other side Arduino programing.

 Nextion display and Arduino communicate with Rx/Tx transfer data.

Components Requirements:

·        1 ×  STM32F103 Board
·        1 ×  Nextion Diaply 
·        1 ×  TTL USB to TTL Serial Adapter
·        8 ×  Jumper Wires

 Nextion Display ( Part-I)

     If you don’t know how to use nextion editor, please follow this link , have all about nextion display information.It is beginners's guide. I created nextion screen as given below



         As you can see in figure 

       Main Screen OR Page Id : p0
       Two Button  Id : b0,b1 ,
Slider Id : h0 ,TextBox Id : t0,t1



We are writing code for slider h0 value on textbox t0,
and operating Built in LED of STM32f103 on PC13 GPIO PIN using button b0 and b1. 

First we set baudrate for nextion display to communicate

Page0 : postinitialize Event
                    
                    bauds=9600

User code instruction for nextion Editor  link.


Interface 

  Upload Project HMI file using TTL Serial to USB Adapter 


  Upload .hmi file to nextion display using TTL to USB converter. 

Part-II  STM32UINO PROGRAMMING

    First, we have to install stm32 board in Arduino IDE for that first there  are following steps

   Step 1 download STM32 board manager for Arduino IDE, open your file menu and select preference   option copy following link  
http://dan.drown.org/stm32duino/package_STM32duino_index.json” on Additioal Boards Manager URL , Click on OK Button.







Step 2 – Now click on Tool Menu and go to Board through Board Manager, new dialog box pop up, type there STM32. It will reflect all STM32 Series board you can select which board you have; we are using STM32F1XX Series , Install it.




  Step 3 – Install nextion library , click on  link  and download library 

  Step 4 – It’s time to configure library for using it with board STM32 board.

As this STM32 has 3 serials we will configure for
  – dbSerial enabled
  – nexSerial to use our hardware serial Serial2 

-- Edit NexConfig.h 
    Following line is not commented   

#define DEBUG_SERIAL_ENABLE

then locate the line defining nexSerial ,Please be insure it is  Serial2



#define nexSerial Serial2

-- Now Edit NexHardware.cpp
locate the nexInit() function, here we configure the baudrate for Serial Monitor and Nextion.We will use the Serial Monitor and set its baudrate high (no need to waste more MCU time than is needed), then we will also need to configure for Nextion.
We have chosen 115200 baud in our requirements, so locate the line


dbSerial.begin(9600); 
nexSerial.begin(9600);

and change these to our 250000/115200 baud

dbSerial.begin(250000); 
nexSerial.begin(115200);

--  Edit Nextion.h
    locate the line

#include NexUpload.h

ensure it is commented out or removed from this include list

//#include NexUpload.h

In the library folder rename NexUpload files
– rename NexUpload.h to NexUpload.h.txt
– rename NexUpload.cpp to NexUpload.cpp.txt
--Finally, we need to pull stdlib utoa and ltoa functions in
    Edit NexObject.h
    Locate the line 
 


#include <Arduino.h>

insert the next 3 lines after this line

#include <stdlib.h>
extern "C" char* utoa(int a, char* buffer, unsigned char radix);
extern "C" char* ltoa(int a, char* buffer, unsigned char radix);
                                            OR

If you want to skip configuration of nextion library for STM32 , I have done , it just click on below link and download it , and add to library to Arduino IDE  link
All configuration is  ready !!!! Lets start coding......


Once the GUI is ready, you need to write the STM32 MCU side code so that the Nextion can interact with the STM32 and vice-versa.  Writing code to interact with the Nextion display is not straightforward for beginners, but it also isn’t as complicated as it may seem.

The first thing you should do is to take note of your components in the GUI that will interact with the Arduino and take note of their ID, names and page. Here’s a table of all the components the code will interact to (your components may have a different ID depending on the order you’ve added them to the GUI).

Object

      Page Num

        Object ID

     Object Name

Textbox

0

1

t0

Slider

0

2

h0

Button-ON

0

4

b0

Button-OFF

0

5

b1


   Include Nextion  Library  to project Add 
    #include "NexUpload.h"

     first need to take hardware Serial for communicate with Nextion Displa
  HardwareSerial Serial1(PA10,PA9);

Create Object of Nextion display  as per communication need 

NexButton bOn = NexButton(0, 4, "b0");

NexButton bOff = NexButton(0, 5, "b1");

NexSlider h0 = NexSlider(0, 2, "h0");

NexText t0 = NexText(0,1,"t0")

create nextion lister list as which object have touch action required

NexTouch *nex_listen_list[] =

 {

  &bOn,

  &bOff,

  &h0,

  NULL

};

After touch object call calback function  for all object

Whole Program is here....










Comments

Popular posts from this blog

ARDUINO PORTENTA H7 Tutorial

Portena H7 simultaneously run high level code along with real time tasks. H7 main processor is the STMICROELECTRONICS dual core STM32H747  including an ARM CORTEX -M7 running at 480 MHz and ARM COTEXT M4 running at 240MHz. The two core communicate via a Remote Procedure call mechanism that allows calling functions on the other processor seamlessly. The  Portenta H7  simultaneously runs high level code along with real time tasks, since it includes two processors that can run tasks in parallel. For example, it is possible to execute Arduino compiled code along with MicroPython one and have both cores to communicate with one another. The Portenta functionality is two-fold, it can either be running like any other embedded microcontroller board or as the main processor of an embedded computer. There are many features in one module  STM32H747 dual-core processor 8 MB SDRAM 16 MB  NOR FLASH 10/100 ETHERNET PHY USB HIGH SPEED SECURE ELEMENT WIFI/ BLUETOOTH MODULE UFL CO...

Getting Started with mmWave Sensor MR60BHA1 and Arduino

Introduction : The MR60BHA1 mmWave Sensor is a compact and efficient radar sensor that utilizes millimeter-wave technology to detect objects, measure distance, and track motion. With its high precision and low power consumption , this sensor is ideal for applications in robotics, automation, and security systems. . Millimeter-wave (mmWave) sensors operate at extremely high frequencies, typically in the 30GHz to 300GHz range, allowing them to detect objects with great accuracy regardless of lighting conditions. Unlike optical sensors, mmWave sensors can penetrate fog, dust, and even certain materials, making them reliable in harsh environments. The MR60BHA1 is one such sensor that operates at 60GHz , providing precise motion detection and range measurement capabilities. By integrating the MR60BHA1 with an Arduino , users can develop a variety of projects, such as human presence detection , security systems , and robotic navigation . In this blog, we will explore how to interface...

Exploring Color Sensing with Arduino: A Journey into the World of RGB Detection

                           In today's tech-driven world, the Arduino platform continues to empower enthusiasts and professionals alike to explore the realms of electronics and programming. One fascinating avenue within this domain is color sensing using Arduino boards. With the integration of RGB sensors, Arduino opens up a world of possibilities for projects ranging from color sorting machines to ambient light displays. Let's delve into the exciting world of color sensing with Arduino and discover its applications, principles, and how you can embark on your own creative endeavors. Understanding Color Sensing       At the heart of color sensing lies the ability to distinguish between different wavelengths of light. RGB (Red, Green, Blue) sensors are commonly used for this purpose. These sensors typically consis...