trying the SimpleDHT
This commit is contained in:
parent
569cd4e795
commit
7d09bff498
15 changed files with 1145 additions and 0 deletions
47
SimpleDHT/examples/DHT22WithRawBits/DHT22WithRawBits.ino
Normal file
47
SimpleDHT/examples/DHT22WithRawBits/DHT22WithRawBits.ino
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <SimpleDHT.h>
|
||||
|
||||
// for DHT22,
|
||||
// VCC: 5V or 3V
|
||||
// GND: GND
|
||||
// DATA: 2
|
||||
int pinDHT22 = 2;
|
||||
SimpleDHT22 dht22(pinDHT22);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// start working...
|
||||
Serial.println("=================================");
|
||||
Serial.println("Sample DHT22 with RAW bits...");
|
||||
|
||||
// read with raw sample data.
|
||||
// @remark We use read2 to get a float data, such as 10.1*C
|
||||
// if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
|
||||
float temperature = 0;
|
||||
float humidity = 0;
|
||||
byte data[40] = {0};
|
||||
int err = SimpleDHTErrSuccess;
|
||||
if ((err = dht22.read2(&temperature, &humidity, data)) != SimpleDHTErrSuccess) {
|
||||
Serial.print("Read DHT22 failed, err="); Serial.print(SimpleDHTErrCode(err));
|
||||
Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(2000);
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Sample RAW Bits: ");
|
||||
for (int i = 0; i < 40; i++) {
|
||||
Serial.print((int)data[i]);
|
||||
if (i > 0 && ((i + 1) % 4) == 0) {
|
||||
Serial.print(' ');
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
Serial.print("Sample OK: ");
|
||||
Serial.print((float)temperature); Serial.print(" *C, ");
|
||||
Serial.print((float)humidity); Serial.println(" RH%");
|
||||
|
||||
// DHT22 sampling rate is 0.5HZ.
|
||||
delay(2500);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue