I am so lost... how in the actual do you use this thing?

I am using a generic ESP32-D0WD-V3. I have a generic GC9A01 240x240 display. I am using micropython. I have been working on this for 5 days now just trying for the life of me to figure out how to get LVGL onto my board. I have downloaded multiple files, I have downloaded multiple programs. I have esptools, idf, and a slew of other stuff I have installed using pip. I have tried cmd, I have tried powershell (ran as administrator), i have tried WSL. I have tried creating projects, building firmwares, flashing firmwares, using examples… lets just say I’m about tired of chasing my tail. I have tried to find any forum related to LVGL using micropython and my display. All I want to do is use EEZ Studio to make a guage to measure the RPM of an electric motor. How in the actual do you use LVGL? Is there a straight forward set of directions on how to add this. I’ll be honest, and hopefully at this point it is apparent, I have no idea what I am doing. I am teaching myself all of this as I go. None of the instructions in any of the readme files make any sense. All they say to do is run “idf.py build”… like, what? I have tried that and received nothing but errors in return. Does anyone have anything other than “Good Luck Kid” to help me?

1 Like

Start with reply why for this you require micropython?

1 Like

I am familiar with the python language and micropython is supposedly one of the better languages to use with MCUs. I already have the motor controller working with micropython. I’m just wanting to add gauges.

1 Like

I feel your pain, I was there once it was literally insane trying to figure out where the starting point and end points were.
Some things I’m going to say are going to be obvious to you maybe not but I don’t know where you’re at so I’m just kind of take a leap here and tell you what the big picture is.
So you have micropython and lvgl, they need to be merged into a single binary (firmware.bin) to be uploaded to the ESP32.
LVGL is not a module that can be imported, it’s baked into the micropython code !!!

Now to make the firmware.bin file that will have micropython and LVGL that will be flashed to your mcu.
I use WSL2 on windows.
In the “terminal” make a build folder ie:guage_firmware

mkdir guage_firmware

now go into that folder

cd guage_firmware

Using repo from GitHub - kdschlosser/lvgl_micropython: LVGL module for MicroPython lot of info there …
now enter…

git clone "https://github.com/kdschlosser/lvgl_micropython.git"

you now will have a lvgl_micropython folder

Now let’s install the tool chains

sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install ninja-build
sudo apt-get install python  

Time to build the firmware

cd lvgl_micropython

This command line is specific for my needs… this is where you create a custom build
For example…
mcu… esp32
use only on 1st run… submodules
remove last build… clean
use only on 1st run… mpy_cross
version of esp32… BOARD=ESP32_GENERIC
esp32 memory type… BOARD_VARIANT=SPIRAM
my tft chip… DISPLAY=ili9341
my touch chip… INDEV=xpt2046
esp32 memory size in mb… --flash-size=4
–optimize-size

Lets build…

python3 make.py esp32 submodules clean mpy_cross BOARD=ESP32_GENERIC BOARD_VARIANT=SPIRAM DISPLAY=ili9341 INDEV=xpt2046 --flash-size=4 --optimize-size

When the build is completed you should see something like this…

To flash firmware:
Replace "(PORT)" with the serial port for your esp32
and run the commands.

/home/rich/.espressif/python_env/idf5.2_py3.8_env/bin/python -m esptool -p (PORT) -b 460800 erase_flash

/home/rich/.espressif/python_env/idf5.2_py3.8_env/bin/python -m esptool --chip esp32 -p (PORT) -b 921600 --before default_reset --after no_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x0 "/home/rich/SL-Version-2/lvgl_micropython/build/lvgl_micropy_ESP32_GENERIC-SPIRAM-SPIRAM-4.bin"

NOW This is where I’m different than other people I like to work in windows so I’m going to grab my firmware file and copy it to a folder in my windows environment…
make a project folder ie: guage
in the gauge folder make a folder bin for the firmware.bin file
In Windows Explorer go to Linux > Ubuntu

image

and get firmware.bin at.

\home\ -NAME- \guage_firmware\lvgl_micropython\lib\micropython\ports\esp32\build-ESP32_GENERIC-SPIRAM\firmware.bin

copy firmware.bin and paste in your guage/bin folder

Lets Flash the esp32…
my esp32 is connected to port com4
Using PowerShell…
erase flash

python -m esptool --chip esp32 --port COM4 erase_flash

now flash…

python -m esptool --chip esp32 --port COM4 --baud 921600 write_flash -z --flash_mode dio --flash_freq 40m 0x1000 firmware.bin

now open your REPL and see if you have a prompt…

>>

Here is a main.py test file with a button and label…


from machine import SPI  # NOQA

def btn_cb(event):
	if event.get_code() == lv.EVENT.CLICKED:
		print('clicked !!')
		msg_txt.set_text('clicked !!') # change hello world to clicked !!

# Create the SPI bus
spi_bus = SPI(2, 1000, miso=19, mosi=23, sck=18, cs=5)

# SPI device for display
import lcd_bus
display_bus = lcd_bus.SPIBus(spi_bus=spi_bus, cs=15, freq=40_000_000, dc=13)

import lvgl as lv

# Start display driver
import ili9341
display = ili9341.ILI9341(
	data_bus=display_bus,
	display_width=240,      # I'm using a portrait rotation
	display_height=320,
	# frame_buffer1=fb1,
	# frame_buffer2=fb2,
	reset_pin=None,
	power_pin=None,
	backlight_pin=27,
	color_space=lv.COLOR_FORMAT.RGB565,
	color_byte_order=ili9341.BYTE_ORDER_BGR,
	rgb565_byte_swap=True
)
display.init()

# Start touch driver
import xpt2046
touch = xpt2046.XPT2046(spi_bus)


main = lv.screen_active()

msg_txt = lv.label(main)
msg_txt.align(lv.ALIGN.CENTER, 0, 80)
msg_txt.set_text('Hello World !!')

btn = lv.button(main)
btn.set_size(90,40)
btn.align(lv.ALIGN.CENTER, 0, 0)
btn.add_event_cb(btn_cb, lv.EVENT.CLICKED, None)
btn_lbl = lv.label(btn)
btn_lbl.set_text("Click Me !")
btn_lbl.align(lv.ALIGN.LEFT_MID, 0, 0)


display.set_backlight(100) # turns on tft backlight

import task_handler 
th = task_handler.TaskHandler()

Hope this helps anyone!!!

This is amazing! Thank you so much for this. For me I found it’s easier to flash using esptools in powershell (if there’s a better way, please let me know.) I’ve been using WSL in my all my failed attempts to follow the readme instructions of:
"

Build Instructions

First step is always to clone lv_micropython and update its submodules recursively:

git clone GitHub - lvgl/lv_micropython: Micropython bindings to LVGL for Embedded devices, Unix and JavaScript
cd lv_micropython
git submodule update --init --recursive lib/lv_bindings

Next you should build mpy-cross

make -C mpy-cross

make -C ports/esp32 LV_CFLAGS=“-DLV_COLOR_DEPTH=16” OARD=GENERIC_SPIRAM deploy
"

Before posting this topic, I compiled something that resembled a firmware.bin, but when I flashed it to my board the diag light on the board just flashed and the shell showed some kind of an awful loop.

Where I got lost in your reply was when you said:
“NOW This is where I’m different than other people I like to work in windows so I’m going to grab my firmware file and copy it to a folder in my windows environment…
make a project folder ie: guage
in the gauge folder make a folder bin for the firmware.bin file
In Windows Explorer go to Linux > Ubuntu
and get firmware.bin at.
\home\ -NAME- \guage_firmware\lvgl_micropython\lib\micropython\ports\esp32\build-ESP32_GENERIC-SPIRAM\firmware.bin
copy firmware.bin and paste in your guage/bin folder”

I’ve never used Linux before, so in my WSL I’ve been using:
“amelvin@Melvin:/mnt/c/Users/andre/OneDrive/Desktop/lvgl-master/lv_micropython/ports/esp32$ idf.py set-target esp32”

I’m assuming that when you’re messing with Linux, you’re doing it from in a virtual machine environment that is using a compartmented file system? I am also assuming that when I’m in WSL the /mnt/ is almost like mounting a virtual drive in a virtual machine? Quite frankly, I’m not sure what I’m doing, I just know I am referencing the directory located in the Windows environment.

That being said, if I never hear from you again, I want you to know I am extremely grateful for your response. I am going to try this now, I’ll post my results. Thanks again @GC-RmG.

Another question I have, what do I do about my tft chip? My display is a gc9a01. The drivers are not part of the standard LVGL download. I do have a GC9A01 driver that I used to test my pinout and see if I could get it to work, which it did. I’m just not sure what I should do with the driver folder to have it also “baked into the micropython code.” I can just upload it to the chip and initialize the driver using the specific file location like I did with the test code, but I’m sure there’s a better way of doing this.

This was how I referenced the driver in my code when I tested the display:
"
from lib import gc9a01py as gc9a01
"

The instructions I gave you were for a new and much better repo named…
lvgl_micropython by Kevin Schlosser @ GitHub - kdschlosser/lvgl_micropython: LVGL module for MicroPython
This package will build a micropython v1.24 and LVGL v9

MicroPython v1.24.0-preview.39.g411d66586.dirty on 2024-06-24; Generic ESP32 module with SPIRAM with ESP32

The methods you are describing are from the original…
lv_micropython by Gabor Kiss-Vamosi @ GitHub - lvgl/lv_micropython: Micropython bindings to LVGL for Embedded devices, Unix and JavaScript

Any questions or any help you need regarding drivers building anything Kevin is extremely responsive and very thorough !!!
image

Thanks to you, I’ve seen more progress than ever. Now, however, I am getting to a certain spot and getting a idf click error. I’m not near my computer but I’ll copy the error or take a screenshot later. I think it’s and idf environment error

make: Entering directory ‘/mnt/c/Users/andre/OneDrive/Documents/ESP32_to_ESC_Project/Gauge_Firmware/lvgl_micropython/lib/micropython/ports/esp32’
idf.py -D MICROPY_BOARD=ESP32_GENERIC -D MICROPY_BOARD_DIR=“/mnt/c/Users/andre/OneDrive/Documents/ESP32_to_ESC_Project/Gauge_Firmware/lvgl_micropython/lib/micropython/ports/esp32/boards/ESP32_GENERIC” -DUSER_C_MODULES=…/…/…/…/…/ext_mod/micropython.cmake -D MICROPY_FROZEN_MANIFEST=/mnt/c/Users/andre/OneDrive/Documents/ESP32_to_ESC_Project/Gauge_Firmware/lvgl_micropython/build/manifest.py -D MICROPY_BOARD_VARIANT=SPIRAM -B build-ESP32_GENERIC-SPIRAM build || (echo -e “See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m”; false)
-e See Build Troubleshooting · micropython/micropython Wiki · GitHub
make: Leaving directory ‘/mnt/c/Users/andre/OneDrive/Documents/ESP32_to_ESC_Project/Gauge_Firmware/lvgl_micropython/lib/micropython/ports/esp32’
Cannot import module “click”. This usually means that “idf.py” was not spawned within an ESP-IDF shell environment or the python virtual environment used by “idf.py” is corrupted.
Please use idf.py only in an ESP-IDF shell environment. If problem persists, please try to install ESP-IDF tools again as described in the Get Started guide.
make: *** [Makefile:66: all] Error 1

amelvin@Melvin:/mnt/c/Users/andre/OneDrive/Documents/ESP32_to_ESC_Project/Gauge_Firmware/lvgl_micropython$

First of all Thanks for your post you really helped me a lot!
I did everything you posted and it worked beatifully or so I thought. The REPL appears and I can even import ili9341, xpt2046 and lvgl. The only issue appears when I want to use the SPI() method in your test file:

.
.
.
spi_bus = SPI(2, 1000, miso=19, mosi=23, sck=18, cs=5)
.
.
.
Traceback (most recent call last):
File “”, line 9, in
TypeError: can’t create ‘SPI’ instances

I tried building like in your reply:
" python3 make.py esp32 submodules clean mpy_cross BOARD=ESP32_GENERIC BOARD_VARIANT=SPIRAM DISPLAY=ili9341 INDEV=xpt2046 --flash-size=4 --optimize-size "
but got the afore mentioned TypeError. I am using an ESP32-WROVER -DEV v1.6 so I thought maybe the problem is there. The microntroller I’m using uses 8MB of SPRAM so I tried adjusting the parameters like this:
python3 make.py esp32 submodules clean mpy_cross BOARD=ESP32_GENERIC BOARD_VARIANT=PSRAM DISPLAY=ili9341 INDEV=xpt2046 --flash-size=8 --optimize-size
but got the same result.
i would appreciate if someone could show me a direction.

Maybe try a simpler way - it’s now possible to use LVGL in ESPHome which is configured in YAML, so no C or IDF skills required.
ESPHome supports the display chip you’re using, and has components to measure pulse rates etc. so should be easy enough to measure your RPM.

Start here: LVGL implementation for ESPHome by clydebarrow · Pull Request #6363 · esphome/esphome · GitHub

Questions can go on ESPHome Discord in the #display-changes thread.

If you are open to using the Arduino IDE, consider this repo: GitHub - yashmulgaonkar/SquareLineStudio_boardpackages

If you pick up the LILYGO T-encoder s3 board package, you can change the graphics driver yo match what you have.