2.4 Zoll TFT Touch weißer Bildschirm

Hallo zusammen,

ich habe ein 2.4'' TFT Display mit Touch von einem unbekannten Hersteller (Treiber ist ST7789V). Die Darstellung der Grafik funktioniert aber wenn ich die Touchscreen Bibliothek verwende bekomme ich Probleme. Wenn ich nach auslesen der Touch Koordinaten mit ts.getPoint() wieder auf das Display schreibe wird es weiß.

Im Beispiel wird folgender Code verwendet
#define YP A2
#define XM A3
#define YM 8
#define XP 9
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Wobei ich nirgends finde was die korrekten Pins für YP,XM,YM,XP sind.

So kann dir hier niemand helfen. Poste mal deinen bisher erstellten code hier ordebtlich in codetags. Wenn du schon nicht weißt was das für ein Display ist, wie sollen es dann andere wissen? Ein Foto wäre Hilfreich. Und welche Bibliothek an welchem Arduino/ESP benutzt du?

Wo hast Du das Display her?
Gibts nen Link dazu?
Gutes Bild von der Unterseite machen, damit man sieht was da so drauf steht.

Mir ist bewußt das es abhängig vom verwendeten Modul ist. Deshalb auch die Frage wofür YP,XM,YM und XP steht. Die 2.4'' TFT Module sind ja prinzipiell alle gleich. YP und XM sollen laut Touchscreen.h Doku an Analog Ports (die bereits belegt sind A0=RD,A1=WR,A2=RS,A3=CS und A4=RST) und YM und XP an Digitalports (D8=LCD_D0 und D9=LCD_D1)

#include "WiFiEsp.h"
#include "WiFiEspUdp.h"
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include "PeepLib.h"
#include "TouchScreen.h"

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define YP A2  
#define XM A3 
#define YM 8   
#define XP 9   

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF

const unsigned long NTP_DELAY = 60000;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
MCUFRIEND_kbv tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
Peep peep(&tft);
//Adafruit_TFTLCD tft;//(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

char timeServer[] = "pool.ntp.org";  // NTP server
unsigned int localPort = 2390;       // local port to listen for UDP packets

const int NTP_PACKET_SIZE = 48;  // NTP timestamp is in the first 48 bytes of the message
const int UDP_TIMEOUT = 2000;    // timeout in miliseconds to wait for an UDP packet to arrive

byte packetBuffer[NTP_PACKET_SIZE];  // buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiEspUDP Udp;

Label timeLabel = Label("timeLabel", 10, 70, "00:00:00");
void setup() {
  Serial3.begin(115200);
  Serial.begin(9600);
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.4\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.4\" TFT Breakout Board Pinout"));
#endif
  Serial.print("TFT size is ");
  Serial.print(tft.width());
  Serial.print("x");
  Serial.println(tft.height());

  tft.reset();
  delay(500);
  uint16_t identifier = tft.readID();

  if (identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if (identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if (identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if (identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if (identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.4\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
  }

  tft.begin(identifier);
  tft.setRotation(1);
  tft.fillScreen(peep.background);


  Button btnTime = Button("time", 10, 2, 60, 30, "Uhr");
  peep.addElement(&btnTime);
  Button btnWeather = Button("weather", 80, 2, 60, 30, "Wetter");
  peep.addElement(&btnWeather);
  Button btnNews = Button("news", 150, 2, 60, 30, "News");
  peep.addElement(&btnNews);

  peep.addElement(&timeLabel);

  WiFi.init(&Serial3);
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true)
      ;
  }
  if (WiFi.begin("SSID", "WLANPWD")) {
    Serial.println("Connected");
  } else {
    Serial.println("Connection error");
  }
  Udp.begin(localPort);
}

unsigned long ntpMillis = 0;
unsigned long currentTime = 0;
unsigned long timeTaken = 0;
unsigned long timeDisplayed = 0;
unsigned long touchTime = 0;
boolean touched=false;
void loop() {
  if (millis() - touchTime > 100) {

    touchTime=millis();
    TSPoint p = ts.getPoint();
    if (p.z > ts.pressureThreshhold) {
      Serial.print("X = ");
      Serial.print(p.x);
      Serial.print("\tY = ");
      Serial.print(p.y);
      Serial.print("\tPressure = ");
      Serial.println(p.z);
    
    }
  }

  if (ntpMillis == 0 || millis() - ntpMillis > NTP_DELAY) {
    ntpMillis = millis();
    Serial.println("Getting time");
    sendNTPpacket(timeServer);  // send an NTP packet to a time server

    // wait for a reply for UDP_TIMEOUT miliseconds
    unsigned long startMs = millis();
    while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}

    Serial.println(Udp.parsePacket());
    if (Udp.parsePacket()) {
      Serial.println("packet received");
      // We've received a packet, read the data from it into the buffer
      Udp.read(packetBuffer, NTP_PACKET_SIZE);

      // the timestamp starts at byte 40 of the received packet and is four bytes,
      // or two words, long. First, esxtract the two words:

      unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
      unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
      // combine the four bytes (two words) into a long integer
      // this is NTP time (seconds since Jan 1 1900):
      unsigned long secsSince1900 = highWord << 16 | lowWord;
      Serial.print("Seconds since Jan 1 1900 = ");
      Serial.println(secsSince1900);

      // now convert NTP time into everyday time:
      Serial.print("Unix time = ");
      // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
      const unsigned long seventyYears = 2208988800UL;
      // subtract seventy years:
      unsigned long epoch = secsSince1900 - seventyYears;
      currentTime = epoch;
      timeTaken = millis();
      // print Unix time:
      Serial.println(epoch);


      // print the hour, minute and second:
      Serial.print("The UTC time is ");       // UTC is the time at Greenwich Meridian (GMT)
      Serial.print((epoch % 86400L) / 3600);  // print the hour (86400 equals secs per day)
      Serial.print(':');
      if (((epoch % 3600) / 60) < 10) {
        // In the first 10 minutes of each hour, we'll want a leading '0'
        Serial.print('0');
      }
      Serial.print((epoch % 3600) / 60);  // print the minute (3600 equals secs per minute)
      Serial.print(':');
      if ((epoch % 60) < 10) {
        // In the first 10 seconds of each minute, we'll want a leading '0'
        Serial.print('0');
      }
      Serial.println(epoch % 60);  // print the second
    }
  }
  if (millis() - timeDisplayed > 1000 && timeTaken > 0) {
    Serial.println("Time");
    timeLabel.setText(unxToString(currentTime + 3600 * 2 + (millis() - timeTaken) / 1000));
    //timeLabel.setText("xxx");
    timeDisplayed = millis();
  }
}

String unxToString(unsigned long unxTme) {
  String sTime = "";
  sTime = String((unxTme % 86400L) / 3600) + ":";
  if (((unxTme % 3600) / 60) < 10) {
    sTime = sTime + "0";
  }
  sTime = sTime + String((unxTme % 3600) / 60) + ":";
  if ((unxTme % 60) < 10) {
    sTime = sTime + "0";
  }
  sTime = sTime + String(unxTme % 60);
  return sTime;
}

void sendNTPpacket(char *ntpSrv) {
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)

  packetBuffer[0] = 0b11100011;  // LI, Version, Mode
  packetBuffer[1] = 0;           // Stratum, or type of clock
  packetBuffer[2] = 6;           // Polling Interval
  packetBuffer[3] = 0xEC;        // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12] = 49;
  packetBuffer[13] = 0x4E;
  packetBuffer[14] = 49;
  packetBuffer[15] = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:
  Udp.beginPacket(ntpSrv, 123);  //NTP requests are to port 123

  Udp.write(packetBuffer, NTP_PACKET_SIZE);

  Udp.endPacket();
}

Na da wäre ich mir nicht so sicher.
Bist du denn sicher, dass dein TFT kompatibel zum Controller ist ?

Ich habe den Code vereinfacht um das Problem einzugrenzen.
Die Consolenausgabe in Zeile 31 wird geschrieben. Das Display wird Blau und wenn Zeile 29 auskommentiert wird auch auch grün. Mit Zeile 29 bleibt es blau obwohl der folgende Code ausgeführt wird.

#include <MCUFRIEND_kbv.h>
#include "TouchScreen.h"

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define YP A2  
#define XM A3 
#define YM 8   
#define XP 9   

#define BLUE 0x001F
#define GREEN 0x07E0

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
MCUFRIEND_kbv tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup() {
  Serial3.begin(115200);
  Serial.begin(9600);
  tft.reset();
  delay(500);
  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  tft.setRotation(1);
  tft.fillScreen(BLUE);
  ts.getPoint();
  tft.fillScreen(GREEN);
  Serial.println("After fillscreen");
}


void loop() {
 
}

Foto nicht nur Unterseite, Ober auch die gibt's auch ohne Touch :wink:

Moin @NickAmSee,

das Problem kenne ich, da ich gleiche (oder zumindest vergleichbare) Displays habe ...

Die Ursache liegt darin, dass bestimme Pins mehrfach genutzt werden, sowohl für das Display selbst wie auch für die Touchpad-Funktion. Deren Auslesepins kollidieren mit Zeichenfunktionen, wenn man dies nicht berücksichtigt.

Um das zu vermeiden, hilft es, vor und nach jedem Zugriff auf Zeichenfunktionen die folgende Routinen einzubauen (siehe void PrintChar() als Beispiel):


void Before(){
      pinMode(XM, OUTPUT);
      pinMode(YP, OUTPUT);
  }

void After(){
      pinMode(XP, OUTPUT);
     pinMode(YM, OUTPUT);
  }


void printChar(char aChar,uint16_t col){
          Before();
          tft.setTextSize(5);
          tft.setTextColor(col);
          tft.setCursor(80,80);
          tft.print(String(aChar));
          After();
}

Viel Erfolg!
ec2021

(Alternativ, aber nicht getestet kann man das vermutlich auch stattdessen invers bei der Touchscreen-Abfrage umsetzen ...)

Die Abfrage des Touchscreen läuft bei den o.a. Displays über eine Widerstandsmessung, daher braucht es für X und Y jeweils einen analogen Pin.

1 Like

Du musst auch auf unsere Fragen nicht eingehen.
Aber wir sollen deine Fragen beantworten?

Super! Danke!
Das war der Hinweis zur Lösung. Ich schreibe nach jedem getPoint explizit den Mode der Ports. Jetzt funktioniert es.

   TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);
    pinMode(YM, OUTPUT);
    pinMode(XP, OUTPUT);
    pinMode(XM, OUTPUT);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.