Browse Source

Write ESP DHT22 demo

master
Starbeamrainbowlabs 1 year ago
parent
commit
547f841124
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
5 changed files with 60 additions and 23 deletions
  1. +4
    -0
      .gitmodules
  2. +33
    -0
      dht22-esp8266/dht22-esp8266.ino
  3. +1
    -0
      dht22-esp8266/lib/esp8266-dht22
  4. +21
    -22
      dht22/dht22.ino
  5. +1
    -1
      dht22/lib/SimpleDHT

+ 4
- 0
.gitmodules 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

+ 33
- 0
dht22-esp8266/dht22-esp8266.ino 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);
}

+ 1
- 0
dht22-esp8266/lib/esp8266-dht22

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

+ 21
- 22
dht22/dht22.ino View File

@ -16,27 +16,26 @@ void setup() {
}
void loop() {
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: ");
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: ");
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("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
}
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
}

+ 1
- 1
dht22/lib/SimpleDHT

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

Loading…
Cancel
Save