4.3_5.0_7.0inch_Lesson03_LVGL_Desk_Lamp_Interface¶
1. Course Introduction¶
This lesson uses LovyanGFX to initialize the LCD and touch device of the 4.⅗.0/7.0 inch CrowPanel, then uses LVGL to create a desk lamp control interface. After flashing, learners can use the ON and OFF controls on the screen to toggle the LED state, verifying the complete chain of display refresh, touch sampling, LVGL events, and external output control.
2. Learning Objectives¶
- Be able to flash the LVGL project using the Arduino IDE configuration method described in Lesson 01.
- Be able to explain the relationship between LovyanGFX, the LVGL display buffer, the touch callback, and UI events.
- Be able to keep
pins_config.h,LovyanGFX_Driver.h, and allui*files to complete compilation. - Be able to determine whether the program is running correctly based on the screen display, touch response, and LED status.
3. What You Need¶
- 1 x CrowPanel Advance 4.⅗.0/7.0 inch ESP32-S3 HMI development board.
- 1 x LED module.
- 1 x USB Type-C data cable that supports data transfer.
- Arduino IDE, ESP32 Arduino Core, LVGL 9.1.0, and LovyanGFX.
- Project:
BigInch_LVGL.ino.
Note: The large-size 4.⅗.0/7.0 inch boards have a function selection switch. 00 corresponds to MIC&SPK, 01 corresponds to WM(wireless module), and 11 corresponds to MIC&TF Card. Because on the large-size product's circuit, pin 19 controls both the wireless module and the UART1 interface, you need to switch the mode to the 0 1 state.
Code and Resource Download¶
Code download: - lesson-03_BigInch_LVGL
Resource download: - table_lamp.png
4. Software Operation Steps¶
-
Open
BigInch_LVGL.inousing the Arduino IDE, and confirm that the same project directory containsLovyanGFX_Driver.h,pins_config.h,ui.c,ui.h,ui_events.c, and the image resource files.
-
Connect the external LED, and use a USB cable that supports data transfer to connect the development board to your computer. Because on the large-size product's circuit, pin 19 controls both the wireless module and the UART1 interface, you need to switch the mode to the 0 1 state.
-
Configure the Arduino IDE. Common settings are as follows:
-
Board:ESP32S3 Dev Module -
Port: select the serial port corresponding to the current board -
Flash Size:16MB (128Mb) -
PSRAM:OPI PSRAM -
Partition Scheme:Huge APP (3MB No OTA/1MB SPIFFS)
- Click Upload to compile and wait for the upload to finish. If it gets stuck at
Connecting..., check for port conflicts and use the BOOT/RESET download mode as required by the board.
- After flashing is complete, open the Serial Monitor and set the baud rate to
115200.
5. Hardware Operation Steps¶
- Connect the external LED, set the large-size board's function selection switch to
01, then connect the USB data cable to power the development board.
- After flashing is complete, wait for the development board to reset; the screen should display the LED UI you just created.
After the screen displays the desk lamp interface, click the ON and OFF controls and observe whether the LED switches in response to the on-screen operations.
6. Key Code Explanation¶
LVGL uses double buffering to prepare the refresh data, then hands it to LovyanGFX via the display callback to push it to the RGB screen. The large-size 800 x 480 screen carries a large amount of data, so if PSRAM is not configured correctly, buffer allocation can easily fail.
The touch callback reads the coordinates from LovyanGFX and passes them to LVGL. When the interface displays but the buttons do not respond, you should first check the touch ribbon cable, the I2C address, and the touch initialization log.
ui_init() loads the auto-generated desk lamp interface and its event bindings within the project. When copying the project, do not omit ui_events.c, ui_Screen1.c, and the image resource .c files, otherwise you will get undefined symbols or an incomplete interface display.
7. UI Creation Steps¶
The UI in this lesson is created with SquareLine Studio. The official process is to first create an Arduino + TFT_eSPI project, then add the lamp image, the On button, and the Off button, and finally bind the Lamp_on and Lamp_off callback functions to the two buttons before exporting the UI files.
For SquareLine Studio download and basic installation, refer to:
7.1 Create the SquareLine Project¶
-
Open SquareLine Studio and click Create at the top. When creating a new project, you must select LVGL
9.1.0. -
In the development board category, select Arduino.
-
Select the Arduino with TFT_eSPI project template.
- Confirm the resolution according to the screen size. The course project for the CrowPanel Advance 4.⅗.0/7.0 inch ESP32-S3 HMI development board uses
800 x 480.
- In Project Settings on the right, set the project name and path, and confirm the key parameters:
- After confirming the parameters, click CREATE to create the project.
### 7.2 Import the Lamp Image Asset
-
After entering the project editing interface, switch to the Assets area at the bottom.
-
Click ADD FILE INTO ASSETS to import the lamp image asset into the project resources.
-
You can also choose another image you want to use.
-
The image asset can be downloaded from the 7.0 inch Arduino code repository: table_lamp.png.

-
After importing it, drag the lamp image resource onto the
Screen1canvas. Adjust its position so that it is on the left side of the screen, leaving space for the button area on the right.
### 7.3 Add the On Button
- In Widgets > BASIC on the left, select Button.
- Drag the Button to the right side of the canvas to use it as the
Onbutton.
-
Select the button, then adjust its position and size in the Inspector on the right.
-
Expand STYLE (MAIN) > Background and set the button background color to orange-red. The official example color is
FF5529.
- Add Label from Widgets > BASIC on the left and drag it into the button.
- Select the Label and change the text in the text box on the right to
On.
- Adjust the Label style, set the text color to white, and select an appropriate font size. Here
montserrat 40is used.
- In the Hierarchy panel on the right, confirm that
Labelis a child widget ofButton.
### 7.4 Copy and Create the Off Button
- In the Hierarchy panel, select the completed
Button1. - Open the More menu and select Copy.
- Paste it on the canvas or in the hierarchy as a new button. Use Paste as child to complete the copy.
- Move the copied button below the
Onbutton.
- Select the Label inside the new button and change the text to
Off.
- Adjust the positions and background colors of the two buttons as needed so that the
On/Offbuttons are arranged vertically on the right.
### 7.5 Set Button Events
- Select the
Onbutton and scroll the Inspector on the right to the EVENTS area. - Click ADD EVENT to add an event.
- Set Trigger to
RELEASED. - Select
CALL FUNCTIONfor Action. - Enter the Function name:
-
Select the
Offbutton and add an event in the same way. -
Set Trigger to
RELEASED, selectCALL FUNCTIONfor Action, and enter the Function name:Note: The Call function name must exactly match the function name in the Arduino project. In this lesson, the
ONbutton usesLamp_on, and theOffbutton usesLamp_off. Incorrect capitalization will prevent the button from controlling the LED correctly.
- Click the play button in the upper-right corner to enter preview mode. After adding the events, run the program and check whether the
On/Offbuttons can be clicked normally.
7.2 Set the Export Path¶
- Click File > Project Settings to open the project settings.
- In FILE EXPORT, set the export path. In the example,
Project Export Rootpoints to the SquareLine project directory, andUI Files Export Pathpoints to theOutputfolder.
- Set
LVGL Include Pathto:
- Check Flat export (exports all files to one folder), then click APPLY CHANGES.
Note: It is recommended to enable Flat export so that the exported UI files are placed together in one folder. This makes it less likely that files will be missed when copying them into the Arduino project later.
7.3 Export the UI Files and Copy Them to the Arduino Project¶
- Click Export > Export UI Files in the top menu.
- Open the exported
Outputfolder and confirm that it contains the UI source files, event files, helper files, and image resource files. Common files include:
ui.c
ui.h
ui_events.c
ui_events.h
ui_helpers.c
ui_helpers.h
ui_Screen1.c
ui_comp_hook.c
ui_img_table_lamp_png.c
- Copy the exported UI files into the Arduino project directory, at the same level as
BigInch_LVGL.ino,LovyanGFX_Driver.h,pins_config.h, andtouch.h.
8. Experimental Results¶
After the program is flashed and the device is reset, the screen should display the desk lamp control interface. Tapping ON turns the LED on, and tapping OFF turns the LED off.
9. Code Download¶
- Code path: lesson-03_BigInch_LVGL
- Lesson03 lamp image: table_lamp.png




































