Erste Erfahrungen


Erster Versuch - Temperatur und Luftfeuchtigkeit mit dem DHT22

Zugegeben - JA - es ist zu 99,9% einem Beispielprogramm entlehnt, aber selbsterklärend war es trotzdem nicht...

Anschluss DHT22: Im Beispielquelltext war kein Datenpin eingetragen (0) - böse Falle, ich hab´s dann mal mit der "14" probiert:

DHT dht1(14, DHT22);

 ... un kaum macht man´s richtig - geht es.


// Include the correct display library
// For a connection via I2C using Wire include
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "DHT.h" //https://github.com/adafruit/DHT-sensor-library
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
// or #include "SH1106.h" alis for `#include "SH1106Wire.h"`
// For a connection via I2C using brzo_i2c (must be installed) include
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
// #include "SSD1306Brzo.h"
// #include "SH1106Brzo.h"
// For a connection via SPI include
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
// #include "SSD1306Spi.h"
// #include "SH1106SPi.h"

// Initialize the OLED display using Wire library
SSD1306 display(0x3c, 5,4);

// SH1106 display(0x3c, 5,4);
// Create the DHT temperature and humidity sensor object
DHT dht1(14, DHT22);

float DHT22_t, DHT22_h;
int xpos = 0;

void setup() {
Serial.begin(115200);
Serial.println();
dht1.begin();
DHT22_t = dht1.readTemperature();
DHT22_h = dht1.readHumidity();

Serial.print("DHT22 ");
Serial.print(DHT22_t,1); Serial.print(String(char(176))+"C ");
Serial.print(DHT22_h,1); Serial.println("%RH");
Serial.println();

// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
}

void drawTempHumiDemo() {
DHT22_t = dht1.readTemperature();
DHT22_h = dht1.readHumidity();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_CENTER); // The coordinates define the center of the screen!
display.drawString(64,0,"Papas Höhle");
display.drawString(64,20,String(DHT22_t,1)+"°C");
display.drawString(64,40,String(DHT22_h,1)+"% rh");
display.setTextAlignment(TEXT_ALIGN_LEFT); // The coordinates define the center of the screen!
display.drawString(xpos%128,48,".");
}

void loop() {
display.clear(); // clear the display
display.setTextAlignment(TEXT_ALIGN_RIGHT);
drawTempHumiDemo();
display.display();
delay(1500);
xpos = xpos + 2;
}

trotzalledem funuktioniert es noch nicht besonders stabil: Aus nicht bekanntem Grund bricht der Datenerhalt vom SHT22 nach kurzer Zeit ab und kann erst durch mechanische Berührung (Kapazität?, Pill-up-Widerstand?) zum erneuten Auslesen gebracht werden

   

Sehr merkwürdig: Wenn man das SHT22-Modul vorsichtig (warning) mit Druckluft anbläst, fangen sich die Daten auch! 
... wahrscheinlich ist es sonst  zu warm und feucht in meiner Programmierhöhle (wink)