Panel Cookies
yt_link
insta_link
fb_link
twitter_link

NEXTION TFT
page 2/5


NEXTION TFT examples with Arduino

Help me by sharing this post



PART 2 - Potentiometer read example

In this part we will see how to read the analog value of the potnetiometer and send that to the TFT display from the Arduino. In this way we will know how to receive but also how to send data to the Arduino. YOu ahve the schematic, code and tft file below.





Schematic


Ok, first of all, for this first example we need the schematic below. But only make the connections after we uplaod the code since the display uses the RX and TX pins and if something is connected to those pins, we can't uplaod the code. But we need the Arduino code part but also the Nextion TFT interface. For that we will use Nextion editor and create our interface.


scheamtic Arduino NEXTION display potentiometer


Nextion TFT file

Downlaod from below the Nextion editor software and install it. Then run the aplication and create a new file. Once again, select the type of display and the horizonal mode. Then add a lael to the screen from the toolbox. Then in the variable settings I name the label as voltage1. Later in the code we will use this voltage1 name to send data to the label on the screen.



Download NEXTION editor:


nextion read analog value Arduino



Uplaod the TFT file

Ok, so I've placed the labeled and named it voltage1, to uplaod the TFT file we have to compile the project. If we have no errors in the console, we go to File and select open build folder anc copy the tft file. Insert a micro SD card into your PC and copy the tft file there. The SD card must be empty and formated to a fat32 format.


Download potentiometer_read TFT file:

nextion editor tutorial

Now that the tft file is on the SD card make sure the Nextion display is not powered on. Insert the SC dard into the card slot. Now power up the display with 5V. You will see on the screen that the new tft interface is being uploaded. Once you see 100%, power off the display and remove the SD card. Now power back the display and connect the TX and RX pins as in the schematic and add a potentiometer to pin A0.





Arduino code

Copy the code from below or just download it. Upload the code to the arduino before you connect the TX and RX pins. After you uplaod the code, connect the UART TX and RX pins and power up the Arduino and display. Connect the potentiometer as you can see in the video below.



Download potentiometer read code:



int potentiometer_pin = A0;                   //Define the pin for potentiometer

void setup() {
  Serial.begin(9600);                         //The default baud rate of the Nextion TFT is 9600.    
  pinMode(potentiometer_pin,INPUT);           //Define that pin as input
}

void loop() {
  int Value = analogRead(potentiometer_pin);  //Read the analog value. Values from 0 to 1024
  Serial.print("voltage1.val=");              //We print the variable we want to cahnge on the screen
  Serial.print(Value);                        //Print the value we want to be displayed
  Serial.write(0xff);                         //Always add 3 full bytes after...       
  Serial.write(0xff);
  Serial.write(0xff);
}




As you can see, after each data send, we also send 3 full bytes (0xFF) in hexadecimal. So we send the "voltage1.val=" text then the voltage analog value. That will update the val value of the label on the screen and by that print the value as we cans ee below in the test video.











Go back ←
Next example →

Help me by sharing this post








ADVERTISERS



PCBWAY PCB service





Curso Arduino Online nivel bajo