Passing Variable values between Arduino ino and lv_demo_printer.c


I have adapted the lv_demo_printer() example and it is called from and Arduino.ino file. In this I have created a task that runs every 10 seconds and should update the gui based on incoming sensor readings.

The problem is that when I update a variable value in the main arduino loop, when the task is ran by lv_task_gandler() it only reverences varables which are in the lv_demo_printer.c file and does not take te updated value from the Arduino.ino file.

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

ESP32 ILI9488

What LVGL version are you using?


What do you want to achieve?

access values updated from arduino loop into lv_demo_printer.c to change GUI items.

so if you look at the code below and you called the lv_printer_example from lv_examples, how would you use the globalCounter value to determine GUI changes. This probably c 101 but I am stick so please help!

What have you tried so far?

using extern in the lv_demo_printer.c file but when I call the variable values the updated value is not used.

I have created a task within lv_demo_printer, which runs, but when It tries to take the value set in the loop it does not pick up the value.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

#include <lvgl.h>
#include <TFT_eSPI.h>
#include <lv_examples.h>
// #include <lv_demo_printer.c>
// #include <lv_examples.h>
#include <Ticker.h>

static int globalCounter = 0; // I WANT TO USE THIS VALUE GLOBALY

static String LoRaData;

#define screenWidth 480
#define screenHeight 320

TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10];
Ticker   lvgl_tick;             /* timer for lvgl */

#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * fn_name, const char * dsc)

  Serial.printf("%[email protected]%d->%s\r\n", file, line, dsc);

/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
  uint32_t w = (area->x2 - area->x1 + 1);
  uint32_t h = (area->y2 - area->y1 + 1);

  tft.setAddrWindow(area->x1, area->y1, w, h);
  tft.pushColors(&color_p->full, w * h, true);


/*Read the touchpad*/
bool my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
  uint16_t touchX, touchY;

  bool touched = tft.getTouch(&touchX, &touchY, 600);

  if (!touched)
    data->state = LV_INDEV_STATE_REL;
    return false;
    data->state = LV_INDEV_STATE_PR;

  if (touchX > screenWidth || touchY > screenHeight)
    Serial.println("Y or y outside of expected parameters..");
    Serial.print(" x:");
    /*Set the coordinates*/
    if (3 == tft.getRotation()) {
      //Shift coordinates
      data->point.x = 480 - touchX;
      data->point.y = 320 - touchY;
    } else if (1 == tft.getRotation()) {
      data->point.x = touchX;
      data->point.y = touchY;

    Serial.print("Data x");

    Serial.print("Data y");

  return false; /*Return `false` because we are not buffering and no more data to read*/


void lv_tick_handler() {

void setup()


#if LV_USE_LOG != 0
  lv_log_register_print_cb(my_print); /* register print function for debugging */

  tft.begin(); /* TFT init */
  tft.setRotation(1); /* Landscape orientation */

  // uint16_t calData[5] = { 305, 3542, 245, 3529, 3  };
  uint16_t calData[5] = { 270, 3639, 250, 3556, 7  };

  lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);

  /*Initialize the display*/
  lv_disp_drv_t disp_drv;
  disp_drv.hor_res = 480;
  disp_drv.ver_res = 320;
  disp_drv.flush_cb = my_disp_flush;
  disp_drv.buffer = &disp_buf;

  /*Initialize the (dummy) input device driver*/
  lv_indev_drv_t indev_drv;
  indev_drv.type = LV_INDEV_TYPE_POINTER;
  indev_drv.read_cb = my_touchpad_read;

  lvgl_tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);



void loop()

      lv_task_handler(); /* let the GUI do its work */




Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

I managed to find a fix using this post: