I'm about to give up / Touchscreen

Hi there,

My simple goal - “Button and action”. :smile:

This is my code:

#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>


void btn_event_cb(lv_obj_t * btn, lv_event_t event)
    if(event == LV_EVENT_CLICKED) {

int main(void)



    static lv_color_t buf[DISP_BUF_SIZE];

    static lv_disp_buf_t disp_buf;
    lv_disp_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);

    lv_disp_drv_t disp_drv;
    disp_drv.buffer = &disp_buf;
    disp_drv.flush_cb = fbdev_flush;

    lv_indev_drv_t indev_drv;
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = evdev_read;
    lv_indev_drv_register(&indev_drv);    /*Add a display the LittlevGL sing the frame buffer driver*/

    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);     
    lv_obj_set_pos(btn, 10, 10);                            
    lv_obj_set_size(btn, 300, 200);                          
    lv_obj_set_event_cb(btn, btn_event_cb);               
    lv_obj_t * label = lv_label_create(btn, NULL);       
    lv_label_set_text(label, "Button");                 

    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {

    return 0;

I’m using a Raspberry with an attached touchscreen. Evtest shows everything is fine with /dev/input/event1.


#define LV_HOR_RES_MAX (800)
#define LV_VER_RES_MAX (480)
#define LV_COLOR_DEPTH 32


#define USE_EVDEV 1
#LIBINPUT_NAME “/dev/input/event1”
#define USE_FBDEV 1
#define FBDEV_PATH “/dev/fb0”

Screen is working fine as expected but I don’t get any feedback from my button. I’m sure it must be a silly mistake…

Any ideas?

Thank you very much in advance.

I haven’t gotten my touchscreen working yet as I am still waiting for some driver work to be done, but I have simulated with a mouse. Have you run evtest to ensure you see the touch events?

I referenced this post when I was bringing up the mouse.

Hi Tarvik,

thank you for your quick reply. Evtest runs without any problems. I’ll try it with mouse as input. Good idea!

(Sorry for my bad formatted code in first post - I don’t know how to correct it)

I’m still learning the formatting myself… I reference the link found in here a lot.

edit Ugh, sorry, I missed out in your original post where you already stated that you’d run evtest successfully. My brain still hasn’t started this morning… :slight_smile:

Thanks a lot! (And you missed nothing :wink: - I deleted this information while fighting with the formatting)

What is the evdev_read code?

Is there a reason why you are using the option for LIBINPUT when you are using the evdev driver?

Some touch controllers scale the values to 12 bit eqivalent ADC value, not the display resolution.

Depending on the touch device, you may need to enable EVDEV_SCALE or EVDEV_CALIBRATE. These options are in lv_drv_conf.h just below USE_EVDEV. Note They are mutualy exclusive.
Try to find what the specifics are for the controller used on the display.
Then try,

#  define EVDEV_SCALE             1               /* Scale input, e.g. if touchscreen resolution does not match display resolution */
#    define EVDEV_SCALE_HOR_RES     (4096)          /* Horizontal resolution of touchscreen */
#    define EVDEV_SCALE_VER_RES     (4096)          /* Vertical resolution of touchscreen */
#  endif  /*EVDEV_SCALE*/

If you find that the X/Y axis are swapped, then set EVDEV_SWAP_AXES to 1

If you find that top is bottom and or left is right then set ``EVDEV_CALIBRATE``` to 1 and play with the calibration values, for example

#  define EVDEV_CALIBRATE         1               /*Scale and offset the touchscreen coordinates by using maximum and minimum values for each axis*/
#    define EVDEV_HOR_MIN   4095                  /*If EVDEV_XXX_MIN > EVDEV_XXX_MAX the XXX axis is automatically inverted*/
#    define EVDEV_HOR_MAX   0
#    define EVDEV_VER_MIN   0
#    define EVDEV_VER_MAX   4095
#  endif  /*EVDEV_SCALE*/