Daily life of a digital nomad: LVGL version detection and display of PNG YouTube icon images

Spread the love

Scattered content

Before I have a clear plan, all my blog content will be concentrated on this blog.

Once I have stable traffic or revenue, I will split the core content into specialized blogs, such as YouTube, WordPress, and Python.

lvgl version detection

I made a small desktop figurine using an ESP32S3 and a 3.5″ screen.

This figurine currently displays my YouTube subscriber count, primarily using the YouTube v3 API.
You can see that my current YouTube subscriber count is 1,659.

The official lvgl version detection method is not supported on my firmware

>>> import lvgl
>>> lvgl.version()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'version'

On other AI, the method found

>>> print("LVGL version:", lvgl.version_major(), ".", lvgl.version_minor(), ".", lvgl.version_patch())
LVGL version: 9 . 0 . 0
>>>

This is just a record. For future lvgl development screens, please refer to the lvgl 9.0 version document.

lvgl displays png images

Official documentation for version 8.2

https://docs.lvgl.io/8.2/widgets/extra/imgbtn.html#overview

The imagetools module doesn’t exist on my firmware.

However, you can refer to its Python file reading method.

My PNG code

# Read image file
filename = "/youtube.png"  # BMP/PNG file
try:
    with open(filename, "rb") as f:
        img_data = f.read()
except Exception as e:
    print("Image file not found:", e)
    img_data = None

if img_data:
    # Create lv_img_dsc_t object
    img_dsc = lv.img_dsc_t({
        "data_size": len(img_data),
        "data": img_data,
        "header": {
            "always_zero": 0,
            "w": 100,      # image width
            "h": 100,      # image height
            "cf": lv.img.CF.TRUE_COLOR_ALPHA
        }
    })

    # Display image
    img = lv.img(scr)
    img.set_src(img_dsc)
    # img.center()
    img.set_x(100)
    img.set_y(120)

Using the above code, you can display png images on the screen, such as the youtube logo icon

Tips

I’m a bit tired today. I’ll update the blog later if I have more content.

This is the benefit of blogging on WordPress: you can edit, add, and update content at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *