How use LV_INDEV_TYPE_BUTTON in LVGL version 7.3


I have created a button & Input dev using LV_INDEV_TYPE_BUTTON. I don’t what’s wrong in my code?. Whenever I press a pushbutton(which is connected to our dev board(STM32F207)) then I got debug print push-button pressed. But there is no change in UI button?. I have looked soo many examples& issues but all are related old versions that example API’s are not available in the latest LVGL version v7.3

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

STM32F207zg nucleo board

What LVGL version are you using?


What do you want to achieve?

What have you tried so far?

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:

/*You code here*/

/* Key Input Test /

static lv_group_t* ModeGroup;

void my_button_init( void )
static lv_indev_t *indev_button;
lv_indev_drv_t indev_drv;

/Register a button input device/

indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = my_input_read;
indev_button = lv_indev_drv_register(&indev_drv);

/Assign buttons to points on the screen/
static const lv_point_t btn_points[ ] = {
{1, 1} /Button 0 -> x:1; y:1/

lv_indev_set_button_points(indev_button, btn_points);

ModeGroup = lv_group_create();


uint8_t my_btn_read( void )
if(HAL_GPIO_ReadPin(MODE_GPIO_Port, MODE_Pin) == 0)

return 1;
return 0;

bool my_input_read(lv_indev_data_t data)
static int8_t last_btn = 0; / Store the last pressed button /
int8_t btn_pr = my_btn_read(); / Get the ID (0,1,2...) of the pressed button */

if(btn_pr > 0) {                /* Is there a button press? */
   last_btn = btn_pr;           /* Save the ID of the pressed button */
   data->state = LV_INDEV_STATE_PR;  /* Set the pressed state */	   
   HAL_UART_Transmit(&huart6,"LV_INDEV_STATE_PR\r\n",strlen("LV_INDEV_STATE_PR\r\n"), 1000);
else {
   data->state = LV_INDEV_STATE_REL; /* Set the released state */

data->btn_id = last_btn;            /* Set the last button */

return false;                    /* No buffering so no more data read */

/* Key Test /

lv_style_t style_btn;

void btn_event_cb(lv_obj_t * btn, lv_event_t event)
HAL_UART_Transmit(&huart6,DBGBuff,strlen(DBGBuff), 1000);

if(event == LV_EVENT_PRESSED) 
	HAL_UART_Transmit(&huart6,"Clicked\r\n",strlen("Clicked\r\n"), 1000);
    static uint8_t cnt = 0;

    /*Get the first child of the button which is the label and change its text*/
    lv_obj_t * label = lv_obj_get_child(btn, NULL);
	lv_label_set_recolor(label, true);
    lv_label_set_text_fmt(label, "#FFFFFF MODE: %d#", cnt);


Create a button with a label and react on Click event.
void lv_usr_Mode_B1(void)
//static lv_style_t style_btn;

/Create a simple button style/
lv_style_set_radius(&style_btn, LV_STATE_DEFAULT, 1);
lv_style_set_bg_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_NAVY);
lv_style_set_bg_grad_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_AQUA);
lv_style_set_bg_grad_dir(&style_btn, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);

/Swap the colors in pressed state/
lv_style_set_bg_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_ORANGE);
lv_style_set_bg_grad_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_SILVER);

/Add a border/
lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70);
lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 1);

lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /Add a button the current screen/
lv_obj_set_pos(btn, 1, 1); /Set its position/
lv_obj_set_size(btn, 80, 40); /Set its size/
lv_obj_set_event_cb(btn, btn_event_cb); /Assign a callback to the button/

lv_obj_t * label = lv_label_create(btn, NULL); /Add a label to the button/
lv_label_set_recolor(label, true); /Enable re-coloring by commands in the text/
lv_label_set_text(label, "#FFFFFF MODE#"); /Set the labels text/

lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn);

//lv_obj_set_free_num(btn, 1); /Set a unique number for the button/
lv_group_add_obj(ModeGroup, btn);


Screenshot and/or video

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


There were 2 issues in your code:

The prototype of the indev_read function should look like this:
bool my_input_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)

  • there is an lv_indev_drv_t parameter too.
  • data is a pointer

And the id of the first button is 0, not 1.

See this example.