ESP 3248s035c read touch horizontal
Posted: Sun Dec 01, 2024 3:09 pm
Hi, I've just started working with the ESP32 in combination with the 3248s035c display. After a lot of effort, I managed to find the correct touch driver and was finally able to read it. However, it works fine when the screen is in portrait mode (320x480).
In the code below, everything works, and I'm able to touch any part of the screen and everything is fine.
The problem arises when I want to rotate the screen and use it in landscape mode. That's when all the magic begins...
Either I can only access half of the screen as if the rest is missing, or I get a mirror image, or I get x, y values in the range of 65200 - 65500. It would seem that I understand how to rotate and handle the resolution, but I still don't quite get it...
I tried manipulating these values, i.e., subtracting 65200 from the results, but I'm not sure if it's the correct solution, and it didn't quite work anyway.
Libs:
TAMC_GT911 1.0.2
TFT_eSPI 2.4.72
lvgl 9.2.0
In the code below, everything works, and I'm able to touch any part of the screen and everything is fine.
Code: Select all
#include <Wire.h>
#include <TAMC_GT911.h>
#include <TFT_eSPI.h>
#include <lvgl.h>
// Definicje pinów dla GT911
#define TS_SDA 33
#define TS_SCL 32
#define TS_INT 21
#define TS_RST 25
TAMC_GT911 ts(TS_SDA, TS_SCL, TS_INT, TS_RST, 0x5D, false); // 0x5D to domyślny adres I2C (możesz go zmienić)
TFT_eSPI tft = TFT_eSPI();
#define TFT_HOR_RES 320
#define TFT_VER_RES 480
#define TFT_ROTATION LV_DISPLAY_ROTATION_0
/* Bufor rysowania dla LVGL */
#define DRAW_BUF_SIZE (TFT_HOR_RES * TFT_VER_RES / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
// Zmienna przechowująca liczbę
int counter = 0;
lv_obj_t *counter_label;
void resetGT911() {
pinMode(TS_RST, OUTPUT);
pinMode(TS_INT, OUTPUT);
digitalWrite(TS_INT, LOW);
digitalWrite(TS_RST, LOW);
delay(10);
digitalWrite(TS_RST, HIGH);
delay(50);
pinMode(TS_INT, INPUT_PULLUP);
}
/* Funkcja do odczytu dotyku */
void my_touchpad_read( lv_indev_t * indev, lv_indev_data_t * data ) {
if (ts.isTouched) {
TP_Point p = ts.points[0];
data->state = LV_INDEV_STATE_PRESSED;
data->point.x = p.x;
data->point.y = p.y;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
static uint32_t my_tick(void) {
return millis();
}
// Funkcja do rysowania kropki w miejscu dotyku
void draw_dot(int x, int y) {
int radius = 5; // Promień kropki
tft.fillCircle(x, y, radius, TFT_RED); // Rysowanie kropki w miejscu dotyku
}
void setup() {
Serial.begin(115200);
String LVGL_Arduino = "Hello Arduino! ";
LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
Serial.println(LVGL_Arduino);
// Inicjalizacja dotyku
resetGT911();
ts.begin(); // Rozpoczęcie pracy z dotykiem
ts.setResolution(480, 320); // Ustaw rozdzielczość dotyku
ts.setRotation(1); // Pasuje do tft.setRotation(1)
lv_init();
lv_tick_set_cb(my_tick);
// Inicjalizacja wyświetlacza
lv_disp_t *disp;
disp = lv_tft_espi_create(TFT_HOR_RES, TFT_VER_RES, draw_buf, sizeof(draw_buf));
lv_disp_set_rotation(disp, TFT_ROTATION);
// Rejestracja wejścia dotykowego
lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);
ui_init();
Serial.println("Setup done");
}
void loop() {
lv_timer_handler(); /* Niech GUI wykona swoją pracę */
delay(5); /* Pozwól, by czas minął */
ts.read(); // Odczyt dotyku
// Sprawdzenie, czy ekran został dotknięty i narysowanie kropki
if (ts.isTouched) {
TP_Point p = ts.points[0];
draw_dot(p.x, p.y); // Rysowanie kropki w miejscu dotyku
// Debugowanie
Serial.print("Surowe X: ");
Serial.print(p.x);
Serial.print(" Surowe Y: ");
Serial.print(p.y);
Serial.println("");
}
}
void ui_init() {
lv_obj_t *screen = lv_obj_create(lv_scr_act()); // Pobierz aktywny ekran
lv_obj_set_size(screen, 320, 480);
lv_obj_center(screen);
lv_style_t style_base;
lv_style_init(&style_base);
lv_style_set_bg_color(&style_base, lv_color_hex(0xFFFFFF)); // Białe tło
lv_obj_add_style(screen, &style_base, LV_PART_MAIN);
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
// Utwórz etykietę przypisaną do 'screen'
lv_obj_t *label = lv_label_create(screen); // Tworzymy label w ramach 'screen'
lv_label_set_text(label, "Hello Arduino, I'm LVGL!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, -50); // Wyrównanie etykiety w pionie
}
The problem arises when I want to rotate the screen and use it in landscape mode. That's when all the magic begins...
Either I can only access half of the screen as if the rest is missing, or I get a mirror image, or I get x, y values in the range of 65200 - 65500. It would seem that I understand how to rotate and handle the resolution, but I still don't quite get it...
I tried manipulating these values, i.e., subtracting 65200 from the results, but I'm not sure if it's the correct solution, and it didn't quite work anyway.
Libs:
TAMC_GT911 1.0.2
TFT_eSPI 2.4.72
lvgl 9.2.0