Touch working but button clicks not registering

Description

I can get my touch driver working, but button presses are not registering.

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

ESP32 with parallel ILI9488 and FT6236 (ESP32-S2 Parallel TFT with Touch 3.5'' ILI9488 V1.1 | Makerfabs). Latest Arduino IDE, lvgl 8.2.

What do you want to achieve?

Getting button presses registering.

What have you tried so far?

I tried different touchscreen drivers (lovyangfx, dustinwatts ft6236 driver, makerfabs own driver), but these are not working. “my_touchpad_read” never gets called. I added Serial.println(“mytouchpadread was called”); but I never see it in the serial console. I do see however output like this in the console: “Screen was touched at x 35 and y 134” due to the test routine


I added to the loop.

Code to reproduce

Add the relevant code snippets here.

#define LGFX_USE_V1

#include <LovyanGFX.hpp>
#include <SPI.h>
#include <lvgl.h>
#include <FT6236.h>
#include <WiFi.h>



const char* ssid = "MySSID";
const char* password = "VerySecret";

//#define SDA_FT6236 38
//#define SCL_FT6236 39
//FT6236 ts = FT6236();
//#define I2C_SCL 39
//#define I2C_SDA 38

#define LCD_CS 37
#define LCD_BLK 45

class LGFX : public lgfx::LGFX_Device
{
   //lgfx::Panel_ILI9341 _panel_instance;
   lgfx::Panel_ILI9488 _panel_instance;
   lgfx::Bus_Parallel16 _bus_instance; 
   lgfx::Touch_FT5x06  _touch_instance; 
public:
   LGFX(void)
   {
       {                                     
           auto cfg = _bus_instance.config(); 

           // 16位设置
           cfg.i2s_port = I2S_NUM_0;  
           cfg.freq_write = 16000000; 
           cfg.pin_wr = 35;           
           cfg.pin_rd = 34;           
           cfg.pin_rs = 36;          
           cfg.pin_d0 = 33;
           cfg.pin_d1 = 21;
           cfg.pin_d2 = 14;
           cfg.pin_d3 = 13;
           cfg.pin_d4 = 12;
           cfg.pin_d5 = 11;
           cfg.pin_d6 = 10;
           cfg.pin_d7 = 9;
           cfg.pin_d8 = 3;
           cfg.pin_d9 = 8;
           cfg.pin_d10 = 16;
           cfg.pin_d11 = 15;
           cfg.pin_d12 = 7;
           cfg.pin_d13 = 6;
           cfg.pin_d14 = 5;
           cfg.pin_d15 = 4;

           _bus_instance.config(cfg);              
           _panel_instance.setBus(&_bus_instance); 
       }

       {                                       
           auto cfg = _panel_instance.config(); 

           cfg.pin_cs = -1;   
           cfg.pin_rst = -1;  
           cfg.pin_busy = -1; 
           cfg.memory_width = 320;   
           cfg.memory_height = 480; 
           cfg.panel_width = 320;    
           cfg.panel_height = 480;   
           cfg.offset_x = 0;        
           cfg.offset_y = 0;         
           cfg.offset_rotation = 0;  
           cfg.dummy_read_pixel = 8; 
           cfg.dummy_read_bits = 1;  
           cfg.readable = true;      
           cfg.invert = false;      
           cfg.rgb_order = false;    
           cfg.dlen_16bit = true;   
           cfg.bus_shared = true;   

           _panel_instance.config(cfg);
       }
        { 
     auto cfg = _touch_instance.config();

     cfg.x_min      = 0;    
     cfg.x_max      = 319;  
     cfg.y_min      = 0;    
     cfg.y_max      = 479;  
     cfg.pin_int    = -1;   
     cfg.bus_shared = false; 
     cfg.offset_rotation = 0;


     cfg.i2c_port = 0;      
     cfg.i2c_addr = 0x38;   
     cfg.pin_sda  = 38;    
     cfg.pin_scl  = 39;     
     cfg.freq = 400000;    

     _touch_instance.config(cfg);
     _panel_instance.setTouch(&_touch_instance);  
   } 
        
       setPanel(&_panel_instance);
   }
};

LGFX tft;

static const uint32_t screenWidth  = 320;
static const uint32_t screenHeight = 480;



static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * 10 ];
/* 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.startWrite();
  tft.setAddrWindow( area->x1, area->y1, w, h );
  //tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
  tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
  //tft.writePixels((lgfx::swap565_t*)&color_p->full, w*h);
  tft.endWrite();

  lv_disp_flush_ready( disp );
}


void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
  Serial.println("mytouchpadread was called");
  uint16_t touchX, touchY;

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

  if(!touched)
  {
     data->state = LV_INDEV_STATE_REL;
  }
  else
  {
     data->state = LV_INDEV_STATE_PR;

     /*Set the coordinates*/
     data->point.x = touchX;
     data->point.y = touchY;

     Serial.print( "Data x " );
     Serial.println( touchX );

     Serial.print( "Data y " );
     Serial.println( touchY );
  }
}



void setup(void)
{      
   pinMode(LCD_CS, OUTPUT);
   pinMode(LCD_BLK, OUTPUT);
   digitalWrite(LCD_CS, LOW);
   digitalWrite(LCD_BLK, HIGH);

   Serial.begin(115200);
     // Connect to WiFi network
   WiFi.begin(ssid, password);
   Serial.println("");

   // Wait for connection
   while (WiFi.status() != WL_CONNECTED) {
       delay(500);
       Serial.print(".");
   }
       Serial.println("");
   Serial.print("Connected to ");
   Serial.println(ssid);
   Serial.print("IP address: ");
   Serial.println(WiFi.localIP());


   tft.init();
  // tft.setRotation(1);
   tft.setBrightness(120);



  lv_init();
  lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * 10 );

  //Initialize the display

  static lv_disp_drv_t disp_drv;
  lv_disp_drv_init(&disp_drv);

  //Change the following line to your display resolution

  disp_drv.hor_res = screenWidth;
  disp_drv.ver_res = screenHeight;
  disp_drv.flush_cb = my_disp_flush;
  disp_drv.draw_buf = &draw_buf;
  lv_disp_drv_register(&disp_drv);

 static lv_indev_drv_t indev_drv;
 lv_indev_drv_init(&indev_drv);
 indev_drv.type = LV_INDEV_TYPE_POINTER;
 indev_drv.read_cb = my_touchpad_read;
 lv_indev_drv_register(&indev_drv);

lv_example_get_started_1();
}

void loop()
{ 
 uint16_t touchX, touchY;
 bool touched =tft.getTouch(&touchX, &touchY);
 if(touched)
  {
     Serial.print("Screen was touched at x "); Serial.print(touchX) ; Serial.print(" and y "); Serial.println(touchY);
  }
 lv_timer_handler(); 
 delay( 5 );
 
 
}

static void btn_event_cb(lv_event_t * e)
{
   
   lv_event_code_t code = lv_event_get_code(e);
  // Serial.print(code); Serial.print(" "); Serial.println(LV_EVENT_CLICKED);
   lv_obj_t * btn = lv_event_get_target(e);
   if(code == LV_EVENT_CLICKED) {
       static uint8_t cnt = 0;
       cnt++;

       /*Get the first child of the button which is the label and change its text*/
       lv_obj_t * label = lv_obj_get_child(btn, 0);
       lv_label_set_text_fmt(label, "Button: %d", cnt);
   }
}


void lv_example_get_started_1(void)
{
   lv_obj_t * btn = lv_btn_create(lv_scr_act());    
   lv_obj_set_size(btn, 120, 50);                         
   lv_obj_align(btn, LV_ALIGN_CENTER, 0,0);
   lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);           

   lv_obj_t * label = lv_label_create(btn);          
   lv_label_set_text(label, "Button");                    
   lv_obj_center(label);
}

```c

I confirm. Same problem. Were you able to resolve the issue?