Closed CoTECH1987 closed 2 weeks ago
Hi! I have installed the latest version of the library https://github.com/moononournation/Arduino_GFX I also adapted the display initialization file according to my own https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-5 Here is the file
#if defined(ESP32_4827S043) #define GFX_DEV_DEVICE ESP32_4827S043 #define GFX_BL 2 #define RGB_PANEL // Uncomment for ST7262 IPS LCD 1024x600 Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel( 5 /* DE */, 3 /* VSYNC */, 46 /* HSYNC */, 7 /* PCLK */, 1 /* R0 */, 2 /* R1 */, 42 /* R2 */, 41 /* R3 */, 40 /* R4 */, 39 /* G0 */, 0 /* G1 */, 45 /* G2 */, 48 /* G3 */, 47 /* G4 */, 21 /* G5 */, 14 /* B0 */, 38 /* B1 */, 18 /* B2 */, 17 /* B3 */, 10 /* B4 */, 0 /* hsync_polarity */, 44 /* hsync_front_porch */, 88 /* hsync_pulse_width */, 188 /* hsync_back_porch */, 0 /* vsync_polarity */, 3 /* vsync_front_porch */, 6 /* vsync_pulse_width */, 16 /* vsync_back_porch */, 1 /* pclk_active_neg */, 40000000 /* prefer_speed */); Arduino_RGB_Display *gfx = new Arduino_RGB_Display( 1024 /* width */, 600 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */); #endif
I'm trying the touch button test. Here's a Sketch:
#include <Arduino_GFX_Library.h> #include "Arduino_GFX_dev_device.h" #include <Wire.h> #include <TAMC_GT911.h> #ifndef GFX_DEV_DEVICE #endif #ifdef ESP32 #undef F #define F(s) (s) #endif #define BTN_HEIGHT 100 #define BTN_WIDTH 150 struct btn_t { int x; int y; char text[10]; bool enable; } btns[] = { {0,100,"BTN01",false}, {160,100,"BTN02",false}, {320,100,"BTN03",false}, {480,100,"BTN04",false}, {640,100,"BTN05",false} }; int btn_n = 5; TAMC_GT911 tp(8, 9, 4, -1, 1024, 600); int32_t w, h, n, n1, cx, cy, cx1, cy1, cn, cn1; uint8_t tsa, tsb, tsc, ds; void setup() { Serial.begin(115200); #ifdef GFX_EXTRA_PRE_INIT GFX_EXTRA_PRE_INIT(); #endif tp.begin(); tp.setRotation(ROTATION_INVERTED); gfx->begin(); w = gfx->width(); h = gfx->height(); n = min(w, h); n1 = n - 1; cx = w / 2; cy = h / 2; cx1 = cx - 1; cy1 = cy - 1; cn = min(cx1, cy1); cn1 = cn - 1; tsa = ((w <= 176) || (h <= 160)) ? 1 : (((w <= 240) || (h <= 240)) ? 2 : 3); // text size A tsb = ((w <= 272) || (h <= 220)) ? 1 : 2; // text size B tsc = ((w <= 220) || (h <= 220)) ? 1 : 2; // text size C ds = (w <= 160) ? 9 : ((w <= 280) ? 10 : 12); #ifdef GFX_BL pinMode(GFX_BL, OUTPUT); digitalWrite(GFX_BL, HIGH); #endif gfx->fillScreen(BLACK); for( int i=0; i<btn_n; i++)displayBTN(i); } uint32_t ms0 = 0; void loop() { uint32_t ms = millis(); tp.read(); if( ms0 == 0 || ms - ms0 > 500 ){ if (tp.isTouched){ ms0 = ms; int x = tp.points[0].x; int y = tp.points[0].y; int n_new = -1; int n_old = -1; for( int i=0; i<btn_n; i++){ if( btns[i].enable )n_old = i; if( x > btns[i].x && x < btns[i].x+BTN_WIDTH && y > btns[i].y && y < btns[i].y+BTN_HEIGHT )n_new = i; } Serial.printf("x=%d y=%d old=%d new=%d ms=%ld\n",x,y,n_old,n_new,ms0); if( n_new >= 0 && n_old == n_new ){ btns[n_new].enable = !btns[n_new].enable; displayBTN(n_new); } else if( n_new >=0 ){ btns[n_new].enable = true; displayBTN(n_new); if( n_old >= 0 ){ btns[n_old].enable = false; displayBTN(n_old); } } } } } void displayBTN(int i){ if( i<0 || i>= btn_n )return; struct btn_t btn = btns[i]; uint16_t color_back = BLACK, color_border = LIGHTGREY, color_text = DARKGREEN; if( btn.enable ){ color_back = DARKGREEN; color_border = LIGHTGREY; color_text = WHITE; } gfx->fillRect(btn.x,btn.y,BTN_WIDTH,BTN_HEIGHT,color_back); gfx->drawRect(btn.x,btn.y,BTN_WIDTH,BTN_HEIGHT,color_border); gfx->drawRect(btn.x+1,btn.y+1,BTN_WIDTH-2,BTN_HEIGHT-2,color_border); gfx->setCursor(btn.x+20, btn.y+30); gfx->setTextSize(4); gfx->setTextColor(color_text); gfx->print(btn.text); }
It's working! The sensor is responding. The image is being displayed!
https://github.com/user-attachments/assets/9d46aef7-a01c-419e-aa57-8156e3fb185a
But when you click on any area of the screen, interference appears on the display. As I understand it, this happens at the moment of updating the screen! Is it possible to adjust something further to avoid pixel displacement?
solved (set / prefer_speed /); =16000000
Hi! I have installed the latest version of the library https://github.com/moononournation/Arduino_GFX I also adapted the display initialization file according to my own https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-5 Here is the file
define ESP32_4827S043
I'm trying the touch button test. Here's a Sketch:
It's working! The sensor is responding. The image is being displayed!
https://github.com/user-attachments/assets/9d46aef7-a01c-419e-aa57-8156e3fb185a
But when you click on any area of the screen, interference appears on the display. As I understand it, this happens at the moment of updating the screen! Is it possible to adjust something further to avoid pixel displacement?