-
Notifications
You must be signed in to change notification settings - Fork 0
Nextion Introduction
LCD screen that'll serve as the car's dashboard screen. It'll display relevant information like battery life of the car to the driver.
Download the Nextion IDE here. IDE available only for Windows 😭.
Upon boot up, select file -> new -> create file

Select the appropriate Nextion screen.

Select the orientation (Horizontal is preferred).

Select the font. EXTREMELY IMPORTANT STEP. WITHOUT SETTING A FONT, THE FILE WILL NOT UPLOAD

Generate





Select debug on the menu bar to enter debugger mode.
This is an interactive simulation. Notice when you click on one of the buttons, a string of characters are returned in the terminal. Clicking on “ON” will output “65 00 01 00 FF FF FF”. The string of characters are the same between the two buttons except the third index. The third index signifies the ID. When you press the button, the Nextion screen will send a string of characters to the Teensy board through the Rx/Tx communication bus. The STM32 code will save the characters into an array. We take advantage of the similarity in the sent characters by only reading the 3rd element of the array (in this case 01 or 02). Based on the read characters, we can program the STM32 to toggle its lights.
To send information from the VCU to the display, it must be connected through a microcontroller. To emulate this connection while configuring the display through your PC, you need to connect the microcontroller appropriately. Once this connection is made, you can follow the same further steps to setup the display and send information to it.
If you are connecting the display directly to the PC without a microcontroller, you will need a TTL adapter.
To flash the Nextion screen, you need the TTL adapter. Follow the connections from the Nextion to the TTL adapter as follows:

An alternate way to flash the Nextion is through a micro sd card. The Nextion also comes with its own adapter, but it's unreliable and hence not recommended.
Walks through snippets of code to explain
#define HWSERIAL Serial1
void setup() {
Serial.begin(9600);
HWSERIAL.begin(9600);
}
Serial refers to the Rx and Tx connections of the Teensy. Teensy has 8 serial ports that reference different Rx and Tx pins. Serial1 references RX: pin 0 and TX: pin 1. Refer to the data sheet for more information.
HWSERIAL.print("b0.txt=\"HELL0\"");
HWSERIAL.print("\xFF\xFF\xFF");
To send to the Nextion, use the print Serial.print() function. Adhering to Nextion protocol is important to sending data to the screen. Every protocol message you send ends with "\xFF\xFF\xFF". "b0.txt="HELL0"" changes the button text to "HELLO". b0 refers to the id of the button. txt refers to which part of the button class you want to change. To send "HELLO", you need to do it as such: "HELLO". Refer here for more details on Nextion Protocol.
if (HWSERIAL.available() > 0) {
incomingByte = HWSERIAL.read();
Serial.print("UART received: ");
Serial.println(incomingByte, HEX);
}