Skip to content

ESP32 P4 SquareLine LVGL 7inch

SquareLine Studio User Guide

1. Introduction

In Lesson 9 of ESP-IDF, we manually wrote LVGL code to design the LVGL interface and controls to manage the LED on and off. In this lesson, based on the functionality implemented in ESP-IDF Lesson 9,, we will use the SquareLine Studio platform to generate the LVGL interface and controls, enabling a more visually appealing and convenient interface to control the LED. After mastering this method, you can also use it to design more interesting interfaces.

Squareline Tutorial Video:

Squareline Tutorial for CrowPanel Advanced ESP32 P4 HMI AI Display Series

2. Operation Effect Diagram

After completing the design on the SquareLine Studio platform, integrating the exported UI files into the project, and successfully uploading the program, you will see this beautifully designed interface.

img

When you click the ON button on the screen, you will be able to turn on the LED.

img

When you click the OFF button on the screen, you will be able to turn off the LED.

img

3. Introduce LVGL

LVGL (LittlevGL) is an open-source, lightweight, high-performance embedded graphics library designed specifically for devices with limited resources. It supports multi-platform porting, provides rich controls, animations, touch support, and highly customizable styles, and is suitable for fields such as smart homes, industrial equipment, and medical instruments. LVGL is centered around modular design and can run on bare metal or operating systems, accelerating GUI development through strong community support and tools such as SquareLine Studio.

img

SquareLine Studio is a next-generation user interface (UI) solution for individuals and professionals, allowing users to quickly and easily design and develop aesthetically pleasing UI for embedded devices. This software provides integrated design, prototyping, and development capabilities, supporting the export of platform-independent C or MicroPython code for LVGL (Lightweight Graphics Library), which can be compiled and run on devices from any vendor.

img

4. SquareLine Studio User Guide

4.1 Installation Guide

Enter https://squareline.io/ to download the SquareLine installation file.

img

Then go to this download page.

img

Please note that the SquareLine Studio version we are using is 1.5.1.

Scroll down and select version 1.5.1 for download.

(Choose the version according to your operating system. Here I am using the Windows system.)

img

Wait for the download to complete.

img

Place the downloaded compressed file in a folder you are familiar with and extract it to obtain the .exe file.

img

Double-click it.

img

Proceed with the installation.

img

Wait for the installation to complete.

img

Installation completed.

img

Now you can see the software on your desktop.

img

Double-click to open it.

img

Then complete identity authentication and log in.

img

4.2 Designing the Interface in SquareLine Studio

After successfully logging in, you will arrive at this interface. Follow the steps in sequence to make your selections. Finally, choose this project as the template to design the interface used on ESP32-P4 in this lesson.

(Here we are using LVGL version 9.2.2. Please pay attention to your selection in step 2.)

img

After completing the above six steps and clicking Create, you will enter this design interface.

img

Before starting, click the link below to download the image resources we provide.

https://github.com/Elecrow-RD/CrowPanel-Advanced-7inch-ESP32-P4-HMI-AI-Display-1024x600-IPS-Touch-Screen/tree/master/example/V1.0/Squareline_Studio/image

Click “ADD FILE INTO ASSETS” at the bottom of the design interface to import the provided resources.

img

Then drag the imported resources into the design interface.

img

img

Next, we will design the buttons.

In the “BASIC” section on the left, find “Button” and drag it into the design interface.

img

Then, in the design panel on the right, customize the button. I will use an example here; you can design your preferred style.

Step one: Rename it to a name that clearly indicates its function at a glance.

Step two: Set the button’s length, width, and its position within the design interface.

img

Step three: Customize the button style, such as button color, background, border, etc.

(Here I only customized the button color.)

img

Step four: Since we need to turn on the LED after clicking the button, we add an event to the button here. Later, we will edit the code to control the LED connected to the Advance-P4.

(It is recommended that both the event and function names be clearly identifiable.)

img

Now that the button design is complete, let’s add a label to make it clearer.

Drag the “Label” into the design interface.

img

Similarly, customize the label by renaming it and editing the text.

img

Next, bind the label to the button.

Drag the label onto the button to bind them together.

img

Set the label position to 0 so that it is centered within the button.

img

Now the “ON” label looks small. Let’s adjust its size and color.

img

That looks much better now.

With the ON button ready, designing the OFF button becomes easy. Here, we directly duplicate the ON button design.

img

Now you can see the second button.

img

The duplicated button overlaps with the original one. Drag it to reveal the copied button.

img

Now we only need to make the necessary modifications based on the original.

img

img

img

4.3 Export the UI Files

At this point, the complete UI design is finished. Next, we will export the UI files.

Click File and select Project Settings.

img

Specify the export path for the UI files here.

img

After that, click Export UI Files, and your designed UI will be exported.

img

Then navigate to the specified export path to view the exported UI files.

img

img

4.4 Integrate the UI Files into the Project

Prerequisite: this project is modified based on the ESP-IDF Lesson 9 code .

Create a ui folder under the main directory.

img

Place the exported UI files into the ui folder.

img

In the CMakeLists.txt file under the main folder, add ui so that main.c can locate the UI files.

img

Then specify LVGL version 9.2.2 in idf_component.yml under the main folder.

img

Finally, add #include "ui.h" to main.c so that it can locate your designed UI files step by step through ui.h.

img

Also add ui_init() in main.c to display the UI interface.

img

Because in ui.c, ui_init() includes all the UI elements.

img

4.5 Add Callback Functionality

Previously, we added events to both buttons in SquareLine Studio. To enable turning the LED on and off by clicking the buttons, we only defined the callback functions at that time but did not implement them. Now we will implement this functionality.

Go to the ui folder under the main directory and locate the ui_events.c file.

img

Add the following three lines of code here.

img

#include "bsp_extra.h": This library is added because the gpio_extra_set_level function used in this file comes from the bsp_extra component, which is required to control the LED connected to pin 48.

img

That is:

remember to connect an LED to the UART1 interface.

img

At this point, both the UI design and the code implementation are complete.

5. Complete Code

Kindly click the link below to view the full code implementation.

https://github.com/Elecrow-RD/CrowPanel-Advanced-7inch-ESP32-P4-HMI-AI-Display-1024x600-IPS-Touch-Screen/tree/master/example/V1.0/Squareline_Studio/SquareLine_LVGL_LED

6. Programming Steps

Now the code is ready. Next, we need to flash the ESP32-P4 so that we can observe the results.

First, connect the Advance-P4 device to your computer via the USB cable.

img

Configure the project.

Before starting the flashing process, delete all compiled files and restore the project to its initial uncompiled state. (This ensures that the subsequent compilation will not be affected by previous operations.)

img

Following the steps in the first section, select the ESP-IDF version, upload method, serial port, and target chip.

img

Next, configure the SDK.

Click the icon shown in the image below.

img

Wait for the loading process to complete, then proceed with the SDK configuration.

img

After enabling the SDK configuration, search for “CONFIG_IDF_EXPERIMENTAL_FEATURES” in the search box, check it, and save the configuration.

img

Enable the PSRAM option to allocate sufficient RAM for the screen.

Enable the above CONFIG_IDF_EXPERIMENTAL_FEATURES option to select 200M PSRAM and use a higher RAM speed.

img

Then search for “flash” in the search box.

(Ensure that your flash settings match mine.)

img

Then select the partition table option we provide. Since the UI files contain images, a larger partition table is required. We have prepared one for you, so just use our partition table.

img

After completing the configuration, remember to save your settings.

Finally, since the label font we designed uses LVGL font size 48,

img

We need to enable it to use it in the project.

img

After the configuration is completed, remember to save your settings.

Then compile and flash the code (as detailed in the first lesson).

Here we introduce a very convenient feature: with a single button click, you can compile, upload, and open the monitor simultaneously. (This assumes the code is error-free.)

img

After a short wait, the code compilation and upload are completed, and the display lights up.

Suggestion: Please connect your Advance-P4 using another Type-C data cable through the USB2.0 interface. This interface provides a maximum current of approximately 500 milliamps from the computer’s USB-A port. When the Advance-P4 uses more external devices, especially the screen, it requires sufficient current supply.

img

After the upload is successful, you will see this beautifully designed interface.

img

When you click the ON button on the screen, you will be able to turn on the LED.

img

When you click the OFF button on the screen, you will be able to turn off the LED.

img