OLED 1.77”
Die bisherigen Anzeigen basierten auf sehr günstigen OLEDs. Nun habe ich ein 1.77” TFT-Monitor für ca. 2.50€ erhalten. Das Einbinden unter ESP32 war etwas trickreich - gelang aber letztlich mit einer besonderen Bibliothek (s.u.). Die Uhr aktualisiert sich alle 5 Minuten über einen Zeitserver.
Hardware:
- NodeMCU-ESP-WROOM-32
- 1.77 Zoll TFT (IC ST7735S SPI) 160×128 (RGB)
Verdrahtung:
TFT ESP32 ------------------------ 1 GND <----> GND 2 VCC <----> 3.3V 3 SCK <----> GPIO18 4 SDA <----> GPIO23 5 RES <----> GPIO04 6 RS <----> GPIO02 7 CS <----> GPIO15 8 LEDA <----> 3.3V
Software: https://github.com/Bodmer/TFT_eSPI.git
Dieses zip-Paket wie gewohnt in der IDE installieren. Folgende Anpassungen sind nötig:
//Datei: User_Setup.h #define ST7735_DRIVER #define TFT_WIDTH 128 #define TFT_HEIGHT 160 #define ST7735_GREENTAB2 // für korrekte Farbwiedergabe #define TFT_CS 5 // Chip select control pin #define TFT_DC 2 // Data Command control pin #define TFT_RST 4 // Reset pin (could connect to RST pin) // Font je nach Bedarf aktivieren #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters #define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-. #define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts #define SMOOTH_FONT #define SPI_FREQUENCY 27000000
Alle anderen Option sind bei mir auskommentiert.
Programm:
Neben der Steuerung des Displays muss ein Time-Server via NTPClient angesprochen werden. Dazu wird eine WLAN-Verbindung genutzt. Der NTPClient-Zugriff via WiFi wurde schon in einem anderen Artikel beschrieben.
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip #include <SPI.h> // NTPClient-staff TFT_eSPI tft = TFT_eSPI(); void setup() { // staff for WiFi and NTPClient // Setup the LCD tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); showUhr(); showDatum(getDatum()); showTemperatur(getTemperatur()); } void showDatum(String s) { tft.setTextSize(1); tft.setTextColor(TFT_GREEN, TFT_BLACK); tft.drawCentreString(s, TFT_W / 2, 60, 4); } void showTemperatur() { tft.setTextSize(1); tft.setTextColor(TFT_CYAN, TFT_BLACK); tft.drawCentreString("T = 19.8 C", TFT_W / 2, 90, 4); } void showSecs(int ss) { tft.setTextSize(1); tft.setTextColor(TFT_CYAN, TFT_BLACK); byte xpos = 70; byte ypos = 45; if (ss<10) xpos+= tft.drawChar('0',xpos,ypos,1); tft.drawNumber(ss,xpos,ypos,1); } void showUhr() { byte xpos = 6; byte ypos = 5; tft.setTextColor(0x39C4, TFT_BLACK); tft.drawString("88:88",xpos,ypos,7); //ueberschreiben = löschen tft.setTextColor(uhrFG, TFT_BLACK); if (hh<10) xpos+= tft.drawChar('0',xpos,ypos,7); xpos+= tft.drawNumber(hh,xpos,ypos,7); xcolon=xpos; xpos+= tft.drawChar(':',xpos,ypos,7); if (mm<10) xpos+= tft.drawChar('0',xpos,ypos,7); tft.drawNumber(mm,xpos,ypos,7); } void loop() { timeClient.update(); // -------------------------------------------- // Datumsbestimmung // -------------------------------------------- wtag = wochentageKurz[timeClient.getDay()]; // wochentage: Langform zeit = timeClient.getFormattedTime(); datum = wtag + "-" + timeClient.getDate() + "." + timeClient.getMonth(); // -------------------------------------------- // wenn Zeit zwischen t1 und t0 >= 300s = 5 min, // dann Temperatur neu einlesen und anzeigen // -------------------------------------------- t1 = timeClient.getEpochTime(); // sec sincs 1.1.1970 if ((t1-t0) >= 300) { showTemperatur(getTemperatur()); showDatum(getDatum()); t0 = t1; } // -------------------------------------------- // Anzeige // -------------------------------------------- hh = timeClient.getHours(); mm = timeClient.getMinutes(); ss = timeClient.getSeconds(); showUhr(timeClient.getHours(), timeClient.getMinutes(), ); showSecs(timeClient.getSeconds() ); // blinkSekunden(); delay(DELAY); }
Quelldatei: tft_uhr_v1.ino (Version noch unbereinigt - aber funktionsfähig)
TODO:
Anpassung der Subroutinen, Integration eines Temperatursensors, Anzeige von Wetterprognosen