Problem with touch GT911 I2C - esp32s3 ESP-IDF 5.4 version ide QSPI

hello i get this error

I (871) GT911_TOUCH: I2C probe addr 0x5D: NOT FOUND
W (875) GT911_TOUCH: GT911 not found at 0x5D, trying alternative address 0x14
I (882) GT911_TOUCH: I2C probe addr 0x14: NOT FOUND
E (887) GT911_TOUCH: GT911 not found at any known address
E (892) GT911_TOUCH: Failed to initialize GT911 for LVGL
I (897) main_task: Returned from app_main()

i tried 0x5D and 0x14 with INT RST 1 and 0 but still getting this error

sharing the code down below

#pragma once

#include “driver/gpio.h”
#include “driver/i2c_master.h”
#include “esp_lcd_touch.h”
#include “esp_lcd_touch_gt911.h”
#include “lvgl.h”

#ifdef __cplusplus
extern “C” {
#endif

// Touch GT911 I2C configuration
#define GT911_I2C_NUM I2C_NUM_0
#define GT911_I2C_SPEED_HZ 400000

// Touch GT911 GPIO pins
#define GT911_PIN_SCL GPIO_NUM_4
#define GT911_PIN_SDA GPIO_NUM_8
#define GT911_PIN_INT GPIO_NUM_3
#define GT911_PIN_RST GPIO_NUM_9

// GT911 I2C address (0x5D when INT is high during reset, 0x14 when INT is low)
#define TOUCH_MODULE_ADDR 0x5D
//#define TOUCH_MODULE_ADDR 0x1A

esp_err_t touch_gt911_init(esp_lcd_touch_handle_t *out_handle);

lv_indev_t *touch_gt911_init_lvgl(void);

void touch_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data);

void check_touch_events(esp_lcd_touch_handle_t touch_handle);

#ifdef __cplusplus
}
#endif

this is file c

#include “touch_gt911.h”
#include “esp_lcd_touch_gt911.h”
#include “esp_lcd_panel_io.h”
#include “esp_lcd_types.h”
#include “lvgl.h”
#include “esp_lcd_touch.h”
#include “esp_log.h”
#include “driver/i2c_master.h”
#include “driver/gpio.h”
#include “freertos/FreeRTOS.h”
#include “freertos/task.h”
#include “esp_check.h”

static const char *TAG = “GT911_TOUCH”;

#define RAW_WIDTH 320
#define RAW_HEIGHT 480

static esp_lcd_touch_handle_t s_tp = NULL;

void touch_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) {
esp_lcd_touch_handle_t touch_handle = (esp_lcd_touch_handle_t)drv->user_data;
uint16_t x, y, strength;
uint8_t point_num = 0;

if (touch_handle == NULL) {
    data->state = LV_INDEV_STATE_RELEASED;
    return;
}

esp_lcd_touch_read_data(touch_handle);
bool touched = esp_lcd_touch_get_coordinates(touch_handle, &x, &y, &strength, &point_num, 1);

if (touched && point_num > 0) {
    data->point.x = x;
    data->point.y = y;
    data->state = LV_INDEV_STATE_PRESSED;
    ESP_LOGD(TAG, "Touch: x=%u y=%u strength=%u", x, y, strength);
} else {
    data->state = LV_INDEV_STATE_RELEASED;
}

}

static esp_err_t gt911_reset_sequence(void) {
ESP_LOGI(TAG, “Starting GT911 reset sequence”);

// Configure INT pin as output, set HIGH to select address 0x5D
gpio_config_t int_cfg = {
    .mode = GPIO_MODE_OUTPUT,
    .pin_bit_mask = 1ULL << GT911_PIN_INT,
    .pull_up_en = GPIO_PULLUP_DISABLE,
    .pull_down_en = GPIO_PULLDOWN_DISABLE,
    .intr_type = GPIO_INTR_DISABLE
};
ESP_RETURN_ON_ERROR(gpio_config(&int_cfg), TAG, "INT pin config failed");

// Configure RST pin as output
gpio_config_t rst_cfg = {
    .mode = GPIO_MODE_OUTPUT,
    .pin_bit_mask = 1ULL << GT911_PIN_RST,
    .pull_up_en = GPIO_PULLUP_DISABLE,
    .pull_down_en = GPIO_PULLDOWN_DISABLE,
    .intr_type = GPIO_INTR_DISABLE
};
ESP_RETURN_ON_ERROR(gpio_config(&rst_cfg), TAG, "RST pin config failed");

// Reset sequence to select I2C address 0x5D
ESP_LOGI(TAG, "INT=HIGH → Selecting I2C address 0x5D");
gpio_set_level(GT911_PIN_INT, 1);  // Set INT high for addr 0x5D
vTaskDelay(pdMS_TO_TICKS(2));

gpio_set_level(GT911_PIN_RST, 0);  // Pull RST low
vTaskDelay(pdMS_TO_TICKS(20));     // Hold for >10ms

gpio_set_level(GT911_PIN_RST, 1);  // Release RST
vTaskDelay(pdMS_TO_TICKS(100));    // Wait for boot >50ms
ESP_LOGI(TAG, "RST toggled: LOW→HIGH → Waiting for GT911 boot (100ms)");

// Configure INT as input with pullup
int_cfg.mode = GPIO_MODE_INPUT;
int_cfg.pull_up_en = GPIO_PULLUP_ENABLE;
ESP_RETURN_ON_ERROR(gpio_config(&int_cfg), TAG, "INT input config failed");

ESP_LOGI(TAG, "GT911 reset sequence completed");
return ESP_OK;

}

static esp_err_t i2c_scan_device(i2c_master_bus_handle_t bus_handle, uint8_t addr) {
i2c_master_dev_handle_t dev_handle;
const i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = addr,
.scl_speed_hz = GT911_I2C_SPEED_HZ,
};

esp_err_t ret = i2c_master_probe(bus_handle, addr, 100); 
ESP_LOGI(TAG, "I2C probe addr 0x%02X: %s", addr, (ret == ESP_OK) ? "FOUND" : "NOT FOUND");
return ret;

}

esp_err_t touch_gt911_init(esp_lcd_touch_handle_t *out_handle) {
ESP_LOGI(TAG, “Initializing GT911 touch controller”);

// Step 1: Reset GT911 to select correct I2C address
ESP_RETURN_ON_ERROR(gt911_reset_sequence(), TAG, "Reset sequence failed");

// Step 2: Create I2C master bus
const i2c_master_bus_config_t bus_cfg = {
    .i2c_port = GT911_I2C_NUM,
    .sda_io_num = GT911_PIN_SDA,
    .scl_io_num = GT911_PIN_SCL,
    .clk_source = I2C_CLK_SRC_DEFAULT,
    .glitch_ignore_cnt = 7,
    .flags.enable_internal_pullup = true,
};

i2c_master_bus_handle_t bus_handle;
ESP_RETURN_ON_ERROR(i2c_new_master_bus(&bus_cfg, &bus_handle), TAG, "I2C master bus creation failed");

// Step 3: Scan for GT911 device
ESP_LOGI(TAG, "Scanning I2C bus for GT911...");
esp_err_t probe_result = i2c_scan_device(bus_handle, TOUCH_MODULE_ADDR);
if (probe_result != ESP_OK) {
    ESP_LOGW(TAG, "GT911 not found at 0x%02X, trying alternative address 0x14", TOUCH_MODULE_ADDR);
    probe_result = i2c_scan_device(bus_handle, 0x14);
    if (probe_result != ESP_OK) {
        ESP_LOGE(TAG, "GT911 not found at any known address");
        i2c_del_master_bus(bus_handle);
        return ESP_ERR_NOT_FOUND;
    }
}

// Step 4: Create panel IO handle
const esp_lcd_panel_io_i2c_config_t io_config = {
    .dev_addr = TOUCH_MODULE_ADDR,
    .lcd_cmd_bits = 8,
    .lcd_param_bits = 8,
    .flags = {
        .disable_control_phase = 1,
    }
};

esp_lcd_panel_io_handle_t io_handle;
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle), 
                    TAG, "Panel IO creation failed");

// Step 5: Configure GT911 touch controller
const esp_lcd_touch_config_t tp_cfg = {
    .x_max = RAW_WIDTH,
    .y_max = RAW_HEIGHT,
    .rst_gpio_num = GT911_PIN_RST,
    .int_gpio_num = GT911_PIN_INT,
    .levels = {
        .reset = 1,        // Active low reset
        .interrupt = 1,    // Active low interrupt
    },
    .flags = {
        .swap_xy = 0,
        .mirror_x = 0,
        .mirror_y = 0,
    },
    .interrupt_callback = NULL,
    .user_data = NULL,
};


ESP_LOGI(TAG, "Initializing GT911: x_max=%d, y_max=%d, RST=%d, INT=%d",
     tp_cfg.x_max, tp_cfg.y_max, tp_cfg.rst_gpio_num, tp_cfg.int_gpio_num);

// Step 6: Initialize GT911 driver
esp_err_t ret = esp_lcd_touch_new_i2c_gt911(io_handle, &tp_cfg, out_handle);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "GT911 initialization failed: %s", esp_err_to_name(ret));
    esp_lcd_panel_io_del(io_handle);
    i2c_del_master_bus(bus_handle);
    return ret;
}

s_tp = *out_handle;
ESP_LOGI(TAG, "GT911 touch controller initialized successfully");
return ESP_OK;

}

lv_indev_t *touch_gt911_init_lvgl(void) {
ESP_LOGI(TAG, “Registering GT911 with LVGL”);

esp_lcd_touch_handle_t tp;
esp_err_t ret = touch_gt911_init(&tp);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "Failed to initialize GT911 for LVGL");
    return NULL;
}

static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touch_read_cb;
indev_drv.user_data = tp;

lv_indev_t *indev = lv_indev_drv_register(&indev_drv);
if (indev == NULL) {
    ESP_LOGE(TAG, "Failed to register LVGL input device");
    return NULL;
}

ESP_LOGI(TAG, "GT911 registered with LVGL successfully");
return indev;

}

void check_touch_events(esp_lcd_touch_handle_t touch_handle) {
if (touch_handle == NULL) {
ESP_LOGW(TAG, “Touch handle is NULL”);
return;
}

esp_lcd_touch_read_data(touch_handle);
uint16_t x[1], y[1], strength[1];
uint8_t cnt = 0;
bool touched = esp_lcd_touch_get_coordinates(touch_handle, x, y, strength, &cnt, 1);

if (touched && cnt > 0) {
    ESP_LOGI(TAG, "Touch detected: x=%d y=%d strength=%d", x[0], y[0], strength[0]);
}

}

Hi,

these drivers are created and maintained by Espressif, so they can comment more.

thank !