Issue with time/sleep and label.set_text

When I try to set_text in a label inside a timer, the label never update. I have tried this in the browser LVGL/Micropython Simulator, but does not work there too. I have included some print lines in the code for debug, to make sure the timer was working and the prints work ok, but the set_text does not update the label.

The Code Tested in Simulator:

# Initialize
import display_driver
import lvgl as lv
def add_data(timer):
    lbl1.set_text('20Mhz')
    print(lbl1.get_text())
    lv.tick_inc(5)
scr = lv.obj(lv.scr_act()) #Frame Base
scr.set_size(320, 240)
lbl1=lv.label(lv.scr_act())
lbl1.set_width(100)
lbl1.set_pos(10, 10)
lbl1.set_text("10Mhz")
lv.scr_load(scr)
for i in range(1000000):
    no_op = 0
print('Pass')
lbl1.set_text('50Mhz')
timer = lv.timer_create(add_data, 10000, None)

Test it in simulator, because in ESP32 using LVGL/Micropython, the same issue occur after a sleep or big loop like in the example.
On ESP32:

print(“Version: “+str(lv.version_major())+”.”+str(lv.version_minor()))
Version: 8.3

os.uname()
(sysname=‘esp32’, nodename=‘esp32’, release=‘1.19.1’, version=‘v1.18-1246-g6ebf96a90 on 2022-07-18’, machine=‘ESP32 module with ESP32’)

Does anyone experienced something similar?
Thanks in advance

Hi @Pinnchus !

A few comments about your code:

  • You are not supposed to call lv.tick_inc(5).
    This is done automatically by the event loop.
  • You need to initialize your display. That usually also starts the event loop implicitly.
  • You have in your code a very long loop “for i in range(1000000)” before you even create the timer by lv.timer_create. I don’t think you are supposed to “pause” like that ever.

Here is a very simple example of using a timer in Micropython:

btn = lv.btn(lv.scr_act())
btn.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn)
label.set_text(' - ')

value = 0

def set_label(timer):
    global value
    label.set_text(str(value))
    value += 1

timer = lv.timer_create(set_label, 1000, None)

Online example

You can find more examples in the docs.
“Loader with Arc” for example:

https://docs.lvgl.io/8.2/widgets/core/arc.html#loader-with-arc

@amirgon Thank you for your answer, sorry if I made this very confusing, please apologizeme.
The pourpuse of thath long loop was to made a delay without using de time.sleep_us function, thinking (wrongly) that the sleep function could deinitialize the display.

The use of lv.tick_inc(5) was a simple act of desesperation :expressionless:

On the ESP32 the label.set_text does not update, to be more exactly (in my case) after a loop of 34782 microseconds

I just start with LVGL/Micropython yesterday, has some experiencie with LVGL in arduino but not with micropython.

My exact code is very basic for the moment, just for testing the environmet:

In this case, with this code, lbl1 never update.
Code:

import lvgl as lv
from ili9XXX import ili9341, LANDSCAPE
import os

freq=0
def add_data(timer):
    global freq
    if freq < 100: 
        buffertemp=str(freq)+'Mhz'
        lbl1.set_text(buffertemp)
        print('DEBUG: '+buffertemp)
        freq=freq+10
    else:
        freq=freq
        #dont know how to lv.timer_del(timer)



print("OS Version:" + str(os.uname()))
print("LGVL Version: "+str(lv.version_major())+"."+str(lv.version_minor()))

disp = ili9341(
    miso=12,
    mosi=13,
    clk=14,
    dc=4,
    cs=16,
    rst=17,
    power=-1,
    backlight=21,
    backlight_on=1,
    mhz=20,
    width=320,
    height=240,
    rot=LANDSCAPE
)

### INIT LV ###
lv.init()
### END INIT LV ###

### Create Interface ###
scr = lv.obj(lv.scr_act()) #Frame Base
scr.set_size(320, 240)
lbl1=lv.label(lv.scr_act())
lbl1.set_width(100)
lbl1.set_pos(10, 10)
lbl1.set_text("10Mhz")
lv.scr_load(scr)
### End Create Interface ###
timer = lv.timer_create(add_data, 1000, None)

Output:

OS Version:(sysname='esp32', nodename='esp32', release='1.19.1', version='v1.18-1246-g6ebf96a90 on 2022-07-18', machine='ESP32 module with ESP32')
LGVL Version: 8.3
Single buffer
ILI9341 initialization completed
Enable backlight
DEBUG: 0Mhz
DEBUG: 10Mhz
DEBUG: 20Mhz
DEBUG: 30Mhz
DEBUG: 40Mhz
DEBUG: 50Mhz
DEBUG: 60Mhz
DEBUG: 70Mhz
DEBUG: 80Mhz
DEBUG: 90Mhz

Thanks!!!
Pinnchus

Solved.
Removing “lv.scr_load(scr)” work like expected…
Do not know why, but following @amirgon example as base, do the trick.
Thanks again…