Write ESP DHT22 demo

This commit is contained in:
Starbeamrainbowlabs 2019-09-30 19:30:07 +01:00
parent cc2fe93ed8
commit 547f841124
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
5 changed files with 61 additions and 24 deletions

4
.gitmodules vendored
View file

@ -4,3 +4,7 @@
[submodule "dht22/lib/SimpleDHT"]
path = dht22/lib/SimpleDHT
url = https://github.com/winlinvip/SimpleDHT
[submodule "dht22-esp8266/lib/esp8266-dht22"]
path = dht22-esp8266/lib/esp8266-dht22
url = https://github.com/Defozo/esp8266-dht22.git
branch = patch-1

View file

@ -0,0 +1,33 @@
#include "lib/esp8266-dht22/dht22.h"
#include "lib/esp8266-dht22/dht22.c"
#define DHT_TYPE DHT22
// D1
#define DHT_PIN_DATA 5
void setup() {
Serial.begin(115200);
Serial.println("DHT22 Demo");
Serial.println("==========");
Serial.println("Board: ESP8266");
Serial.print("Initialising the DHT - ");
DHT_init(DHT_PIN_DATA, DHT_TYPE, 1);
DHT_begin();
Serial.println("done");
Serial.print("Waiting to warm DHT22 up - ");
delay(2000); // Give the DHT22 time to warm up
}
void loop() {
float temp, humidity;
temp = readTemperature(false);
humidity = readHumidity();
Serial.print("Temperature: "); Serial.print(temp); Serial.println("°C");
Serial.print("Humidity: "); Serial.print(humidity); Serial.println("%");
delay(1000);
}

@ -0,0 +1 @@
Subproject commit b949ac35a553e4089f3e81dc7e4d739a02a00f78

View file

@ -16,27 +16,26 @@ void setup() {
}
void loop() {
float temp = 0, humidity = 0;
float temp = 0, humidity = 0;
int read_error = dhtA.read2(dhtA_pin, &temp, &humidity, NULL);
Serial.println("Read complete - analysing result");
if(read_error != SimpleDHTErrSuccess) {
Serial.print("Error: Failed reading from the DHT22. Code: ");
int read_error = dhtA.read2(dhtA_pin, &temp, &humidity, NULL);
Serial.println("Read complete - analysing result");
if(read_error != SimpleDHTErrSuccess) {
Serial.print("Error: Failed reading from the DHT22. Code: ");
Serial.println(read_error);
delay(2000); // We can only read every 2 seconds or so
return;
}
Serial.print("Error code: ");
Serial.println(read_error);
delay(2000); // We can only read every 2 seconds or so
return;
}
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" deg celsius");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
Serial.println("*****");
Serial.print("Error code: ");
Serial.println(read_error);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" deg celsius");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
Serial.println("*****");
delay(2000); // We can only read every 2 seconds
delay(2000); // We can only read every 2 seconds
}

@ -1 +1 @@
Subproject commit 80ac2b47c9caca07edf75f38289cfd64023872c9
Subproject commit 155f77445daa0b4757f79d984865ba68a59a7cf8