/*
* Temperatur und Feuchigkeitsanzeige auf OLED 128 x 64 I2C Display
* und DHT22 / 21 / 11 Temperatur / Feuchtikeit Sensor
*
*/
#include "U8glib.h" // Library I2C - OLED 128 x 64 Display
#include <Wire.h> // Wire Library
#include "DHT.h" // Library DHT11 / 22 / 21
#define DHTPIN 8 // digital pin sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
int x;
float f;
char bufferY [20];
char bufferX [21];
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
DHT dht(DHTPIN, DHTTYPE);
void setup(void) {
u8g.begin(); // I2C OLED Display initialiseren
dht.begin(); // DHT11 / 22 / 21 initialiseren
}
void loop(void) {
delay(1000);
int h = dht.readHumidity(); // Variable Feuchtikeuît DHT 22 setzen
// Read temperature as Celsius (the default)
int t = dht.readTemperature(); // Variable Temperatur DHT 22 setzen (t)
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
u8g.drawStr(22,40,"NO CONNECTION");
return;
}
// Anzeigeroutine - Modus auf OLED - Display
u8g.firstPage();
do {
u8g.setFont(u8g_font_gdr14r);
u8g.drawStr(0,14,"Termometer");
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 22, 60, bufferY);
sprintf(bufferY, "Temp.: %d", t);
u8g.drawStr( 22, 40, bufferX);
sprintf(bufferX, "Feut.: %d", h);
u8g.setPrintPos(95, 60);
u8g.print("C");
u8g.setPrintPos(95, 40);
u8g.print("%");
} while ( u8g.nextPage() );
}