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:
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
User code instruction for nextion Editor link.
Interface
Upload Project HMI file using TTL Serial to USB Adapter
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
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
then locate the line defining nexSerial ,Please be insure it is 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
nexSerial.begin(9600);
and change these to our 250000/115200 baud
nexSerial.begin(115200);
-- Edit Nextion.h
locate the line
ensure it is commented out or removed from this include list
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
insert the next 3 lines after this line
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 |
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
Post a Comment