/************************************************************************** * * ESP8266 NodeMCU (ESP-12E)mit ST7735S TFT Display (128x160 Pixel) * und DHT22 Luftdruck-, Temperatursensor. * *************************************************************************/ #include // include Adafruit graphics library #include // include Adafruit ST7735 TFT library #include // include Adafruit DHT library code //LED Setup int LEDrot = D0; // -> GPIO-16 int LEDblau = D3; // -> GPIO-0 // ST7735 TFT module connections #define TFT_RST -1 // TFT RST pin is connected to NodeMCU pin RST #define TFT_CS D8 // TFT CS pin is connected to NodeMCU pin D8 #define TFT_DC D4 // TFT DC pin is connected to NodeMCU pin D4 // initialize ST7735 TFT library with hardware SPI module // SCK (CLK) ---> NodeMCU pin D5 (GPIO14) // MOSI(DIN) ---> NodeMCU pin D7 (GPIO13) Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); #define DHTPIN D6 // DHT11 data pin is connected to NodeMCU pin D6 (GPIO5) #define DHTTYPE DHT22 // DHT11 sensor is used DHT dht22(DHTPIN, DHTTYPE); // configure DHT library void setup(void) { //LED initialisieren -> LED aus pinMode(LEDrot, OUTPUT); // Pin D0 ist ein Ausgang. pinMode(LEDblau,OUTPUT); // Pin D3 ist ein Ausgang. digitalWrite(LEDrot, LOW); // Schalte die LED an Pin D0 aus. D0 ist beim Start des ESP8266 auf HIGH. digitalWrite(LEDblau, LOW); // Schalte die LED an Pin D3 aus. tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab tft.fillScreen(ST7735_BLACK); // fill screen with black color tft.drawFastHLine(0, 50, tft.width(), ST7735_BLUE); // draw horizontal blue line at position (0, 50) tft.drawFastHLine(0, 102, tft.width(), ST7735_BLUE); // draw horizontal blue line at position (0, 102) tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // set text color to white with black background tft.setTextSize(1); // text size = 1 tft.setCursor(4, 16); // move cursor to position (4, 16) pixel tft.print("ESP8266 + ST7735 TFT"); tft.setCursor(22, 33); // move cursor to position (22, 33) pixel tft.print("+ DHT22 SENSOR"); tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set text color to green with black background tft.setCursor(25, 61); // move cursor to position (25, 61) pixel tft.print("TEMPERATURE ="); tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // set text color to yellow with black background tft.setCursor(34, 113); // move cursor to position (34, 113) pixel tft.print("HUMIDITY ="); tft.setTextSize(2); // text size = 2 tft.drawCircle(83, 80, 2, ST7735_RED); // print degree symbol ( ° ) tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red with black background tft.setCursor(89, 78); tft.print("C"); // initialize DHT11 sensor dht22.begin(); } // main loop void loop() { // read humidity in rH% int Humi = dht22.readHumidity() * 10; // read temperature in degree Celsius int Temp = dht22.readTemperature() * 10; // print temperature (in °C) tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red with black background tft.setCursor(17, 78); if(Temp < 0) // if temperature < 0 tft.printf("-%02u.%1u", (abs(Temp)/10)%100, abs(Temp) % 10); else // temperature >= 0 tft.printf(" %02u.%1u", (Temp/10)%100, Temp % 10); // print humidity (in %) tft.setTextColor(ST7735_CYAN, ST7735_BLACK); // set text color to cyan with black background tft.setCursor(29, 130); tft.printf("%02u.%1u %%", (Humi/10)%100, Humi % 10); delay(1000); // wait a second } // end of code.