Nextion Display - Control Font Color Using Commands

by RonFrtek in Circuits > Arduino

118 Views, 2 Favorites, 0 Comments

Nextion Display - Control Font Color Using Commands

Nextion VLX

In this project we are going to make a project with VL53L0X is a Time of Flight distance sensor to measure the distance of the obstacle and display the distance of the obstacle on the Nextion Display. If the distance will be too short the font of the displayed distance will change from Black to Red.

You will learn how to send commands for changing font color from Arduino to Nextion Display using Visuino program.

Check my other Nextion projects to get more ideas!

Watch the Video!

What You Will Need

nextion-display.jpg
vl53l0x.png
nextion-editor.jpg
VisuinoAdvrtisemenArduinoUno_R4_4.png
arduino.jpg
breadboard.png
F5OFEUQJJ4ZYFKY.LARGE.jpg
  • Arduino UNO (or any other board)
  • Nextion Display
  • VL53L0X is a Time of Flight distance sensor
  • Breadboard
  • Jumper wires
  • Nextion Editor program: Download Nextion
  • Visuino program: Download Visuino


The Circuit

2024-07-16_20-43-59.jpg
  • Connect Nextion Display VCC red wire to Arduino 5V pin
  • Connect Nextion Display GND black wire to Arduino GND pin
  • Connect Nextion Display Yellow wire (RX) wire to Arduino TX pin
  • Connect Nextion Display Blue wire (TX) wire to Arduino RX pin
  • Connect TimeOfFlight Sensor pin[VCC] to Arduino pin[3.3V]
  • Connect TimeOfFlight Sensor pin[GND] to Arduino pin[GND]
  • Connect TimeOfFlight Sensor pin[SDA] to Arduino pin[SDA]
  • Connect TimeOfFlight Sensor pin[SCL] to Arduino pin[SCL]


Nextion Editor

FLFPGG9LP5HNEI9.jpg
FUF4ZY8LP5HNEI7.jpg
FHGVH87LP5HNEIY.jpg
FISNUO6LP5HNEI8.jpg
FQPFBQDLP5HNERD.png
FUGTDHNLP5HNFBY.png
2024-07-12_14-07-06.jpg
F1ARMKMLP5HNFV4.jpg
FKA4PHYLP5HNFV5.jpg
  • Download Nextion Editor and Install it
  • Start Nextion Editor
  • In the Nextion Editor click on the "New" button
  • In the Window set the name for the Project like "VL53L0X-Distance"
  • In the "Setting" window select the Model of your Nextion Display & click "Ok"
  • Select Display Direction 90 & click "Ok"
  • In the Menu select "Tools">"Font Generator"
  • In the Font creator window set the "Height" to 40 & set the name for your font and click "Generate Font", Save the Font, you will be asked "Add the generated font?" Click Yes
  • In the Editor on the left in the "Toolbox" find:
  •  "Text" & drag it to the right


  • In the Toolbar click on the "Compile" button
  • In the Menu Select "File" > "TFT File Output"
  • Set the Output folder & click on the "Output" button
  • Save the File to the SD card
  • Insert the SD card to your Nextion Display
  • Power the Arduino and you will notice that the Nextion Display will start to Update it self
  • On the Finish disconnect the power and remove the SD card from the Nextion display


Start Visuino, and Select the Arduino UNO Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add & Set Components

2024-07-17_15-37-14.jpg
F9A0TAXLG54R2OQ.jpg
2024-07-17_15-45-02.jpg
2024-07-17_15-45-50.jpg
2024-07-17_15-46-49.jpg
2024-07-17_15-48-14.jpg
2024-07-17_15-47-38.jpg
2024-07-17_15-48-28.jpg
2024-07-17_15-48-45.jpg
2024-07-17_15-53-09.jpg
  • Add "Nextion Display" component
  • Double click on the "DisplayNextion1" And in the Elements window drag "Text" to the left side
  • Drag "Command" to the left side and in the properties window set "Command" to t0.pco=1024, this means black color
  • Drag "Command" to the left side and in the properties window set "Command" to t0.pco=1024, this means black color
  • Drag another "Command" to the left side and in the properties window set "Command" to t0.pco=63488 -red color


Note: to get the value for the color select the Text Element in Nextion editor and in the properties window search for "pco" and you will see the value number for the selected color


  • Add "Time Of Flight Laser Ranger VL53L0X" component
  • Add "Analog Multi Source" component
  • Add "Analog To Text" component, and in the properties window set "Precision" to 0
  • Add "Compare Analog Value" and in the properties window set "Compare Type" to ctBigger and "Value" to 50
  • Add another "Compare Analog Value" and in the properties window set "Compare Type" to ctSmaller and "Value" to 50

In Visuino Connect Components

2024-07-17_15-54-11.jpg
nextion-vlx.png
  • Connect "LaserRanger1" pin Sensor [I2C] to Arduino pin I2C [In]
  • Connect "LaserRanger1" pin Sensor [I2C] to Arduino pin I2C [In]
  • Connect "LaserRanger1" pin [Distance mm] to "MultiSource1" pin [In]
  • Connect "MultiSource1" pin [0] to "AnalogToText1" pin [In]
  • Connect "MultiSource1" pin [1] to "Compare1" pin [In]
  • Connect "MultiSource1" pin [2] to "Compare2" pin [In]
  • Connect "AnalogToText1" pin [Out] to "DisplayNextion1" > "Text1" pin [In]
  • Connect "Compare1" pin [Out] to "DisplayNextion1" > "Command1" pin [Clock]
  • Connect "Compare2" pin [Out] to "DisplayNextion1" > "Command2" pin [Clock]
  • Connect "DisplayNextion1" Pin[Out] to "Arduino" > "Serial [0]" pin [In]


Generate, Compile, and Upload the Arduino Code

2024-07-17_16-01-47.jpg
Visuino-Compile-UNO.jpg

Before Uploading Disconnect RX pin on Arduino and connect it back after the Upload.

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module and put the obstacle in front of the VL53L0X sensor Nextion display will show the distance of the obstacle in mm, if the distance is lower then 50mm the font color will change to red.

This approach of using commands can also be used for changing other properties in the Nextion display.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here and open it in Visuino: https://www.visuino.eu