Micropython Build for Pico 2 W

I am new to LVGL. Using WSL2, I have downloaded source from…

https://github.com/lvgl/lv_micropython.git

…by following the instructions at…

lv_micropython/README-LVGL.md at master · lvgl/lv_micropython

After installing a few extra packages, I was able to build for RPI_PICO and RPI_PICO2.

However, I need to build for RPI_PICO2_W - the board that has BLE and WiFi.

Unfortunately, the board is not in ports/rp2/boards, though it (any many others) are in the current Micropython source.

micropython/ports/rp2/boards at master · micropython/micropython

I can build for RPI_PICO2_W using the standard Micropython source above.

What is my best chance of getting Micropython LVGL running on this board?

I tried copying across the board definition files, but just ended up chasing undefined constants around the source, as the underlying versions seem to be too far apart.
I had hoped to get up and running quickly, but am now knee deep in build problems.

Do I try to patch LVGL into a current Micropython. If so, can anyone tell me the steps, or do I have to reverse engineer it by looking at what files are different between an LVGL Micropython source and a standard source and then try to reapply those changes to a new source?
Or do I wait for a new Micropython LVGL update that supports more boards?

I must be going about this the wrong way. It can’t be this hard. I would think this is now the most popular Pico board, since it has enough RAM for a decent UI, as well as connectivity to do something with it. Hundreds of people must already be using LVGL with this board - I just can’t work out how.

Thanks in advance for any help.

By the way, for anyone else struggling, who hasn’t got this far:

  • You need to install doxygen, though compilation doesn’t spit out this error, seemingly unless you try to build without user c modules specified.
  • You also need to install python3-pycparser.
    (Neither of the above are included in Ubuntu WSL2 and are in addition to what is required for a standard Micropython build)
  • The board name in the instructions is now out of date. Instructions state PICO as the board name, though it is now RPI_PICO - I’m guessing the Micropython source has been updated since the instructions were written.
1 Like

Further to my post above. I did look at when various updates were done in github…

The RPI_PICO2_W was added to the Micropython build in December 2024 - more than 2 years ago.
The LVGL boards folder was last merged from Micropython only 11 months ago, but it was from the 1.24.1 from Nov 29th 2024. So it just missed the key updates by a few days.

I’m trying to provide as much information as I can, but I think getting this to work by myself is probably way above my pay grade.

By some miracle, I have managed to modify the source (bringing in missing files, adding includes, missing functions from newer libraries and renaming variables that have changed in the more recent code), and have managed to build an lv_micropython for RPI_PICO2_W.

It ain’t pretty, but I can now ‘import lvgl as lv’ from a REPL prompt.
It’s a temporary hack, rather than a general solution for everyone I think.

The next issue is that I have no st7789 driver.
I’m surprised, as isn’t this the most common, cheap lcd display chip?

I guess I’ll continue to hack my way through these problems… with just enough know-how to be dangerous!

I found a pure micropython LVGL driver for st77xx here:

lv_binding_micropython/driver/generic at master · lvgl/lv_binding_micropython

Unfortunately, it is pretty broken. I wasted another day of my life discovering that the PWM backlight pin is not initialised correctly. The PWM frequency is missing in the initialiser, which means the frequency gets initialised to 0Hz and the pin never switches from off to on - so all you get is a black screen. Hacking ‘1000Hz’ into the driver got things working, after comparing the driver with a working Russ Hughes version and trying to ascertain why one worked and the other didn’t.

Furthermore, the LCD initialisation parameters on this LVGL driver are hard-coded, so I’ve had to hack in my required init params, so my lcd doesn’t end up colour inverted etc. The DMA doesn’t work for me, possibly because the SPI registers have been hard-coded to SPI1 and I’m using SPI0, because that’s how my display’s PCB is wired. I might investigate this further, though I don’t know if this will give a performance improvement. However, this is the least of my worries, since after several days, I am still not quite at the ‘Hello World’ stage.

I have created a test.py to attempt an LVGL Hello World app. I can finally get a button to display on the screen, but I have to run the script twice to achieve this. Any ideas why? I guess it could be something to do with the display driver that I am using, though it is hard for me to know with my current level of experience,

Script is below…

import time
import lvgl as lv
from st77xx import St7789
from machine import Pin, SPI

lv.init()

spi = SPI(0, baudrate=62_500_000, sck=Pin(18), mosi=Pin(19))

# dma=rp2_dma.DMA(0)
rp2_dma=None

# Create display in Landscape orientation
display = St7789(rot=1,res=(240,320),spi=spi,rp2_dma=rp2_dma,cs=17,dc=16,bl=20,rst=None)
display.set_backlight(30)

# Create a button on the screen
scr = lv.obj()
btn = lv.button(scr)
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text("Hello World")

# Load the screen
lv.screen_load(scr)

while True:
    lv.task_handler()
    time.sleep_ms(5)

Once I had the firmware on my Pico and the display driver behaving, I managed to get everything working in an evening: Display, buttons, rotary encoder. The results are amazing and I’m now working my way through the docs to see what is possible and then try it out. I’m glad I pushed through the pain to get there. But it doesn’t need to be this hard for a newbie…

Here are the problems I found:

  • The lv_micropython repo is very out of date and does not support what is probably the most popular hobbyist microcontroller - the Pi Pico 2 W. It needs to be updated so as not to be a showstopper before an enthusiast even gets started with LVGL. People who are wanting to use LVGL with Micropython are likely to be less hardcore than those choosing to use c/c++. So barriers to entry need to be minimal.
  • The st7789 driver has some issues:
    – The backlight code didn’t work for me. Maybe it works under certain conditions, but not for me. I have a fix for this now.
    – The DMA is hardcoded for SPI1. I haven’t fixed this. I’ve never written DMA code, though maybe I am about to.
    – The constructor probably needs a custom_init parameter, though I was wrong, and was able to make my specific display work just fine without this feature.
    – I can add to the st7789 test scripts for Pimoroni displays (3) and Waveshare (1)

I am happy to contribute my fixes to make things a little better for the next person who tries to do what I did. I am no git expert, having never created a pull request, so if I can contribute, please let me know the best way to go about this. I notice that issues appear to be disabled for lv_micropython, but enabled for lv_binding_micropython.

Steve

1 Like

Can you please share the results of yours successful work on adapting of LVGL to RPI_PICO2_W with community.
It will be nice to share the fixed source and the compiled firmware (for a quick test ).
Thank you in advance.
BYW you can attach a zipped archive with source only and second file - your compiled firmware for Pico2W.

Attached is the firmware for RPI_PICO2_W.

firmware.zip (977.1 KB)

I need to work out the best way to package up or list my changes. Because the lv_micropython repo is comprised of multiple other repos, I have found it quite difficult to list the complete set of changes. i.e. git diff and git status don’t help much as they list the changes in the ‘base’ repo, not the linked ones. If you know of a way to do this, let me know. Otherwise, I’ll spend some time finding a solution. In the mean time, give the firmware a try and see what you think.

The reason I said in a previous post that I didn’t think it was a viable general solution is because there are changes in multiple linked repositories. But I would think that with a bit more work, I could get all changes in the main repo. Obviously, it would be a big task for the lv_micropython guys to update the base micropython version and then retest all targets - I know I said the repo is out of date, but on reflection I should have said WRT Pi Pico. So if I can get the changes to only be in the base repo ports/rp2 folder and the pico-sdk, then I think that it would be reasonable to expect a pull request would be accepted, since there’s no chance of that affecting ESP32 builds etc.

Let me know what you think. And thanks for replying to my post/rant! :grin:

1 Like

Thanks a lot!

Unfortunately I don’t have the github account and I can’t help with that! But I’m much appreciate it for a shared firmware!