About Project :
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.
Components Requirements:
·
1
× Arduino
·
1
× Nextion Display ()
·
1
× TTL Serial to USB Adapter
·
1
× 220 Ω Register
·
1
× LED
· 8 × Jumper Wires
Part – I Nextion screen create & programming
Slider Id : h0
Text Box Id : t0,t1
Two button Id : b0,b1
First we set baudrate for nextion display to communicate
Page0 : postinitialize Event
bauds=9600
h0 : TouchRelease Event
here we care va0 as
string variable to convert number to string
covx h0.val,va0.txt,0,0
prints va0.txt,3
b0 : TouchRelease Event
prints b0.txt,2
b0 : TouchRelease Event
prints b0.txt,2
Nextion display video tutorials link is Nextion Display Tutorial
Part -II Arduino Programming
Its time write code on other part of project, Arduino code
First set
data for serial communication baudrate
ON/ OFF button will do built-In LED On/Off,
for that initialize Pin 13 to output mode
Serial.begin(9600);
pinMode(13, OUTPUT);
For reading string coming
from nextion display we need to check
serial
if(Serial.available())
after read data till
data available on serial
while(Serial.available())
{
Data_From_Display += char(Serial.read());
}
Compare string available with what we sent it from nextion display
ON/OFF or value of slider
If ON string come
write
digitalWrite(13,HIGH);
OFF string coming ,
digitalWrite(13,LOW);
else coming data is
slider value so we need to send it back to page0 textbox t0, for that we have
to
send
string as given below
“page0.t0.txt
=” “Data_From_Display”
Here
page0 : screen Id,
t0 : textbox id
Data_From_Display : string come from slider
Completing
sending data to nextion display, need to write after every string , it specify
string is compete.
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Source
code for Arduino and nextion display project file can download from below,
Interface
Hope you find this project interesting and useful,Be sure to leave your comments, questions and edit suggestions.