Description
I bought from China a ESP32-2424S012 module. The screen part is working fine it display what I have created with SquareLine Studio, but I have nothing from the touchpad. I think that the touchpad doesn’t communicate properly with LVGL library, because the read function does not seems to be called ever.
Thank you in advance for your help!
What MCU/Processor/Board and compiler are you using?
I am using the ESP32-2424S012 module with GC9A01 display and CST816D touchpad.
Coded with Arduino IDE
What LVGL version are you using?
8.3.10
What do you want to achieve?
I wish to create a template code for this module allowing the use of any ui from SquareLine Studio.
What have you tried so far?
I tested the touchpad with a very simple Arduino’s sketch, and it is returning properly every touch with the good coordinates.
TouchPad’s test code:
#include "Arduino.h"
#include "CST816D.h"
#define I2C_SDA 4
#define I2C_SCL 5
#define TP_INT 0
#define TP_RST 1
CST816D touch(I2C_SDA, I2C_SCL, TP_RST, TP_INT);
void setup()
{
USBSerial.begin( 115200 );
touch.begin();
USBSerial.println( "I am LVGL_Arduino" );
}
bool FingerNum;
uint8_t gesture;
uint16_t touchX, touchY;
void loop()
{
FingerNum = touch.getTouch(&touchX, &touchY, &gesture);
if (FingerNum)
{
USBSerial.print("Data x ");
USBSerial.println(touchX);
USBSerial.print("Data y ");
USBSerial.println(touchY);
USBSerial.print("Gesture ");
USBSerial.println(gesture);
}
delay(100);
}
I put println in the my_touchpad_read() function but it seems that the function is never been called.
void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
USBSerial.println( "read !" );
bool touched;
uint8_t gesture;
uint16_t touchX, touchY;
touched = touch.getTouch(&touchX, &touchY, &gesture);
if (!touched)
{
USBSerial.print("Not Touched");
data->state = LV_INDEV_STATE_REL;
}
else
{
data->state = LV_INDEV_STATE_PR;
data->point.x = touchX;
data->point.y = touchY;
USBSerial.print("Data x ");
USBSerial.println(touchX);
USBSerial.print("Data y ");
USBSerial.println(touchY);
}
}
Code to reproduce
#include <lvgl.h>
#include <TFT_eSPI.h>
#include "ui.h"
#include "CST816D.h"
#define TFT_BLK 3
#define I2C_SDA 4
#define I2C_SCL 5
#define TP_INT 0
#define TP_RST 1
CST816D touch(I2C_SDA, I2C_SCL, TP_RST, TP_INT);
/*Change to your screen resolution*/
static const uint16_t screenWidth = 240;
static const uint16_t screenHeight = 240;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[ screenWidth * screenHeight / 10 ];
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
#if LV_USE_LOG != 0
/* USBSerial debugging */
void my_print(const char * buf)
{
USBSerial.printf(buf);
USBSerial.flush();
}
#endif
/* 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.endWrite();
lv_disp_flush_ready( disp );
}
/*Read the touchpad*/
void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
USBSerial.println( "read !" );
bool touched;
uint8_t gesture;
uint16_t touchX, touchY;
touched = touch.getTouch(&touchX, &touchY, &gesture);
if (!touched)
{
USBSerial.print("Not Touched");
data->state = LV_INDEV_STATE_REL;
}
else
{
data->state = LV_INDEV_STATE_PR;
data->point.x = touchX;
data->point.y = touchY;
USBSerial.print("Data x ");
USBSerial.println(touchX);
USBSerial.print("Data y ");
USBSerial.println(touchY);
}
}
void setup()
{
pinMode(TFT_BLK, OUTPUT);
analogWrite(TFT_BLK, 10);
touch.begin();
USBSerial.begin( 115200 ); /* prepare for possible USBSerial debug */
String LVGL_Arduino = "Hello Arduino! ";
LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
USBSerial.println( LVGL_Arduino );
USBSerial.println( "I am LVGL_Arduino" );
lv_init();
#if LV_USE_LOG != 0
lv_log_register_print_cb( my_print ); /* register print function for debugging */
#endif
tft.begin(); /* TFT init */
tft.setRotation( 0 ); /* Landscape orientation, flipped */
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * screenHeight / 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 );
USBSerial.println( "hello 01" );
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 );
ui_init();
USBSerial.println( "Setup done" );
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay(5);
//USBSerial.println( "loop!" );
}
Screenshot and/or video
Return of the Serial Monitor:
Hello Arduino! V8.3.10
I am LVGL_Arduino
hello 01
Setup done
Hello Arduino! V8.3.10
I am LVGL_Arduino
hello 01
Setup done