DHT11/DHT22 - Mess­da­ten und Zeit auf TFT anzeigen

TFT 128×160

// ESP8266
// #include "ESP8266WiFi.h"

// ESP32
// #include "WiFi.h"

#include "time.h"
#include "Adafruit_ST7735.h"
#include "U8g2_for_Adafruit_GFX.h"
#include "DHT.h"

// freier digitaler Pin für DHT
int SENSOR_DHT = 11;

// Sensortyp festlegen
// DHT22
#define SensorTyp DHT22

// DHT11
// #define SensorTyp DHT11

// Sensor einen Namen zuweisen
DHT dht(SENSOR_DHT, SensorTyp);

// Wemos D1 Mini
// #define TFT_CS       D8
// #define TFT_RST      D1
// #define TFT_DC       D2

// XIAO
// #define TFT_CS       D7
// #define TFT_RST      D1
// #define TFT_DC       D2

// Arduino Nano ESP 32
// #define TFT_CS       10
// #define TFT_RST       9
// #define TFT_DC        8

// ESP32-C6
// #define TFT_CS       18
// #define TFT_RST       3                                          
// #define TFT_DC        2

// ESP32-WROOM
// #define TFT_CS        5
// #define TFT_RST       4 
// #define TFT_DC        2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

char Router[] = "Router_SSID";
char Passwort[] = "xxxxxxxx";

// NTP-Server aus dem Pool
#define Zeitserver "de.pool.ntp.org"

/*
  Liste der Zeitzonen
  https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
  Zeitzone CET = Central European Time -1 -> 1 Stunde zurück
  CEST = Central European Summer Time von
  M3 = März, 5.0 = Sonntag 5. Woche, 02 = 2 Uhr
  bis M10 = Oktober, 5.0 = Sonntag 5. Woche 03 = 3 Uhr
*/
#define Zeitzone "CET-1CEST,M3.5.0/02,M10.5.0/03"

// time_t enthält die Anzahl der Sekunden seit dem 1.1.1970 0 Uhr
time_t aktuelleZeit;

/* 
  Struktur tm
  tm_hour -> Stunde: 0 bis 23
  tm_min -> Minuten: 0 bis 59
  tm_sec -> Sekunden 0 bis 59
  tm_mday -> Tag 1 bis 31
  tm_mon -> Monat: 0 (Januar) bis 11 (Dezember)
  tm_year -> Jahre seit 1900
  tm_yday -> vergangene Tage seit 1. Januar des Jahres
  tm_isdst -> Wert > 0 = Sommerzeit (dst = daylight saving time)
*/
tm Zeit;
WiFiServer Server(80);
WiFiClient Client;

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// Objekt u8g2Schriften
U8G2_FOR_ADAFRUIT_GFX u8g2Schriften;

// Bitmaps
const unsigned char Kalender [] PROGMEM = {
	// 'Kalender_30x35, 30x35px
	0x7f, 0xff, 0xff, 0xf8, 0xff, 0xfc, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 
	0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 
	0xff, 0xff, 0xff, 0xfc, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x8e, 0x00, 0x01, 0xc4, 
	0x8e, 0x00, 0x01, 0xc4, 0x8e, 0x00, 0x01, 0xc4, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 
	0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 
	0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 
	0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 
	0x8e, 0x00, 0x01, 0xc4, 0x8e, 0x00, 0x01, 0xc4, 0x8e, 0x00, 0x01, 0xc4, 0x80, 0x00, 0x00, 0x04, 
	0x80, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x04, 0xff, 0xff, 0xff, 0xfc
};

const unsigned char Uhr [] PROGMEM = {
	// 'Uhr_30x30, 30x30px
	0x00, 0x1f, 0xe0, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x01, 0xf0, 0x3e, 0x00, 0x07, 0x80, 0x07, 0x80, 
	0x0f, 0x03, 0x03, 0xc0, 0x1c, 0x60, 0x18, 0xe0, 0x18, 0x00, 0x00, 0x60, 0x38, 0x01, 0x00, 0x70, 
	0x30, 0x01, 0x00, 0x30, 0x63, 0x01, 0x01, 0x98, 0x60, 0x01, 0x00, 0x18, 0xe0, 0x01, 0x00, 0x1c, 
	0xc0, 0x01, 0x00, 0x0c, 0xc0, 0x01, 0x00, 0x0c, 0xcc, 0x01, 0x00, 0xcc, 0xc0, 0x02, 0x00, 0x0c, 
	0xc0, 0x0c, 0x00, 0x0c, 0xc0, 0x30, 0x00, 0x0c, 0xe0, 0xc0, 0x00, 0x1c, 0x66, 0x00, 0x01, 0x98, 
	0x60, 0x00, 0x00, 0x18, 0x70, 0x00, 0x00, 0x38, 0x38, 0x00, 0x00, 0x70, 0x18, 0x60, 0x10, 0x60, 
	0x1c, 0x00, 0x00, 0xe0, 0x0f, 0x03, 0x03, 0xc0, 0x07, 0x80, 0x07, 0x80, 0x01, 0xf0, 0x3e, 0x00, 
	0x00, 0x7f, 0xfc, 0x00, 0x00, 0x1f, 0xe0, 0x00
};

const unsigned char Thermometer [] PROGMEM = {
	// 'Thermometer_19x40, 19x40px
	0x01, 0xe0, 0x00, 0x03, 0xf8, 0x00, 0x06, 0x0c, 0x00, 0x04, 0x04, 0x00, 0x08, 0x04, 0x00, 0x08, 
	0x04, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x18, 0x04, 
	0x00, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x18, 0x04, 0x00, 0x08, 0x04, 0x00, 
	0x00, 0xe4, 0x00, 0x00, 0xe4, 0x00, 0x38, 0xe4, 0x00, 0x00, 0xe4, 0x00, 0x00, 0xe4, 0x00, 0x00, 
	0xe4, 0x00, 0x00, 0xe4, 0x00, 0x18, 0xe7, 0x00, 0x30, 0xe3, 0x80, 0x21, 0xe1, 0x80, 0x63, 0xf8, 
	0xc0, 0x47, 0xf8, 0xc0, 0x47, 0xfc, 0x40, 0xc7, 0xfc, 0x60, 0xc7, 0xfc, 0x60, 0xc7, 0xfc, 0x60, 
	0x47, 0xfc, 0x40, 0x63, 0xf8, 0xc0, 0x61, 0xf0, 0xc0, 0x30, 0x01, 0x80, 0x10, 0x03, 0x00, 0x0e, 
	0x0e, 0x00, 0x07, 0xfc, 0x00, 0x00, 0xe0, 0x00
};

const unsigned char Regen [] PROGMEM = {
	// 'Regen_43x35, 43x35px
	0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x22, 0x22, 0x21, 0x00, 0x00, 0x00, 0x66, 0x22, 0x23, 0x20, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 
	0x03, 0x11, 0x11, 0x19, 0x10, 0x00, 0x02, 0x00, 0x01, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x08, 0x08, 0x88, 0x80, 0x31, 0x11, 
	0x19, 0x18, 0x89, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x88, 0x8c, 0x88, 0xc4, 0xcc, 0xc0, 0x08, 0x88, 0x88, 0x04, 
	0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 
	0x00, 0x00, 0x80, 0x00, 0x23, 0x33, 0x11, 0x11, 0x99, 0x00, 0x20, 0x20, 0x11, 0x10, 0x11, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x88, 0x88, 0x88, 
	0x88, 0x00, 0x01, 0x08, 0x98, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x44, 0x46, 0x00, 0x00, 
	0x00, 0x04, 0x44, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00
};

void setup()
{
    // Zeitzone: Parameter für die zu ermittelnde Zeit
  configTzTime(Zeitzone, Zeitserver);

  Serial.begin(9600);

  // auf serielle Verbindung warten
  while (!Serial);
  delay(1000);

  // WiFi starten
  WiFi.begin(Router, Passwort);

  Serial.println("------------------------");

  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(200);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Verbunden mit ");
  Serial.println(Router);
  Serial.print("IP über DHCP: ");
  Serial.println(WiFi.localIP());

  // Schriften von u8g2 tft zuordnen
  u8g2Schriften.begin(tft); 

  // Zufallsgenerator starten
  randomSeed(analogRead(A0));
  Serial.begin(9600);
  delay(500);
  Serial.println("Bildschirm: " + String(tft.height()) + " x " + String(tft.width()));

  // TFT starten
  tft.initR(INITR_BLACKTAB);

  // Rotation anpassen
  tft.setRotation(2);

  // Bitmaps anzeigen
  tft.fillScreen(ST77XX_BLACK);
  tft.drawBitmap(1, 1, Kalender, 30, 35, ST77XX_WHITE);  
  tft.drawBitmap(1, 40, Uhr, 30, 30, ST77XX_WHITE);
  tft.drawBitmap(10, 75, Thermometer, 19, 40, ST77XX_WHITE);
  tft.drawBitmap(1, 121, Regen, 43, 35, ST77XX_WHITE);

  // Sensor starten
  dht.begin();
}

void loop()
{
  // aktuelle Zeit holen
  time(&aktuelleZeit);

  // localtime_r -> Zeit in die lokale Zeitzone setzen
  localtime_r(&aktuelleZeit, &Zeit);

  // Temperatur lesen
  String Temperatur = String(dht.readTemperature());

  // replace -> . durch , ersetzen
  Temperatur.replace(".", ",");

  // Luftfeuchtigkeit lesen
  String Luftfeuchtigkeit = String(dht.readHumidity());

  // replace -> . durch , ersetzen
  Luftfeuchtigkeit.replace(".", ",");

  // nur den Bereich der Daten schwärzen 
  tft.fillRect(45, 1, tft.width(), tft.height(), ST77XX_BLACK);

  u8g2Schriften.setForegroundColor(ST77XX_WHITE);   
  u8g2Schriften.setBackgroundColor(ST77XX_BLACK);
  u8g2Schriften.setFont(u8g2_font_helvB12_te); 
  u8g2Schriften.setCursor(48, 20); 
    
    // Tag: führende 0 ergänzen
  if (Zeit.tm_mday < 10) 
  {
    u8g2Schriften.print("0");
  }

  u8g2Schriften.print(Zeit.tm_mday);
  u8g2Schriften.print(".");

  // Monat: führende 0 ergänzen
  if (Zeit.tm_mon < 9) 
  {
    u8g2Schriften.print("0");
  }
  u8g2Schriften.print(Zeit.tm_mon + 1);
  u8g2Schriften.print(".");

  // Anzahl Jahre seit 1900
  u8g2Schriften.print(Zeit.tm_year + 1900);
  u8g2Schriften.print(" ");

  u8g2Schriften.setCursor(48, 60);

  // Stunde: wenn Stunde < 10 -> 0 davor setzen
  if (Zeit.tm_hour < 10) u8g2Schriften.print("0");
  u8g2Schriften.print(Zeit.tm_hour);
  u8g2Schriften.print(":");

  // Minuten
  if (Zeit.tm_min < 10) u8g2Schriften.print("0");
  u8g2Schriften.print(Zeit.tm_min);

  // Messdaten anzeigen
  u8g2Schriften.setCursor(48, 100);
  u8g2Schriften.print(Temperatur + " °C");
  u8g2Schriften.setCursor(48, 140);
  u8g2Schriften.print(Luftfeuchtigkeit + " %");

  delay(10000);
}

TFT 240×320

// ESP8266
// #include "ESP8266WiFi.h"

// ESP32
// #include "WiFi.h"

#include "Adafruit_ILI9341.h"
#include "time.h"
#include "U8g2_for_Adafruit_GFX.h"
#include "DHT.h"

// freier digitaler Pin für DHT
int SENSOR_DHT = D3;

// Sensortyp festlegen
// DHT22
#define SensorTyp DHT22

// DHT11
// #define SensorTyp DHT11

// Sensor einen Namen zuweisen
DHT dht(SENSOR_DHT, SensorTyp);

// Wemos D1 Mini
// #define TFT_CS       D8
// #define TFT_RST      D1
// #define TFT_DC       D2

// XIAO
// #define TFT_CS       D7
// #define TFT_RST      D1
// #define TFT_DC       D2

// Arduino Nano ESP 32
// #define TFT_CS       10
// #define TFT_RST       9
// #define TFT_DC        8

// ESP32-C6
// #define TFT_CS       18
// #define TFT_RST       3                                          
// #define TFT_DC        2

// ESP32-WROOM
// #define TFT_CS        5
// #define TFT_RST       4 
// #define TFT_DC        2

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

char Router[] = "Router_SSID";
char Passwort[] = "xxxxxxxx";

// NTP-Server aus dem Pool
#define Zeitserver "de.pool.ntp.org"

/*
  Liste der Zeitzonen
  https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv
  Zeitzone CET = Central European Time -1 -> 1 Stunde zurück
  CEST = Central European Summer Time von
  M3 = März, 5.0 = Sonntag 5. Woche, 02 = 2 Uhr
  bis M10 = Oktober, 5.0 = Sonntag 5. Woche 03 = 3 Uhr
*/
#define Zeitzone "CET-1CEST,M3.5.0/02,M10.5.0/03"

// time_t enthält die Anzahl der Sekunden seit dem 1.1.1970 0 Uhr
time_t aktuelleZeit;

/* 
  Struktur tm
  tm_hour -> Stunde: 0 bis 23
  tm_min -> Minuten: 0 bis 59
  tm_sec -> Sekunden 0 bis 59
  tm_mday -> Tag 1 bis 31
  tm_mon -> Monat: 0 (Januar) bis 11 (Dezember)
  tm_year -> Jahre seit 1900
  tm_yday -> vergangene Tage seit 1. Januar des Jahres
  tm_isdst -> Wert > 0 = Sommerzeit (dst = daylight saving time)
*/
tm Zeit;
WiFiServer Server(80);
WiFiClient Client;

// Objekt u8g2Schriften
U8G2_FOR_ADAFRUIT_GFX u8g2Schriften;

// Bitmaps
const unsigned char Uhr [] PROGMEM = {
	// 'Uhr, 50x50px
	0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x03, 
	0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x01, 
	0xfe, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x1f, 0xc0, 
	0x00, 0x01, 0xf8, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x03, 0xf0, 0x00, 0xc0, 0x03, 0xf0, 0x00, 0x07, 
	0xc0, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x07, 0x80, 0xc0, 0x00, 0x40, 0x78, 0x00, 0x0f, 0x80, 0x00, 
	0x00, 0x00, 0x7c, 0x00, 0x1f, 0x00, 0x00, 0x80, 0x00, 0x3e, 0x00, 0x1e, 0x00, 0x00, 0xc0, 0x00, 
	0x1e, 0x00, 0x3e, 0x00, 0x00, 0xc0, 0x00, 0x1f, 0x00, 0x3c, 0x00, 0x00, 0xc0, 0x00, 0x0f, 0x00, 
	0x38, 0x30, 0x00, 0xc0, 0x01, 0x07, 0x00, 0x78, 0x00, 0x00, 0xc0, 0x00, 0x07, 0x80, 0x78, 0x00, 
	0x00, 0xc0, 0x00, 0x07, 0x80, 0x70, 0x00, 0x00, 0xc0, 0x00, 0x03, 0x80, 0xf0, 0x00, 0x00, 0xc0, 
	0x00, 0x03, 0xc0, 0xf0, 0x00, 0x00, 0xc0, 0x00, 0x03, 0xc0, 0xf0, 0x00, 0x00, 0xc0, 0x00, 0x03, 
	0xc0, 0xf0, 0x00, 0x00, 0xc0, 0x00, 0x03, 0xc0, 0xf1, 0x80, 0x00, 0xc0, 0x00, 0x63, 0xc0, 0xf1, 
	0x80, 0x01, 0x80, 0x00, 0x63, 0xc0, 0xf0, 0x00, 0x07, 0x00, 0x00, 0x03, 0xc0, 0xf0, 0x00, 0x1c, 
	0x00, 0x00, 0x03, 0xc0, 0xf0, 0x00, 0x78, 0x00, 0x00, 0x03, 0xc0, 0xf0, 0x00, 0xe0, 0x00, 0x00, 
	0x03, 0xc0, 0x70, 0x03, 0x80, 0x00, 0x00, 0x03, 0x80, 0x78, 0x07, 0x00, 0x00, 0x00, 0x07, 0x80, 
	0x78, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x78, 0x20, 0x00, 0x00, 0x01, 0x07, 0x80, 0x3c, 0x00, 
	0x00, 0x00, 0x00, 0x0f, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1e, 0x00, 0x00, 0x00, 
	0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x7c, 
	0x00, 0x07, 0x80, 0x80, 0x00, 0xc0, 0x78, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x03, 
	0xf0, 0x00, 0xc0, 0x03, 0xf0, 0x00, 0x01, 0xf8, 0x00, 0xc0, 0x07, 0xe0, 0x00, 0x00, 0xfe, 0x00, 
	0x00, 0x1f, 0xc0, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x1f, 0xe0, 0x01, 0xfe, 
	0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xf0, 0x00, 0x00, 
	0x00, 0x00, 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00
};

const unsigned char Thermometer [] PROGMEM = {
	// 'Thermometer, 34x70px
	0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x00, 
	0x7c, 0x0f, 0x00, 0x00, 0x00, 0x70, 0x07, 0x80, 0x00, 0x00, 0xe0, 0x03, 0xc0, 0x00, 0x00, 0xe0, 
	0x01, 0xc0, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x01, 0xc0, 0x01, 
	0xc0, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x0f, 0xc0, 0x01, 0xc0, 0x00, 0x0f, 0xc0, 0x01, 0xc0, 
	0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 
	0x00, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 0x0f, 0xc0, 0x01, 0xc0, 0x00, 0x0f, 
	0xc0, 0x01, 0xc0, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 
	0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x00, 0x0f, 0xc0, 0x01, 
	0xc0, 0x00, 0x0f, 0xc0, 0x01, 0xc0, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0xc3, 0xe1, 0xc0, 
	0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x0f, 0xc3, 0xf1, 0xc0, 0x00, 
	0x0f, 0xc3, 0xf1, 0xc0, 0x00, 0x0f, 0xc3, 0xf1, 0xc0, 0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x00, 
	0xc3, 0xf1, 0xc0, 0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x00, 0xc3, 
	0xf1, 0xc0, 0x00, 0x00, 0xc3, 0xf1, 0xc0, 0x00, 0x03, 0xc3, 0xf1, 0xf0, 0x00, 0x07, 0xc3, 0xf0, 
	0xf8, 0x00, 0x0f, 0x03, 0xf0, 0x7c, 0x00, 0x0e, 0x03, 0xe0, 0x3c, 0x00, 0x1c, 0x07, 0xf0, 0x1e, 
	0x00, 0x3c, 0x1f, 0xfc, 0x0f, 0x00, 0x38, 0x3f, 0xfe, 0x0f, 0x00, 0x78, 0x7f, 0xff, 0x07, 0x80, 
	0x70, 0x7f, 0xff, 0x87, 0x80, 0x70, 0x7f, 0xff, 0x83, 0x80, 0xf0, 0xff, 0xff, 0x83, 0xc0, 0xf0, 
	0xff, 0xff, 0xc3, 0xc0, 0xf0, 0xff, 0xff, 0xc3, 0xc0, 0xf0, 0xff, 0xff, 0xc3, 0xc0, 0xf0, 0xff, 
	0xff, 0xc3, 0xc0, 0xf0, 0xff, 0xff, 0x83, 0xc0, 0x70, 0x7f, 0xff, 0x83, 0x80, 0x70, 0x7f, 0xff, 
	0x87, 0x80, 0x78, 0x3f, 0xff, 0x07, 0x80, 0x38, 0x3f, 0xfe, 0x0f, 0x00, 0x3c, 0x0f, 0xfc, 0x0f, 
	0x00, 0x1e, 0x03, 0xe0, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x3e, 0x00, 0x0f, 0x00, 0x00, 0x7c, 0x00, 
	0x07, 0xe0, 0x01, 0xf8, 0x00, 0x03, 0xf8, 0x07, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xc0, 0x00, 0x00, 
	0x7f, 0xff, 0x80, 0x00, 0x00, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00
};

const unsigned char Regen [] PROGMEM = {
	// 'Regen, 60x49px
	0x00, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x02, 0x08, 0x21, 0x04, 0x10, 0x00, 0x00, 0x00, 0x06, 0x18, 0x63, 0x0c, 0x30, 0x80, 0x00, 
	0x00, 0x06, 0x10, 0x63, 0x0c, 0x31, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x20, 0x84, 0x10, 0x41, 0x08, 0x20, 0x00, 0x00, 0x61, 0x8c, 0x30, 0xc3, 0x18, 0x60, 0x00, 
	0x08, 0xc1, 0x8c, 0x30, 0xc3, 0x18, 0x61, 0x00, 0x00, 0x41, 0x04, 0x20, 0x82, 0x08, 0x40, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x30, 0x86, 0x18, 0x43, 0x04, 0x30, 0x80, 
	0x18, 0x71, 0x86, 0x18, 0xc3, 0x0c, 0x31, 0x80, 0x18, 0x21, 0x84, 0x10, 0xc3, 0x0c, 0x21, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x18, 0x21, 0x04, 0x10, 0x42, 0x18, 0x40, 
	0x86, 0x18, 0x63, 0x0c, 0x30, 0xc6, 0x18, 0xc0, 0x86, 0x10, 0x63, 0x0c, 0x30, 0xc6, 0x18, 0xc0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x18, 0x21, 0x04, 0x10, 0xc2, 0x0c, 0x21, 0x00, 0x30, 0x63, 0x0c, 0x31, 0xc6, 0x0c, 0x63, 0x00, 
	0x30, 0x63, 0x0c, 0x31, 0x86, 0x18, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x06, 0x10, 0x43, 0x08, 0x20, 0x86, 0x10, 0x00, 0x06, 0x30, 0xc3, 0x18, 0x61, 0x86, 0x30, 0x00, 
	0x04, 0x30, 0xc2, 0x18, 0x61, 0x8c, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x80, 0x00, 0x00, 0x0c, 0x30, 0xc6, 0x18, 0x61, 0x00, 0x00, 
	0x00, 0x00, 0x61, 0xc6, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x86, 0x10, 0x60, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const unsigned char Kalender [] PROGMEM = {
	// 'Kalender, 51x60px
	0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xe0, 0xff, 0xff, 
	0xff, 0x1f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 
	0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0xf0, 
	0x00, 0x00, 0x01, 0xe0, 0x60, 0x81, 0xf8, 0x00, 0x00, 0x03, 0xf0, 0x60, 0x81, 0xf8, 0x00, 0x00, 
	0x03, 0xf0, 0x60, 0x81, 0xf8, 0x00, 0x00, 0x03, 0xf0, 0x60, 0x81, 0xf8, 0x00, 0x00, 0x03, 0xf0, 
	0x60, 0x80, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 
	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 
	0x80, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x60, 0x81, 0xf8, 0x00, 0x00, 0x03, 0xf0, 0x60, 0x81, 0xf8, 
	0x00, 0x00, 0x03, 0xf0, 0x60, 0xc1, 0xf8, 0x00, 0x00, 0x03, 0xf0, 0x60, 0xc1, 0xf8, 0x00, 0x00, 
	0x03, 0xf0, 0x60, 0xc0, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc0, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0xc0
};

void setup()
{
    // Zeitzone: Parameter für die zu ermittelnde Zeit
  configTzTime(Zeitzone, Zeitserver);

  Serial.begin(9600);

  // auf serielle Verbindung warten
  while (!Serial);
  delay(1000);

  // WiFi starten
  WiFi.begin(Router, Passwort);

  Serial.println("------------------------");

  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(200);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Verbunden mit ");
  Serial.println(Router);
  Serial.print("IP über DHCP: ");
  Serial.println(WiFi.localIP());

  // Schriften von u8g2 tft zuordnen
  u8g2Schriften.begin(tft); 

  // Zufallsgenerator starten
  randomSeed(analogRead(A0));
  Serial.begin(9600);
  delay(500);
  Serial.println("Bildschirm: " + String(tft.height()) + " x " + String(tft.width()));

  // TFT starten
  tft.begin();

  // Rotation anpassen
  tft.setRotation(2);

  // Bitmaps anzeigen
  tft.fillScreen(ILI9341_BLACK);
  tft.drawBitmap(1, 1, Kalender, 51, 60, ILI9341_WHITE);  
  tft.drawBitmap(1, 90, Uhr, 50, 50, ILI9341_WHITE);
  tft.drawBitmap(10, 170, Thermometer, 34, 70, ILI9341_WHITE);
  tft.drawBitmap(1, 270, Regen, 60, 49, ILI9341_WHITE);

  // Sensor starten
  dht.begin();
}

void loop()
{
  // aktuelle Zeit holen
  time(&aktuelleZeit);

  // localtime_r -> Zeit in die lokale Zeitzone setzen
  localtime_r(&aktuelleZeit, &Zeit);

  // Temperatur lesen
  String Temperatur = String(dht.readTemperature());

  // replace -> . durch , ersetzen
  Temperatur.replace(".", ",");

  // Luftfeuchtigkeit lesen
  String Luftfeuchtigkeit = String(dht.readHumidity());

  // replace -> . durch , ersetzen
  Luftfeuchtigkeit.replace(".", ",");

  // nur den Bereich der Daten schwärzen 
  tft.fillRect(60, 1, tft.width(), tft.height(), ILI9341_BLACK);

  u8g2Schriften.setForegroundColor(ILI9341_WHITE);   
  u8g2Schriften.setBackgroundColor(ILI9341_BLACK);
  u8g2Schriften.setFont(u8g2_font_helvB24_tf); 
  u8g2Schriften.setCursor(70, 45); 
    
    // Tag: führende 0 ergänzen
  if (Zeit.tm_mday < 10) 
  {
    u8g2Schriften.print("0");
  }

  u8g2Schriften.print(Zeit.tm_mday);
  u8g2Schriften.print(".");

  // Monat: führende 0 ergänzen
  if (Zeit.tm_mon < 9) 
  {
    u8g2Schriften.print("0");
  }
  u8g2Schriften.print(Zeit.tm_mon + 1);
  u8g2Schriften.print(".");

  // Anzahl Jahre seit 1900
  u8g2Schriften.print(Zeit.tm_year + 1900);
  u8g2Schriften.print(" ");

  u8g2Schriften.setCursor(70, 120);

    // Stunde: wenn Stunde < 10 -> 0 davor setzen
    if (Zeit.tm_hour < 10) u8g2Schriften.print("0");
    u8g2Schriften.print(Zeit.tm_hour);
    u8g2Schriften.print(":");

    // Minuten
    if (Zeit.tm_min < 10) u8g2Schriften.print("0");
    u8g2Schriften.print(Zeit.tm_min);

     // Messdaten anzeigen
    u8g2Schriften.setCursor(70, 210);
    u8g2Schriften.print(Temperatur + " °C");
    u8g2Schriften.setCursor(70, 300);
    u8g2Schriften.print(Luftfeuchtigkeit + " %");

    delay(10000);
}

Letzte Aktualisierung: Feb. 6, 2025 @ 11:39