Loading...

You have no items in your shopping cart.

 
 
 
×

Registration

Profile Informations

Login Datas

or login

First name is required!
Last name is required!
First name is not valid!
Last name is not valid!
This is not an email address!
Email address is required!
This email is already registered!
Password is required!
Enter a valid password!
Please enter 6 or more characters!
Please enter 16 or less characters!
Passwords are not same!
Terms and Conditions are required!
Email or Password is wrong!
Captcha is required!
Captcha is wrong!

Product Preview: Nextion in an Arduino Project (2)

In previous blog, we've given a simple example of Nextion. In this blog, we will show you how to apply Nextion in an Arduino project. 

Hardware we use

  • Nextion 2.4"
  • Iteaduino UNO
  • Rotary Potentiometer Brick

Click here to download the HMI file.

Demonstration Video

Hardware Connection

Code we upload to Iteaduino UNO

float getValue;
int value;
float oldvalue;

void setup() {
  Serial.begin(9600);
}

void loop() {
  getValue = analogRead(A0);
  if (getValue==oldvalue)
  {;}
  else
 { oldvalue=getValue;
   getValue=(getValue*100/1023);
   value=getValue;
  
  Serial.print("j0.val=");
  Serial.print(value);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t0.txt=");
  Serial.write(0x22);
  Serial.print(value);
  Serial.write(0x22);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
 }
  delay(100);
}

If use the Arduino library we offer, it will be much concise and easy to read.

#include nextion.h //view more about the arduino_nextion_library here:https://github.com/itead/ITEADLIB_Arduino_Nextion
float getValue;
int value;
float oldvalue;
Nextion bar(j0);
Nextion percent(t0);

void setup() {
  Serial.begin(9600);
}

void loop() {
  getValue = analogRead(A0);
  if (getValue==oldvalue)
  {;}
  else
 { oldvalue=getValue;
   getValue=(getValue*100/1023);
   value=getValue;
  
  bar.val(value);
  percent.txt(value);
  
 }
  delay(100);
}

Step by step image turorial of how to build the Nextion project for this demo HERE.

Stay tune! More tutorials will be released!