How to use a function inside the ui_event file instead of void loop()

What do you want to achieve?

Create a function inside ui_events that reads my sensors (i2c) every x seconds. If I put the function inside the void loop(), it makes the display unavailable during the reading so if I have 2 sensors with 900ms delay for reading each, its almost 2 sec without being able to interact with touch display and I have 4 of them… hahaha

What have you tried so far?

Searching on google, more searching… Searching… No luck

Screenshot or video


  • SquareLine Studio version:1.1.1
  • Operating system: Windows 10
  • Target hardware: ESP32-S2 with ili9488 TFT Touch Display

LVGL provides timers, look here: Timers — LVGL documentation
I have also had great success making use of tasks using Scott Bezek task.h - see inside his SmartKnob GitHub project - scottbez1/smartknob: Haptic input knob with software-defined endstops and virtual detents (


Awesome, thanks for the advice and the fast response! I will look into it! Will let you know if it fots my project:)

@AndyFraser, I just got back home and looked at that lv_timer thing. I noticed that it is actually present in the void loop() as “lv_timer_handler();”. My question is, where do I place my custom function(s) in arduino/Squareline project for the timer to trigger it every x seconds? Here is a sample of my function:

float check_ph() {
  Wire.requestFrom(ph_address, 32, 1);
  return_code =; // Not used

  while (Wire.available()) {
    in_char =;
    ph_data[i] = in_char;
    i += 1;
    if (in_char == 0) {
      i = 0;
  return ph_float;              //print the data.

And the result is then pushed to Squareline label and widget:

      lv_label_set_text(ui_Home_Ph_Label, phString3.c_str());
      lv_arc_set_value(ui_Home_PH_Meter, ph_val);

Thanks again :slight_smile:

Should I use the LVGL built-in task system? And if so, where should I put my code (what file and where in that file)? Thanks!!

Sorry for the late reply.

Note that LVGL timer are blocking. So what you do in them will block the UI and other timers.

I suggest used HW timers to ready from interrupt or so and only get the result with lv_timer.

After ui_init you can create the timers as described here: