Set label text before void function call (bug?)

Hi guys,

Here I am back again on my road trying to learn lvgl, with a different weird behaviour I am encountering:

I am trying to change a text (lv_label_set_text) and a hidden flag (lv_obj_clear_flag) before calling a function that’s scanning for wifi networks - the problem is that the modifications are not done before the function call, they are actually done after the function ends.

Sample code:

void startWifiFunction(lv_event_t * e) { // this is a switch (on/off)
  lv_label_set_text(ui_myLabel, "Looking for networks ...");
  lv_obj_clear_flag(ui_wifiPanel, LV_OBJ_FLAG_HIDDEN);

  // added the following 3 lines so I can see what happens
  Serial.println("1. lv elements should have changed");
  Serial.println("2. start scanning will be triggered next");

  scanWifi(); // this does a WiFi.scanNetworks();

Expected behaviour:

1. change text & flag (changes visible on the display for the user)
2. print 1
3. wait 2 seconds
4. print 2
5. start scanning
6. finished scanning

Current behaviour:

1. no change of text & flag
2. print 1
3. delay 2 seconds
4. print 2
5. start scanning
6. finished scanning
7. label & flag changes

What am I missing? I encountered this behaviour a lot of times before while working on this project, my solution was just to adjust the flow/UI and not need it anymore. But in this case I quite need to understand what happens.

Thank you very much and as always I highly appreciate the support :heart:


The UI is not updated directly when you call lv_label_set_text and lv_obj_clear_flag instead, I believe all screen changes are queued and the screen updated with calls to lv_tick_inc. I am not sure it is possible (or good practice!) to call lv_tick_inc in your startWifiFunction function to have it update the UI at that time.


Hi Andy,

Thank you for your reply. Indeed I was thinking maybe something like that is happening. I have no lv_tick_inc in my code, just a lv_timer_handler() - I will try to dig into the docs some more and see if I can figure out something.

Thank you,

Yes, I think lv_timer_handler does the same as lv_tick_inc.
I would be interested to know the opinion of @kisvegabor as to how you go about updating the display outwith lv_timer_handler/lv_tick_inc and whether it is considered good practice to do so.


1 Like


lv_timer_handler periodically reads the input device(s), refreshes the screen (queued, as @AndyFraser pointed out), updates animations, etc. So if you don’t call lv_timer_handler nothing will happen on the screen

lv_tick_inc tells LVGL how much time has been elapsed to schedule the timers.

To fix your issue you can call lv_refr_now(NULL) before the delay to force LVGL refreshing the screen.


Right, I spent some time trying to look into how the display is refreshed, figuring that would help - and I think I found lv_refr_now on stackoverflow, but didn’t really figure it out properly. Close but not quite haha.

Thank you Gabor and @AndyFraser, it works well!


1 Like