Screen does not update continuously

Description

What MCU/Processor/Board and compiler are you using?

I am using the ESP32-C6 micro controller with a small SSD1306 LCD screen.

What LVGL version are you using?

I am using version 8.3.11

What do you want to achieve?

I want to update the screen continuously (every lvgl iteration) so that I can show constantly changing variables like time.

What have you tried so far?

I tried lv_refr_now, but (I think) it recurses inside the LV_EVENT_DRAW_PART_BEGIN callback and crashes the stack.

Code to reproduce

// Display an incrementing varible on every draw:
void ev_label_draw_cb(lv_event_t *e)                      
{
        static long x;
        lv_obj_t *menu_cont = lv_event_get_target(e);
        lv_obj_t *label = lv_obj_get_child(menu_cont, 0);
                                                          
        lv_label_set_text_fmt(label, "%ld", x);
        x++;
}
void init()
{
...
        // Other initialization exist above the label creation, but
        // we only care about the label for this question:
        lv_obj_t *label = lv_label_create(cont);

        lv_label_set_text(label, "");
        lv_obj_add_event_cb(cont, ev_label_draw_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
...
}

I know you want it to run in the simulator, and if you need that I will make it run in the simulator, but if you can figure it out or provide me with a hint by just looking at the code here, that would be great.

hello!

have a look at this example in the documentation, maybe this is the behavior you’re looking for

https://docs.lvgl.io/master/others/observer.html#bind-a-slider-s-value-to-a-label

in this example, the value of the slider is automatically updated on the label

That only updates when the slider updates, and I want it to update even if no buttons are pressed because time is changing even if there is no external input

Sorry, I didn’t notice that you’re using version 8.3, the observers are not implemented in this version…

You can set a timer event on the screen and update everything on the timer callback

https://docs.lvgl.io/8.3/overview/timer.html#create-a-timer

A draft of an example: the timer will run at every 500ms so no overhead will be added on redraw the entire screen

void my_timer(lv_timer_t * timer)
{
  /*Use the user_data*/
  lv_obj_t *label =lv_timer_get_user_data(timer)
  lv_label_set_text_fmt(label, "%ld", x);
  /*Do something with LVGL*/
  
  
}


void init()
{
...
        // Other initialization exist above the label creation, but
        // we only care about the label for this question:
        lv_obj_t *label = lv_label_create(cont);

        lv_label_set_text(label, "");
        lv_timer_t * timer = lv_timer_create(my_timer, 500,  label);
...
}
1 Like

Thanks, I will try it and let you know how it goes!

1 Like