Hallo zusammen,
ich habe ein kleines Problem bei meinem Projekt und komme nicht weiter.
Ich betreibe einen "GMT130-V1.0 1.3" 240x240 TFT IPS Color Display ST7789, SPI" an einem ESP32 WROOM 32.
Der Display ist wie folgt angeschlossen:
GND -> G
VCC -> 3.3
SCK -> D18
SDA -> D23
RES -> RX2
DC - > TX2
BLK -> D22
Der Code ist von einem Projekt, was ich online gefunden habe, auf die neue Hardware angepasst.
Hier der aktuelle Code:
// === ESP32 + 240x240 TFT Layout + BMP280 ===
#include <tft_setup.h>
#include <WiFi.h>
#include <Wire.h>
#include <AHT20.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#include "time.h"
#include <Preferences.h>
#include "esp_sleep.h"
#include "TFT_eSPI.h"
#include <Adafruit_BMP280.h>
TFT_eSPI tft = TFT_eSPI();
Adafruit_BMP280 bmp; // BMP280 Sensor
#define TOUCH_PIN 33
Preferences prefs;
// WiFi
const char* ssid = "*****";
const char* password = "*****";
// NTP
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 1 * 3600;
const int daylightOffset_sec = 0;
// AHT20
#define SDA_PIN 4
#define SCL_PIN 27
AHT20 aht20;
// TFT Colors
#define CYBER_BG ST77XX_BLACK
#define CYBER_GREEN 0x07E0
#define CYBER_ACCENT 0x07FF
#define CYBER_LIGHT 0xFD20
#define CYBER_MIX 0x05FF
#define CYBER_BLUE 0x07FF
#define CYBER_PINK 0xF81F
#define CYBER_RED 0x001F
int prevSecond = -1;
String prevSecStr = "--";
String prevHourStr = "--";
String prevMinStr = "--";
bool pulse = false;
// ================================ WiFi + Time ================================
void connectWiFiAndSyncTime() {
tft.fillScreen(CYBER_BG);
tft.setTextColor(CYBER_LIGHT);
tft.setTextSize(2);
tft.setCursor(20, 60);
tft.print("Connecting...");
WiFi.begin(ssid, password);
uint8_t retry = 0;
while (WiFi.status() != WL_CONNECTED && retry < 20) {
delay(300);
tft.print(".");
retry++;
}
tft.fillScreen(CYBER_BG);
if (WiFi.status() == WL_CONNECTED) {
tft.setCursor(20, 80);
tft.print("");
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
} else {
tft.setTextColor(ST77XX_RED);
tft.setCursor(20, 80);
tft.print("WiFi FAILED!");
}
delay(1000);
}
// ================================ Time String ================================
String getTimeStr(char type) {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) return "--";
char buf[8];
if (type == 'H') strftime(buf, sizeof(buf), "%H", &timeinfo);
if (type == 'M') strftime(buf, sizeof(buf), "%M", &timeinfo);
if (type == 'S') strftime(buf, sizeof(buf), "%S", &timeinfo);
return String(buf);
}
// ================================ BORDER ================================
void drawRedBorder() {
tft.drawRect(0, 0, 240, 240, ST77XX_RED); // 240x240 Rand
}
// ================================ Clock ================================
void drawClock(String hourStr, String minStr, String secStr) {
if (hourStr != prevHourStr || minStr != prevMinStr || secStr != prevSecStr ) {
prevHourStr = hourStr;
prevMinStr = minStr;
prevSecStr = secStr;
// Bereich der Uhr säubern
tft.fillRect(10, 10, 220, 60, CYBER_BG);
tft.setTextColor(CYBER_LIGHT);
tft.setTextSize(4);
tft.setCursor(10, 15);
tft.print(hourStr);
tft.print(":");
tft.print(minStr);
tft.print(":");
tft.print(secStr);
drawRedBorder();
}
}
// ================================ ENV DISPLAY ================================
void drawEnv(float temp, float hum, float pres) {
int y = 150;
int h = 89; // Gesamthöhe des Feldes
tft.fillRect(10, y, 220, h, CYBER_BG);
tft.setTextSize(2);
tft.setTextColor(CYBER_GREEN);
tft.setCursor(10, y);
tft.printf("TEMPERATURE: %.1fC", temp);
tft.setTextColor(CYBER_PINK);
tft.setCursor(10, y + 30);
tft.printf("HUMIDITY: %.0f%%", hum);
tft.setTextColor(CYBER_BLUE);
tft.setCursor(10, y + 60);
tft.printf("PRESSURE: %.1fhPa", pres);
drawRedBorder();
}
// ================================ Sleep ================================
void goToSleep() {
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(2);
tft.setCursor(40, 120);
tft.print("Sleeping...");
pinMode(TOUCH_PIN, INPUT_PULLDOWN);
esp_sleep_enable_ext1_wakeup(1ULL << TOUCH_PIN, ESP_EXT1_WAKEUP_ANY_HIGH);
delay(200);
esp_deep_sleep_start();
}
// ================================ Setup ================================
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
prefs.begin("state", false);
bool isSleeping = prefs.getBool("sleeping", false);
tft.init();
tft.setRotation(0);
tft.fillScreen(CYBER_BG);
drawRedBorder();
if (isSleeping) {
prefs.putBool("sleeping", false);
tft.setCursor(20, 40);
tft.setTextColor(CYBER_LIGHT);
tft.setTextSize(2);
tft.print("Woke up!");
delay(800);
}
connectWiFiAndSyncTime();
if (!aht20.begin()) {
tft.fillScreen(CYBER_BG);
tft.setCursor(20, 60);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(2);
tft.print("AHT20 ERROR!");
delay(1500);
return;
}
if (!bmp.begin(0x77)) { // BMP280 I2C Adresse
tft.fillScreen(CYBER_BG);
tft.setCursor(20, 100);
tft.setTextColor(ST77XX_RED);
tft.setTextSize(2);
tft.print("BMP280 ERROR!");
delay(1500);
}
drawClock(getTimeStr('H'), getTimeStr('M'), getTimeStr('S'));
drawEnv(aht20.getTemperature(), aht20.getHumidity(), bmp.readPressure() / 100.0);
}
// ================================ Loop ================================
void loop() {
if (WiFi.status() != WL_CONNECTED) WiFi.reconnect();
struct tm timeinfo;
if (getLocalTime(&timeinfo)) {
int sec = timeinfo.tm_sec;
if (sec != prevSecond) {
prevSecond = sec;
drawClock(getTimeStr('H'), getTimeStr('M'), getTimeStr('S'));
drawEnv(aht20.getTemperature(), aht20.getHumidity(), bmp.readPressure() / 100.0);
}
}
if (digitalRead(TOUCH_PIN) == HIGH) {
delay(60);
if (digitalRead(TOUCH_PIN) == HIGH) {
while (digitalRead(TOUCH_PIN) == HIGH) delay(10);
goToSleep();
}
}
}
Und hier der Code der tft_setup.h:
// 1.3" TFT Display (GMT130 V.10),
// no CS pin
// 240x240, ST7789
// tft_setup.h
#define ST7789_DRIVER
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
#define TFT_RGB_ORDER TFT_BGR
#define TFT_CS -1
#define TFT_RST 16
#define TFT_DC 17
#define TFT_MOSI 23 // SDA // HW MOSI
#define TFT_SCLK 18 // SCL // HW SCL
#define TFT_MISO 19 // not used
#define TFT_BL 22 // LED back-light
#define TFT_BACKLIGHT_ON HIGH
#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
#define SMOOTH_FONT
#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
#define TFT_INVERSION_OFF
Mein Problem ist folgendes:
Der Display hat oben diese schwarzen Linien, die sich bis über den Rand ziehen. Anfangs dachte ich, dass sich dort irgendwele Bereiche überlagern, aber es scheint nicht so zu sein.
Nachdem ich jetzt viele Stunden alles mögliche ausprobiert habe, vermute ich fast, dass der Display defekt ist. Oder könnt ihr im Code etwas finden, dass das Problem auslöst?
Außerdem Flackert der angezeigte Text in den Bereichen, die über tft.fillRect definiert sind. Entferne ich diese tft.fillRect, "übermalen" sich die Zahlen, die sich verändern selbst.
Hier noch ein kurzes Video:
Ich hoffe, ich habe es einigermaßen gut beschrieben. Mein Wissen zum Thema ist leider sehr begrenzt. ![]()
Viele Grüße
Christian



