How to setup the lvgl library for Esp32-s3-WROOM-1 with TFT display 800*480

I have a similar problem.

I bought a 5" elecrow display and the files they sent as an example.

They use very old libraries, which is Arduino_GFX

And nothing compiles, I can’t do a basic HelloWord with LVGL and this card.

I read this forum thread carefully and still haven’t been able to find a solution.

Can anybody help me.

My board is a small variation of the problem you are experiencing.

image

image

The declared display is the ILI6122 and ILI5960

This code below is the example provided by the manufacturer.

But it’s useless because it doesn’t compile and uses very outdated libraries.


#include <lvgl.h>
#include <demos/lv_demos.h>
//UI
#include "ui.h"
static int first_flag = 0;
extern int zero_clean;
extern int goto_widget_flag;
extern int bar_flag;
extern lv_obj_t * ui_MENU;
extern lv_obj_t * ui_TOUCH;
extern lv_obj_t * ui_JIAOZHUN;
extern lv_obj_t * ui_Label2;
static lv_obj_t * ui_Label;//TOUCH interface label
static lv_obj_t * ui_Label3;//TOUCH interface label3
static lv_obj_t * ui_Labe2;//Menu interface progress bar label
static lv_obj_t * bar;//Menu interface progress bar
#include <SPI.h>
SPIClass& spi = SPI;
uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
uint8_t  touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
static int val = 100;

static uint32_t screenWidth;
static uint32_t screenHeight;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t disp_draw_buf[800 * 480 / 10];
static lv_disp_drv_t disp_drv;

#include <Ticker.h>          //Call the ticker. H Library
Ticker ticker1;
#include <Arduino_GFX_Library.h>
#define TFT_BL 2
#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin

/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *lcd = create_default_Arduino_GFX();
#else /* !defined(DISPLAY_DEV_KIT) */

Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
  GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
  40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,
  45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
  5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
  8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */
);

Arduino_RPi_DPI_RGBPanel *lcd = new Arduino_RPi_DPI_RGBPanel(
  bus,
  800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,
  480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
  1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);
#endif /* !defined(DISPLAY_DEV_KIT) */
#include "touch.h"
/* 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);

#if (LV_COLOR_16_SWAP != 0)
  lcd->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#else
  lcd->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#endif

  lv_disp_flush_ready(disp);
}

void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
  if (touch_has_signal())
  {
    if (touch_touched())
    {
      data->state = LV_INDEV_STATE_PR;

      /*Set the coordinates*/
      data->point.x = touch_last_x;
      data->point.y = touch_last_y;
      Serial.print( "Data x :" );
      Serial.println( touch_last_x );

      Serial.print( "Data y :" );
      Serial.println( touch_last_y );
    }
    else if (touch_released())
    {
      data->state = LV_INDEV_STATE_REL;
    }
  }
  else
  {
    data->state = LV_INDEV_STATE_REL;
  }
}

uint16_t calData[5] = { 190, 3679, 382, 3335, 0 };
void callback1()  //Callback function
{
  if (bar_flag == 6)
  {
    if (val > 1)
    {
      val--;
      lv_bar_set_value(bar, val, LV_ANIM_OFF);
      lv_label_set_text_fmt(ui_Labe2, "%d %%", val);
    }
    else
    {
      lv_obj_clear_flag(ui_touch, LV_OBJ_FLAG_CLICKABLE);
      lv_label_set_text(ui_Labe2, "Loading");
      delay(150);
      val = 100;
      bar_flag = 0; //Stop progress bar sign
      goto_widget_flag = 1; //Enter the widget logo

    }
  }
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); // Init Display
#ifdef TFT_BL
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, LOW);
#endif
  lcd->begin();
  lcd->fillScreen(BLACK);
  lcd->setTextSize(2);
  delay(200);

  lv_init();
  touch_init();
  screenWidth = lcd->width();
  screenHeight = lcd->height();

  lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * screenHeight / 10);
  //  lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, 480 * 272 / 10);
  /* Initialize the display */
  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);

  /* Initialize the (dummy) input device driver */
  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);
#ifdef TFT_BL
  digitalWrite(TFT_BL, HIGH);
#endif
  ui_init();//Boot UI
  while (1)
  {
    if (goto_widget_flag == 1)//Go to widget
    {
      if (ticker1.active() == true)
      {
        ticker1.detach();
      }
      goto_widget_flag = 0;
      delay(300);
      break;
    }

    if (goto_widget_flag == 3)//Go to the touch screen and close the progress bar thread first
    {
      bar_flag = 0; //Stop progress bar sign
      if (ticker1.active() == true)
      {
        ticker1.detach();
      }
      if (first_flag == 0 || first_flag == 1)
      {
        label_xy();
        first_flag = 2;
      }
      if (zero_clean == 1)
      {
        touch_last_x = 0;
        touch_last_y = 0;
        zero_clean = 0;
      }
      lv_label_set_text(ui_Label, "Touch Adjust:");
      lv_label_set_text_fmt(ui_Label3, "%d  %d", touch_last_x, touch_last_y); //Display touch information
    }

    if (goto_widget_flag == 4)//触摸界面返回到Menu界面,使进度条清零重启
    {
      val = 100;
      delay(100);
      ticker1.attach_ms(35, callback1);//每20ms调用callback1
      goto_widget_flag = 0;
    }

    if (goto_widget_flag == 5) //Trigger Calibration Signal
    {
      lv_scr_load_anim(ui_touch_calibrate, LV_SCR_LOAD_ANIM_NONE, 0, 0, false);
      lv_timer_handler();
      lv_timer_handler();
      delay(100);
      touch_calibrate();//Touch Calibration
      lv_scr_load_anim(ui_TOUCH, LV_SCR_LOAD_ANIM_NONE, 0, 0, false);
      lv_timer_handler();
      delay(100);
      goto_widget_flag = 3; //Access to the touch screen logo
      touch_last_x = 0;
      touch_last_y = 0;
    }

    if (bar_flag == 6)//Runs the progress bar once when you first boot into the Menu screen, then stops running after that
    {
      if (first_flag == 0)
      {
        lv_example_bar();
        ticker1.attach_ms(35, callback1);//每20ms调用callback1
        first_flag = 1;
      }
    }

    lv_timer_handler();
  }


  lcd->fillScreen(BLACK);
  lv_demo_widgets();//Main UI
  Serial.println( "Setup done" );

}

void loop() {
  // put your main code here, to run repeatedly:
  lv_timer_handler();
  delay(5);

}

//Touch Label Controls
void label_xy()
{
  ui_Label = lv_label_create(ui_TOUCH);
  lv_obj_enable_style_refresh(true);
  lv_obj_set_width(ui_Label, LV_SIZE_CONTENT);   /// 1
  lv_obj_set_height(ui_Label, LV_SIZE_CONTENT);    /// 1
  lv_obj_set_x(ui_Label, -55);
  lv_obj_set_y(ui_Label, -40);
  lv_obj_set_align(ui_Label, LV_ALIGN_CENTER);
  lv_obj_set_style_text_color(ui_Label, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT);
  lv_obj_set_style_text_opa(ui_Label, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
  lv_obj_set_style_text_font(ui_Label, &lv_font_montserrat_24, LV_PART_MAIN | LV_STATE_DEFAULT);

  ui_Label3 = lv_label_create(ui_TOUCH);
  lv_obj_enable_style_refresh(true);
  lv_obj_set_width(ui_Label3, LV_SIZE_CONTENT);   /// 1
  lv_obj_set_height(ui_Label3, LV_SIZE_CONTENT);    /// 1
  lv_obj_set_x(ui_Label3, 85);
  lv_obj_set_y(ui_Label3, -40);
  lv_obj_set_align(ui_Label3, LV_ALIGN_CENTER);
  lv_obj_set_style_text_color(ui_Label3, lv_color_hex(0x00FF00), LV_PART_MAIN | LV_STATE_DEFAULT);
  lv_obj_set_style_text_opa(ui_Label3, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
  lv_obj_set_style_text_font(ui_Label3, &lv_font_montserrat_24, LV_PART_MAIN | LV_STATE_DEFAULT);

}


//Progress bar control
void lv_example_bar(void)
{
  //////////////////////////////
  bar = lv_bar_create(ui_MENU);
  lv_bar_set_value(bar, 0, LV_ANIM_OFF);
  lv_obj_set_width(bar, 480);
  lv_obj_set_height(bar, 25);
  lv_obj_set_x(bar, 0);
  lv_obj_set_y(bar, 175);
  lv_obj_set_align(bar, LV_ALIGN_CENTER);
  lv_obj_set_style_bg_img_src(bar, &ui_img_bar_800_01_png, LV_PART_MAIN | LV_STATE_DEFAULT);

  lv_obj_set_style_bg_img_src(bar, &ui_img_bar_800_02_png, LV_PART_INDICATOR | LV_STATE_DEFAULT);
  lv_obj_set_style_outline_color(bar, lv_color_hex(0x2D8812), LV_PART_INDICATOR | LV_STATE_DEFAULT);
  lv_obj_set_style_outline_opa(bar, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT);
  //////////////////////
  ui_Labe2 = lv_label_create(bar);//Creating Tags
  lv_obj_set_style_text_color(ui_Labe2, lv_color_hex(0x09BEFB), LV_STATE_DEFAULT);
  lv_label_set_text(ui_Labe2, "0%");
  lv_obj_center(ui_Labe2);
}

#define Z_THRESHOLD 350 // Touch pressure threshold for validating touches
#define _RAWERR 20 // Deadband error allowed in successive position samples
void begin_touch_read_write(void) {
  digitalWrite(38, HIGH); // Just in case it has been left low
  spi.setFrequency(600000);
  digitalWrite(38, LOW);
}

void end_touch_read_write(void) {
  digitalWrite(38, HIGH); // Just in case it has been left low
  spi.setFrequency(600000);

}

uint16_t getTouchRawZ(void) {

  begin_touch_read_write();

  // Z sample request
  int16_t tz = 0xFFF;
  spi.transfer(0xb0);               // Start new Z1 conversion
  tz += spi.transfer16(0xc0) >> 3;  // Read Z1 and start Z2 conversion
  tz -= spi.transfer16(0x00) >> 3;  // Read Z2

  end_touch_read_write();

  return (uint16_t)tz;
}

uint8_t getTouchRaw(uint16_t *x, uint16_t *y) {
  uint16_t tmp;

  begin_touch_read_write();

  // Start YP sample request for x position, read 4 times and keep last sample
  spi.transfer(0xd0);                    // Start new YP conversion
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0xd0);                    // Read last 8 bits and start new YP conversion
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0xd0);                    // Read last 8 bits and start new YP conversion
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0xd0);                    // Read last 8 bits and start new YP conversion

  tmp = spi.transfer(0);                   // Read first 8 bits
  tmp = tmp << 5;
  tmp |= 0x1f & (spi.transfer(0x90) >> 3); // Read last 8 bits and start new XP conversion

  *x = tmp;

  // Start XP sample request for y position, read 4 times and keep last sample
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0x90);                    // Read last 8 bits and start new XP conversion
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0x90);                    // Read last 8 bits and start new XP conversion
  spi.transfer(0);                       // Read first 8 bits
  spi.transfer(0x90);                    // Read last 8 bits and start new XP conversion

  tmp = spi.transfer(0);                 // Read first 8 bits
  tmp = tmp << 5;
  tmp |= 0x1f & (spi.transfer(0) >> 3);  // Read last 8 bits

  *y = tmp;

  end_touch_read_write();

  return true;
}

uint8_t validTouch(uint16_t *x, uint16_t *y, uint16_t threshold) {
  uint16_t x_tmp, y_tmp, x_tmp2, y_tmp2;

  // Wait until pressure stops increasing to debounce pressure
  uint16_t z1 = 1;
  uint16_t z2 = 0;
  while (z1 > z2)
  {
    z2 = z1;
    z1 = getTouchRawZ();
    delay(1);
    Serial.print("z1:");
    Serial.println(z1);
  }


  if (z1 <= threshold) return false;

  getTouchRaw(&x_tmp, &y_tmp);


  delay(1); // Small delay to the next sample
  if (getTouchRawZ() <= threshold) return false;

  delay(2); // Small delay to the next sample
  getTouchRaw(&x_tmp2, &y_tmp2);


  if (abs(x_tmp - x_tmp2) > _RAWERR) return false;
  if (abs(y_tmp - y_tmp2) > _RAWERR) return false;

  *x = x_tmp;
  *y = y_tmp;

  return true;
}

void calibrateTouch(uint16_t *parameters, uint32_t color_fg, uint32_t color_bg, uint8_t size) {
  int16_t values[] = {0, 0, 0, 0, 0, 0, 0, 0};
  uint16_t x_tmp, y_tmp;
  uint16_t _width = 800;
  uint16_t _height = 480;

  for (uint8_t i = 0; i < 4; i++) {
    lcd->fillRect(0, 0, size + 1, size + 1, color_bg);
    lcd->fillRect(0, _height - size - 1, size + 1, size + 1, color_bg);
    lcd->fillRect(_width - size - 1, 0, size + 1, size + 1, color_bg);
    lcd->fillRect(_width - size - 1, _height - size - 1, size + 1, size + 1, color_bg);

    if (i == 5) break; // used to clear the arrows

    switch (i) {
      case 0: // up left
        lcd->drawLine(0, 0, 0, size, color_fg);
        lcd->drawLine(0, 0, size, 0, color_fg);
        lcd->drawLine(0, 0, size , size, color_fg);
        break;
      case 1: // bot left
        lcd->drawLine(0, _height - size - 1, 0, _height - 1, color_fg);
        lcd->drawLine(0, _height - 1, size, _height - 1, color_fg);
        lcd->drawLine(size, _height - size - 1, 0, _height - 1 , color_fg);
        break;
      case 2: // up right
        lcd->drawLine(_width - size - 1, 0, _width - 1, 0, color_fg);
        lcd->drawLine(_width - size - 1, size, _width - 1, 0, color_fg);
        lcd->drawLine(_width - 1, size, _width - 1, 0, color_fg);
        break;
      case 3: // bot right
        lcd->drawLine(_width - size - 1, _height - size - 1, _width - 1, _height - 1, color_fg);
        lcd->drawLine(_width - 1, _height - 1 - size, _width - 1, _height - 1, color_fg);
        lcd->drawLine(_width - 1 - size, _height - 1, _width - 1, _height - 1, color_fg);
        break;
    }

    // user has to get the chance to release
    if (i > 0) delay(1000);

    for (uint8_t j = 0; j < 8; j++) {
      while (touch_has_signal())
      {
        if (touch_touched())
        {
          Serial.print( "Data x :" );
          Serial.println( touch_last_x );
          Serial.print( "Data y :" );
          Serial.println( touch_last_y );
          break;
        }
      }
    }
  }
}

void touch_calibrate()//screen calibration
{
  uint16_t calData[5];
  uint8_t calDataOK = 0;
  Serial.println("screen calibration");

  //校准
  Serial.println("Touch corners as directed");
  lv_timer_handler();
  calibrateTouch(calData, MAGENTA, BLACK, 17);
  Serial.println("calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15)");
  Serial.println(); Serial.println();
  Serial.println("// Use this calibration code in setup():.");
  Serial.print("uint16_t calData[5] = ");
  Serial.print("{ ");

  for (uint8_t i = 0; i < 5; i++)
  {
    Serial.print(calData[i]);
    if (i < 4) Serial.print(", ");
  }

  Serial.println(" };");


}

void setTouch(uint16_t *parameters) {
  touchCalibration_x0 = parameters[0];
  touchCalibration_x1 = parameters[1];
  touchCalibration_y0 = parameters[2];
  touchCalibration_y1 = parameters[3];

  if (touchCalibration_x0 == 0) touchCalibration_x0 = 1;
  if (touchCalibration_x1 == 0) touchCalibration_x1 = 1;
  if (touchCalibration_y0 == 0) touchCalibration_y0 = 1;
  if (touchCalibration_y1 == 0) touchCalibration_y1 = 1;

  touchCalibration_rotate = parameters[4] & 0x01;
  touchCalibration_invert_x = parameters[4] & 0x02;
  touchCalibration_invert_y = parameters[4] & 0x04;
}

Does anyone have an idea what could be happening?

Which path to follow?

@Xylopyrographer and @Yuri_Alves_Bordin

(Fala Youri me ajuda, por favor). Tamos de boa

After trying this code:

/*******************************************************************************
 * LVGL Widgets
 * This is a widgets demo for LVGL - Light and Versatile Graphics Library
 * import from: https://github.com/lvgl/lv_demos.git
 *
 * This was created from the project here 
 * https://www.makerfabs.com/sunton-esp32-s3-4-3-inch-ips-with-touch.html
 * 
 * Dependent libraries:
 * LVGL: https://github.com/lvgl/lvgl.git

 * Touch libraries:
 * FT6X36: https://github.com/strange-v/FT6X36.git
 * GT911: https://github.com/TAMCTec/gt911-arduino.git
 * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
 *
 * LVGL Configuration file:
 * Copy your_arduino_path/libraries/lvgl/lv_conf_template.h
 * to your_arduino_path/libraries/lv_conf.h
 * Then find and set:
 * #define LV_COLOR_DEPTH     16
 * #define LV_TICK_CUSTOM     1
 *
 * For SPI display set color swap can be faster, parallel screen don't set!
 * #define LV_COLOR_16_SWAP   1
 *
 * Optional: Show CPU usage and FPS count
 * #define LV_USE_PERF_MONITOR 1
 ******************************************************************************/
//#include "lv_demo_widgets.h"
//#include <Arduino.h>
#include <lvgl.h>
//#include <demos/lv_demos.h>
#include <Arduino_GFX_Library.h>
#include <esp_now.h>
#include <WiFi.h>
#include <ArduinoJson.h>

#define TFT_BL 2
#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
 
unsigned long previousMillis = 0;  
const long interval = 5000;

void Create_Screen1(void);
void Create_Screen2(void);
void Create_Screen3(void);
void button_event_cb(lv_event_t *event);

Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
    40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,
    45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
    5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
    8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */,
    0 /* hsync_polarity */, 8 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 8 /* hsync_back_porch */,
    0 /* vsync_polarity */, 8 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 8 /* vsync_back_porch */,
    0 /* pclk_active_neg */, 13000000 /* prefer_speed */);
    
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
    800 /* width */, 480 /* height */, rgbpanel);

#include "touch.h"


void button_event_cb(lv_event_t *event);


/* Change to your screen resolution */
static uint32_t screenWidth;
static uint32_t screenHeight;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;

/* 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);

#if (LV_COLOR_16_SWAP != 0)
  gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#else
  gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
#endif

  lv_disp_flush_ready(disp);
}

void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
  if (touch_has_signal())
  {
    if (touch_touched())
    {
      data->state = LV_INDEV_STATE_PR;
      /*Set the coordinates*/
      data->point.x = touch_last_x;
      data->point.y = touch_last_y;
    }
    else if (touch_released())
    {
      data->state = LV_INDEV_STATE_REL;
    }
  }
  else
  {
    data->state = LV_INDEV_STATE_REL;
  }
}

lv_obj_t *screen1;
lv_obj_t *screen2;
lv_obj_t *screen3;

void setup(){
        Serial.begin(115200);

          // Init touch device
          // Init Display
          gfx->begin();
          #ifdef TFT_BL
          pinMode(TFT_BL, OUTPUT);
          digitalWrite(TFT_BL, HIGH);
          #endif
          gfx->fillScreen(RED);
          delay(500);
          // gfx->fillScreen(GREEN);
          // delay(500);
          // gfx->fillScreen(RED);
          // delay(500);
          // gfx->fillScreen(GREEN);
          // delay(500);
          // gfx->fillScreen(RED);
          // delay(500);

          lv_init();
          delay(10);
          touch_init();

          screenWidth = gfx->width();
          screenHeight = gfx->height();

          #ifdef ESP32
          disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
          #else
          disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4);
          #endif
          if (!disp_draw_buf)
          {
              printf("LVGL disp_draw_buf allocate failed!\n");
          }
          else
          {
          lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * screenHeight / 4);

          /* Initialize the display */
          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);

          /* Initialize the (dummy) input device driver */
          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);

          //******************************* MY CODE *******************************************
          //Dim the TFT backlight
          analogWrite(TFT_BL, 255 / 1.5); // values go from 0 to 255,

          //Three(3) Screen Example
          Create_Screen1();       //Create and load the first screen
          lv_scr_load(screen1);

          printf("Setup done\n");
        }
}

void loop(){
        lv_timer_handler(); /* let the GUI do its work */
        delay(5);

        unsigned long currentMillis = millis();
        if (currentMillis - previousMillis >= interval) {
          previousMillis = currentMillis;
          //espnow_senddata();
        }
}


//**********************  PROCEDURES  *************************************************
void Create_Screen1(void){
      screen1 = lv_obj_create(NULL);

      lv_obj_t * button1 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button1, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button1, 170, 80);
      lv_obj_set_pos(button1, 32, 100);
      lv_obj_t * label1 = lv_label_create(button1);
      lv_label_set_text(label1, "Test");

      lv_obj_t * button2 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button2, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button2, 170, 80);
      lv_obj_set_pos(button2, 249, 100);
      lv_obj_t * label2 = lv_label_create(button2);
      lv_label_set_text(label2, "Goto_Screen2");
}

void Create_Screen2(void){
      screen2 = lv_obj_create(NULL);

      lv_obj_t * button3 = lv_btn_create(screen2);
      lv_obj_add_event_cb(button3, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button3, 170, 80);
      lv_obj_set_pos(button3, 249, 100);
      lv_obj_t * label3 = lv_label_create(button3);
      lv_label_set_text(label3, "Goto_Screen3");
}

void Create_Screen3(void){
      screen3 = lv_obj_create(NULL);

      lv_obj_t * button4 = lv_btn_create(screen3);
      lv_obj_add_event_cb(button4, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button4, 170, 80);
      lv_obj_set_pos(button4, 249, 100);
      lv_obj_t * label4 = lv_label_create(button4);
      lv_label_set_text(label4, "Goto_Screen1");
}


void button_event_cb(lv_event_t *event){

        lv_obj_t *btn = lv_event_get_target(event);
        lv_obj_t * label = lv_obj_get_child(btn, 0);
        const char * text = lv_label_get_text(label);
        printf ("Button_Touched: %s \n", text);
        printf("[APP] Minimum memory: %s bytes\n", String(esp_get_minimum_free_heap_size()));

        if(strcmp(text, "Goto_Screen2") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen2:\n");
          Create_Screen2();
          lv_scr_load(screen2);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          //printf ("Clean Screen1:\n");
          //lv_obj_clean(screen1);
          printf ("Delete Screen1:\n");
          lv_obj_del(screen1);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen3") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen3:\n");
          Create_Screen3();
          lv_scr_load(screen3);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen2:\n");
          lv_obj_del(screen2);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen1") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Create Screen1:\n");
          Create_Screen1();
          lv_scr_load(screen1);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen3:\n");
          lv_obj_del(screen3);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        else{
          return;
        }

}

I get this result:

I possess a Git repository housing an example for compiling LVGL with diverse board types. Adjusting pins, resolution, and Hsync/Vsync settings to match your screen allows for successful compilation. This project acts as a straightforward starting point that you can further develop for your specific needs.

(Claro que está tudo bem @allacmc , eu tive uns imprevistos aqui e esqueci de te responder e enviar o Código que você pediu, me perdoa por isso se você ainda precisar do Código eu ainda tenho ele)

For the basic PlatformIO project structure, refer to this link.

Additionally, there’s a project utilizing ESP-IDF and LVGL, designed for an easy start. It supports Resistive Touch, with LVGL touch indev and the actual Resistive Touch separated for individual use. Find the project here. The LCD Driver can be accessed here. To add new displays, create and configure a copy of the mentioned file.

Furthermore, the repository includes additional LVGL examples within PlatformIO, available here.

I solved!

Tanks!!

The code:

/*******************************************************************************
 * LVGL Widgets
 * This is a widgets demo for LVGL - Light and Versatile Graphics Library
 * import from: https://github.com/lvgl/lv_demos.git
 *
 * This was created from the project here 
 * https://www.makerfabs.com/sunton-esp32-s3-4-3-inch-ips-with-touch.html
 * 
 * Dependent libraries:
 * LVGL: https://github.com/lvgl/lvgl.git

 * Touch libraries:
 * FT6X36: https://github.com/strange-v/FT6X36.git
 * GT911: https://github.com/TAMCTec/gt911-arduino.git
 * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
 *
 * LVGL Configuration file:
 * Copy your_arduino_path/libraries/lvgl/lv_conf_template.h
 * to your_arduino_path/libraries/lv_conf.h
 * Then find and set:
 * #define LV_COLOR_DEPTH     16
 * #define LV_TICK_CUSTOM     1
 *
 * For SPI display set color swap can be faster, parallel screen don't set!
 * #define LV_COLOR_16_SWAP   1
 *
 * Optional: Show CPU usage and FPS count
 * #define LV_USE_PERF_MONITOR 1
 ******************************************************************************/
//#include "lv_demo_widgets.h"
//#include <Arduino.h>
#include <lvgl.h>
//#include <demos/lv_demos.h>
#include <Arduino_GFX_Library.h>
#include <esp_now.h>
#include <WiFi.h>
#include <ArduinoJson.h>

#define TFT_BL 2
#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
 
unsigned long previousMillis = 0;  
const long interval = 5000;

void Create_Screen1(void);
void Create_Screen2(void);
void Create_Screen3(void);
void button_event_cb(lv_event_t *event);

uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
uint8_t  touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
static int val = 100;


Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
    40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,
    45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
    5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
    8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */,

    0 /* hsync_polarity */, 210 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,
    0 /* vsync_polarity */, 22 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
    0 /* pclk_active_neg */, 16000000 /* prefer_speed */);
    
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(800 /* width */, 480 /* height */, rgbpanel);

#include "touch.h"


void button_event_cb(lv_event_t *event);


/* Change to your screen resolution */
static uint32_t screenWidth = 800;
static uint32_t screenHeight = 480;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;

/* 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);
      #if (LV_COLOR_16_SWAP != 0)
        gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
      #else
        gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
      #endif

        lv_disp_flush_ready(disp);
}

void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){
      if (touch_has_signal())
      {
        if (touch_touched())
        {
          data->state = LV_INDEV_STATE_PR;
          /*Set the coordinates*/
          data->point.x = touch_last_x;
          data->point.y = touch_last_y;

          Serial.print( "Data x :" );
          Serial.println( touch_last_x );

          Serial.print( "Data y :" );
          Serial.println( touch_last_y );

        }
        else if (touch_released())
        {
          data->state = LV_INDEV_STATE_REL;
        }
      }
      else
      {
        data->state = LV_INDEV_STATE_REL;
      }
}

lv_obj_t *screen1;
lv_obj_t *screen2;
lv_obj_t *screen3;

void setup(){
        Serial.begin(115200);

          // Init touch device
          // Init Display
          gfx->begin();
          #ifdef TFT_BL
          pinMode(TFT_BL, OUTPUT);
          digitalWrite(TFT_BL, HIGH);
          #endif
          gfx->fillScreen(RED);
          delay(500);
          gfx->fillScreen(GREEN);
          delay(500);
          gfx->fillScreen(RED);
          delay(500);
          gfx->fillScreen(GREEN);
          delay(500);
          gfx->fillScreen(RED);
          delay(500);
          gfx->setCursor(10, 10);
          gfx->setTextColor(BLACK);
          gfx->println("Hello World!");
          delay(3000);
          lv_init();
          delay(10);
          touch_init();

          screenWidth = gfx->width();
          screenHeight = gfx->height();

          #ifdef ESP32
          disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
          #else
          disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4);
          #endif
          if (!disp_draw_buf)
          {
              printf("LVGL disp_draw_buf allocate failed!\n");
          }
          else
          {
          lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * screenHeight / 4);

          /* Initialize the display */
          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);

          /* Initialize the (dummy) input device driver */
          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);

          //******************************* MY CODE *******************************************
          //Dim the TFT backlight
          analogWrite(TFT_BL, 255 / 1.5); // values go from 0 to 255,

          //Three(3) Screen Example
          Create_Screen1();       //Create and load the first screen
          lv_scr_load(screen1);

          printf("Setup done\n");
        }
}

void loop(){
        lv_timer_handler(); /* let the GUI do its work */
        delay(5);

        unsigned long currentMillis = millis();
        if (currentMillis - previousMillis >= interval) {
          previousMillis = currentMillis;
          //espnow_senddata();
        }
}


//**********************  PROCEDURES  *************************************************
void Create_Screen1(void){
      screen1 = lv_obj_create(NULL);

      lv_obj_t * button1 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button1, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button1, 170, 80);
      lv_obj_set_pos(button1, 32, 100);
      lv_obj_t * label1 = lv_label_create(button1);
      lv_label_set_text(label1, "Test");

      lv_obj_t * button2 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button2, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button2, 170, 80);
      lv_obj_set_pos(button2, 249, 100);
      lv_obj_t * label2 = lv_label_create(button2);
      lv_label_set_text(label2, "Goto_Screen2");
}

void Create_Screen2(void){
      screen2 = lv_obj_create(NULL);

      lv_obj_t * button3 = lv_btn_create(screen2);
      lv_obj_add_event_cb(button3, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button3, 170, 80);
      lv_obj_set_pos(button3, 249, 100);
      lv_obj_t * label3 = lv_label_create(button3);
      lv_label_set_text(label3, "Goto_Screen3");
}

void Create_Screen3(void){
      screen3 = lv_obj_create(NULL);

      lv_obj_t * button4 = lv_btn_create(screen3);
      lv_obj_add_event_cb(button4, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button4, 170, 80);
      lv_obj_set_pos(button4, 249, 100);
      lv_obj_t * label4 = lv_label_create(button4);
      lv_label_set_text(label4, "Goto_Screen1");
}


void button_event_cb(lv_event_t *event){

        lv_obj_t *btn = lv_event_get_target(event);
        lv_obj_t * label = lv_obj_get_child(btn, 0);
        const char * text = lv_label_get_text(label);
        printf ("Button_Touched: %s \n", text);
        printf("[APP] Minimum memory: %s bytes\n", String(esp_get_minimum_free_heap_size()));

        if(strcmp(text, "Goto_Screen2") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen2:\n");
          Create_Screen2();
          lv_scr_load(screen2);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          //printf ("Clean Screen1:\n");
          //lv_obj_clean(screen1);
          printf ("Delete Screen1:\n");
          lv_obj_del(screen1);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen3") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen3:\n");
          Create_Screen3();
          lv_scr_load(screen3);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen2:\n");
          lv_obj_del(screen2);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen1") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Create Screen1:\n");
          Create_Screen1();
          lv_scr_load(screen1);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen3:\n");
          lv_obj_del(screen3);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        else{
          return;
        }

}

Now I need to get the capacitive touchscreen working.

1 Like

The Solved,
Display and Touch

The code:

/*******************************************************************************
 * LVGL Widgets
 * This is a widgets demo for LVGL - Light and Versatile Graphics Library
 * import from: https://github.com/lvgl/lv_demos.git
 *
 * This was created from the project here 
 * https://www.makerfabs.com/sunton-esp32-s3-4-3-inch-ips-with-touch.html
 * 
 * Dependent libraries:
 * LVGL: https://github.com/lvgl/lvgl.git

 * Touch libraries:
 * FT6X36: https://github.com/strange-v/FT6X36.git
 * GT911: https://github.com/TAMCTec/gt911-arduino.git
 * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
 *
 * LVGL Configuration file:
 * Copy your_arduino_path/libraries/lvgl/lv_conf_template.h
 * to your_arduino_path/libraries/lv_conf.h
 * Then find and set:
 * #define LV_COLOR_DEPTH     16
 * #define LV_TICK_CUSTOM     1
 *
 * For SPI display set color swap can be faster, parallel screen don't set!
 * #define LV_COLOR_16_SWAP   1
 *
 * Optional: Show CPU usage and FPS count
 * #define LV_USE_PERF_MONITOR 1
 ******************************************************************************/
//#include "lv_demo_widgets.h"
//#include <Arduino.h>
#include <lvgl.h>
//#include <demos/lv_demos.h>
#include <Arduino_GFX_Library.h>
#include <esp_now.h>
#include <WiFi.h>
#include <ArduinoJson.h>

#define TFT_BL 2
#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
 
unsigned long previousMillis = 0;  
const long interval = 5000;

void Create_Screen1(void);
void Create_Screen2(void);
void Create_Screen3(void);
void button_event_cb(lv_event_t *event);

uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
uint8_t  touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
static int val = 100;


Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
    40 /* DE */, 41 /* VSYNC */, 39 /* HSYNC */, 0 /* PCLK */,
    45 /* R0 */, 48 /* R1 */, 47 /* R2 */, 21 /* R3 */, 14 /* R4 */,
    5 /* G0 */, 6 /* G1 */, 7 /* G2 */, 15 /* G3 */, 16 /* G4 */, 4 /* G5 */,
    8 /* B0 */, 3 /* B1 */, 46 /* B2 */, 9 /* B3 */, 1 /* B4 */,

    0 /* hsync_polarity */, 210 /* hsync_front_porch */, 4 /* hsync_pulse_width */, 43 /* hsync_back_porch */,
    0 /* vsync_polarity */, 22 /* vsync_front_porch */, 4 /* vsync_pulse_width */, 12 /* vsync_back_porch */,
    0 /* pclk_active_neg */, 16000000 /* prefer_speed */);
    
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(800 /* width */, 480 /* height */, rgbpanel);

#include "touch.h"


void button_event_cb(lv_event_t *event);


/* Change to your screen resolution */
static uint32_t screenWidth = 800;
static uint32_t screenHeight = 480;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t *disp_draw_buf;
static lv_disp_drv_t disp_drv;

/* 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);
      #if (LV_COLOR_16_SWAP != 0)
        gfx->draw16bitBeRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
      #else
        gfx->draw16bitRGBBitmap(area->x1, area->y1, (uint16_t *)&color_p->full, w, h);
      #endif

        lv_disp_flush_ready(disp);
}

void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){
      if (touch_has_signal())
      {
        if (touch_touched())
        {
          data->state = LV_INDEV_STATE_PR;
          /*Set the coordinates*/
          data->point.x = touch_last_x;
          data->point.y = touch_last_y;

          Serial.print( "Data x :" );
          Serial.println( touch_last_x );

          Serial.print( "Data y :" );
          Serial.println( touch_last_y );

        }
        else if (touch_released())
        {
          data->state = LV_INDEV_STATE_REL;
        }
      }
      else
      {
        data->state = LV_INDEV_STATE_REL;
      }
}

lv_obj_t *screen1;
lv_obj_t *screen2;
lv_obj_t *screen3;

void setup(){
        Serial.begin(115200);

          // Init touch device
          // Init Display
          gfx->begin();
          #ifdef TFT_BL
          pinMode(TFT_BL, OUTPUT);
          digitalWrite(TFT_BL, HIGH);
          #endif
          gfx->fillScreen(RED);
          delay(500);
          gfx->fillScreen(GREEN);
          delay(500);
          gfx->fillScreen(RED);
          delay(500);
          gfx->fillScreen(GREEN);
          delay(500);
          gfx->fillScreen(RED);
          delay(500);
          gfx->setCursor(10, 10);
          gfx->setTextColor(BLACK);
          gfx->println("Hello World!");
          delay(3000);
          lv_init();
          delay(10);
          touch_init();

          screenWidth = gfx->width();
          screenHeight = gfx->height();

          #ifdef ESP32
          disp_draw_buf = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
          #else
          disp_draw_buf = (lv_color_t *)malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 4);
          #endif
          if (!disp_draw_buf)
          {
              printf("LVGL disp_draw_buf allocate failed!\n");
          }
          else
          {
          lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, screenWidth * screenHeight / 4);

          /* Initialize the display */
          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);

          /* Initialize the (dummy) input device driver */
          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);

          //******************************* MY CODE *******************************************
          //Dim the TFT backlight
          analogWrite(TFT_BL, 255 / 1.5); // values go from 0 to 255,

          //Three(3) Screen Example
          Create_Screen1();       //Create and load the first screen
          lv_scr_load(screen1);

          printf("Setup done\n");
        }
}

void loop(){
        lv_timer_handler(); /* let the GUI do its work */
        delay(5);

        unsigned long currentMillis = millis();
        if (currentMillis - previousMillis >= interval) {
          previousMillis = currentMillis;
          //espnow_senddata();
        }
}


//**********************  PROCEDURES  *************************************************
void Create_Screen1(void){
      screen1 = lv_obj_create(NULL);

      lv_obj_t * button1 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button1, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button1, 170, 80);
      lv_obj_set_pos(button1, 32, 100);
      lv_obj_t * label1 = lv_label_create(button1);
      lv_label_set_text(label1, "Test");

      lv_obj_t * button2 = lv_btn_create(screen1);
      lv_obj_add_event_cb(button2, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button2, 170, 80);
      lv_obj_set_pos(button2, 249, 100);
      lv_obj_t * label2 = lv_label_create(button2);
      lv_label_set_text(label2, "Goto_Screen2");
}

void Create_Screen2(void){
      screen2 = lv_obj_create(NULL);

      lv_obj_t * button3 = lv_btn_create(screen2);
      lv_obj_add_event_cb(button3, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button3, 170, 80);
      lv_obj_set_pos(button3, 249, 100);
      lv_obj_t * label3 = lv_label_create(button3);
      lv_label_set_text(label3, "Goto_Screen3");
}

void Create_Screen3(void){
      screen3 = lv_obj_create(NULL);

      lv_obj_t * button4 = lv_btn_create(screen3);
      lv_obj_add_event_cb(button4, button_event_cb, LV_EVENT_CLICKED, NULL);
      lv_obj_set_size(button4, 170, 80);
      lv_obj_set_pos(button4, 249, 100);
      lv_obj_t * label4 = lv_label_create(button4);
      lv_label_set_text(label4, "Goto_Screen1");
}


void button_event_cb(lv_event_t *event){

        lv_obj_t *btn = lv_event_get_target(event);
        lv_obj_t * label = lv_obj_get_child(btn, 0);
        const char * text = lv_label_get_text(label);
        printf ("Button_Touched: %s \n", text);
        printf("[APP] Minimum memory: %s bytes\n", String(esp_get_minimum_free_heap_size()));

        if(strcmp(text, "Goto_Screen2") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen2:\n");
          Create_Screen2();
          lv_scr_load(screen2);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          //printf ("Clean Screen1:\n");
          //lv_obj_clean(screen1);
          printf ("Delete Screen1:\n");
          lv_obj_del(screen1);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen3") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Load Screen3:\n");
          Create_Screen3();
          lv_scr_load(screen3);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen2:\n");
          lv_obj_del(screen2);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        if(strcmp(text, "Goto_Screen1") == 0) {
          printf ("Goto Screen: %s \n", text);

          printf ("Create Screen1:\n");
          Create_Screen1();
          lv_scr_load(screen1);

          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));
          printf ("Delete Screen3:\n");
          lv_obj_del(screen3);
          printf("[APP] Free memory: %s bytes\n", String(esp_get_free_heap_size()));

        }
        else{
          return;
        }

}

and touch.h

/*******************************************************************************
 * Touch libraries:
 * FT6X36: https://github.com/strange-v/FT6X36.git
 * GT911: https://github.com/TAMCTec/gt911-arduino.git
 * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
 ******************************************************************************/

/* uncomment for FT6X36 */
// #define TOUCH_FT6X36
// #define TOUCH_FT6X36_SCL 38//19
// #define TOUCH_FT6X36_SDA 37//18
// #define TOUCH_FT6X36_INT 4//39
// #define TOUCH_SWAP_XY
// #define TOUCH_MAP_X1 800
// #define TOUCH_MAP_X2 0
// #define TOUCH_MAP_Y1 0
// #define TOUCH_MAP_Y2 480

/* uncomment for GT911 */
 #define TOUCH_GT911
 #define TOUCH_GT911_SCL 20//20
 #define TOUCH_GT911_SDA 19//19
 #define TOUCH_GT911_INT 10//-1
 #define TOUCH_GT911_RST 11
 
 //38
 #define TOUCH_GT911_ROTATION ROTATION_NORMAL
 #define TOUCH_MAP_X1 800//480
 #define TOUCH_MAP_X2 0
 #define TOUCH_MAP_Y1 480//272
 #define TOUCH_MAP_Y2 0

/* uncomment for XPT2046 */
// #define TOUCH_XPT2046
// #define TOUCH_XPT2046_SCK 12
// #define TOUCH_XPT2046_MISO 13
// #define TOUCH_XPT2046_MOSI 11
// #define TOUCH_XPT2046_CS 38
// #define TOUCH_XPT2046_INT 36
// #define TOUCH_XPT2046_ROTATION 0
// #define TOUCH_MAP_X1 4000
// #define TOUCH_MAP_X2 100
// #define TOUCH_MAP_Y1 100
// #define TOUCH_MAP_Y2 4000

int touch_last_x = 0, touch_last_y = 0;

#if defined(TOUCH_FT6X36)
#include <Wire.h>
#include <FT6X36.h>
FT6X36 ts(&Wire, TOUCH_FT6X36_INT);
bool touch_touched_flag = true, touch_released_flag = true;

#elif defined(TOUCH_GT911)
#include <Wire.h>
#include <TAMC_GT911.h>
TAMC_GT911 ts = TAMC_GT911(TOUCH_GT911_SDA, TOUCH_GT911_SCL, TOUCH_GT911_INT, TOUCH_GT911_RST, max(TOUCH_MAP_X1, TOUCH_MAP_X2), max(TOUCH_MAP_Y1, TOUCH_MAP_Y2));

#elif defined(TOUCH_XPT2046)
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
XPT2046_Touchscreen ts(TOUCH_XPT2046_CS, TOUCH_XPT2046_INT);

#endif

#if defined(TOUCH_FT6X36)
void touch(TPoint p, TEvent e)
{
  if (e != TEvent::Tap && e != TEvent::DragStart && e != TEvent::DragMove && e != TEvent::DragEnd)
  {
    return;
  }
  // translation logic depends on screen rotation
#if defined(TOUCH_SWAP_XY)
  touch_last_x = map(p.y, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width());
  touch_last_y = map(p.x, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height());
#else
  touch_last_x = map(p.x, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width());
  touch_last_y = map(p.y, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height());
#endif
  switch (e)
  {
  case TEvent::Tap:
    Serial.println("Tap");
    touch_touched_flag = true;
    touch_released_flag = true;
    break;
  case TEvent::DragStart:
    Serial.println("DragStart");
    touch_touched_flag = true;
    break;
  case TEvent::DragMove:
    Serial.println("DragMove");
    touch_touched_flag = true;
    break;
  case TEvent::DragEnd:
    Serial.println("DragEnd");
    touch_released_flag = true;
    break;
  default:
    Serial.println("UNKNOWN");
    break;
  }
}
#endif

void touch_init()
{
#if defined(TOUCH_FT6X36)
  Wire.begin(TOUCH_FT6X36_SDA, TOUCH_FT6X36_SCL);
  ts.begin();
  ts.registerTouchHandler(touch);

#elif defined(TOUCH_GT911)
  Wire.begin(TOUCH_GT911_SDA, TOUCH_GT911_SCL);
  ts.begin();
  ts.setRotation(TOUCH_GT911_ROTATION);

#elif defined(TOUCH_XPT2046)
  SPI.begin(TOUCH_XPT2046_SCK, TOUCH_XPT2046_MISO, TOUCH_XPT2046_MOSI, TOUCH_XPT2046_CS);
  ts.begin();
  ts.setRotation(TOUCH_XPT2046_ROTATION);

#endif
}

bool touch_has_signal()
{
#if defined(TOUCH_FT6X36)
  ts.loop();
  return touch_touched_flag || touch_released_flag;

#elif defined(TOUCH_GT911)
  return true;

#elif defined(TOUCH_XPT2046)
  return ts.tirqTouched();

#else
  return false;
#endif
}

bool touch_touched()
{
#if defined(TOUCH_FT6X36)
  if (touch_touched_flag)
  {
    touch_touched_flag = false;
    return true;
  }
  else
  {
    return false;
  }

#elif defined(TOUCH_GT911)
  ts.read();
  if (ts.isTouched)
  {
#if defined(TOUCH_SWAP_XY)
    touch_last_x = map(ts.points[0].y, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width() - 1);
    touch_last_y = map(ts.points[0].x, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height() - 1);
#else
    touch_last_x = map(ts.points[0].x, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width() - 1);
    touch_last_y = map(ts.points[0].y, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height() - 1);
#endif
    return true;
  }
  else
  {
    return false;
  }

#elif defined(TOUCH_XPT2046)
  if (ts.touched())
  {
    TS_Point p = ts.getPoint();
#if defined(TOUCH_SWAP_XY)
    touch_last_x = map(p.y, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width() - 1);
    touch_last_y = map(p.x, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height() - 1);
#else
    touch_last_x = map(p.x, TOUCH_MAP_X1, TOUCH_MAP_X2, 0, gfx->width() - 1);
    touch_last_y = map(p.y, TOUCH_MAP_Y1, TOUCH_MAP_Y2, 0, gfx->height() - 1);
#endif
    return true;
  }
  else
  {
    return false;
  }

#else
  return false;
#endif
}

bool touch_released()
{
#if defined(TOUCH_FT6X36)
  if (touch_released_flag)
  {
    touch_released_flag = false;
    return true;
  }
  else
  {
    return false;
  }

#elif defined(TOUCH_GT911)
  return true;

#elif defined(TOUCH_XPT2046)
  return true;

#else
  return false;
#endif
}

I tried to compile your code … as it is … but i git too many errors. Please can you let me know what libraries and version I supposed to have ? to compile your code

Hi Alfonso. At the top of the .ino file the versions I used are listed:

// The values in this sketch work when using:
//  - Arduino IDE v 2.1.1
//  - arduino-esp32 core v2.0.11
//  - lvgl at version 8.3.7
//  - GFX Library for Arduino at version 1.3.7
//  - TAMC_GT911 at version 1.0.2

There are reports that this doesn’t work with LVGL v9, but I’ve not tried with that version.

Hope that’s enough to get it working for you.

1 Like

I’m going to try today … really appreciate your help

hello i am new for the ESP32 LCD 4.3 inch
link : ESP32 display-4.3 Inch HMI Display 480x272 RGB TFT LCD Touch Screen Compatible with Arduino/LVGL

i have seen the Youtube videos where then mentioned to use display driver : NV3047
but i dont know how to do it

pls help

Thanks in Advance !!!

Help for Sunton 8048S70 board

I bought the card in question, and I’m trying to load the program from your site

I followed your instructions correctly, but I can’t get this example to work.

I use Arduino IDE and as device board I use ESP32 S3 Device Module, is this correct?

I kindly ask you for your help.

Thank you

Best regards

Paul


DO I RECEIVE THESE ERRORS WHEN COMPILING ARDUINO?

In file included from c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_GFX_Library.h:4,
from C:\Users\paolo\Documents\Arduino\music_picture\music_picture.ino:1:
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:160:13: error: ‘i80_device_list’ has not been declared
160 | LIST_HEAD(i80_device_list, lcd_panel_io_i80_t)
| ^~~~~~~~~~~~~~~
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:160:3: error: ISO C++ forbids declaration of ‘LIST_HEAD’ with no type [-fpermissive]
160 | LIST_HEAD(i80_device_list, lcd_panel_io_i80_t)
| ^~~~~~~~~
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:160:48: error: expected ‘;’ at end of member declaration
160 | LIST_HEAD(i80_device_list, lcd_panel_io_i80_t)
| ^
| ;
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:161:3: error: ‘device_list’ does not name a type
161 | device_list; // Head of i80 device list
| ^~~~~~~~~~~
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:195:3: error: ISO C++ forbids declaration of ‘LIST_ENTRY’ with no type [-fpermissive]
195 | LIST_ENTRY(lcd_panel_io_i80_t)
| ^~~~~~~~~~
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:195:32: error: expected ‘;’ at end of member declaration
195 | LIST_ENTRY(lcd_panel_io_i80_t)
| ^
| ;
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_DataBus.h:196:3: error: ‘device_list_entry’ does not name a type
196 | device_list_entry; // Entry of i80 device list
| ^~~~~~~~~~~~~~~~~
In file included from c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/Arduino_GFX_Library.h:14:
c:\Users\paolo\Documents\Arduino\libraries\Arduino_GFX-master\src/databus/Arduino_ESP32RGBPanel.h:43:3: error: ‘esp_lcd_rgb_panel_frame_trans_done_cb_t’ does not name a type; did you mean ‘esp_lcd_panel_io_color_trans_done_cb_t’?
43 | esp_lcd_rgb_panel_frame_trans_done_cb_t on_frame_trans_done; // Callback, invoked after frame trans done
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| esp_lcd_panel_io_color_trans_done_cb_t

exit status 1

Compilation error: exit status 1

Hi
can you share the connection of ESP32S3-LCD?
and what driver do you need for the bare LCD setup?
thanks