-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdht22_test.ino
103 lines (86 loc) · 2.19 KB
/
dht22_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// FILE: dht22_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: DHT library test sketch for DHT22 && Arduino
// URL: https://github.com/RobTillaart/DHTstable
#include "DHTStable.h"
DHTStable DHT;
#define DHT22_PIN 5
struct
{
uint32_t total;
uint32_t ok;
uint32_t crc_error;
uint32_t time_out;
uint32_t connect;
uint32_t ack_l;
uint32_t ack_h;
uint32_t unknown;
} counter = { 0,0,0,0,0,0,0,0};
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("LIBRARY VERSION: ");
Serial.println(DHTSTABLE_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
}
void loop()
{
// READ DATA
Serial.print("DHT22, \t");
uint32_t start = micros();
int chk = DHT.read22(DHT22_PIN);
uint32_t stop = micros();
counter.total++;
switch (chk)
{
case DHTLIB_OK:
counter.ok++;
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
counter.crc_error++;
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
counter.time_out++;
Serial.print("Time out error,\t");
break;
default:
counter.unknown++;
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.getHumidity(), 1);
Serial.print(",\t");
Serial.print(DHT.getTemperature(), 1);
Serial.print(",\t");
Serial.print(stop - start);
Serial.println();
// DISPLAY COUNTERS
if (counter.total % 20 == 0)
{
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
Serial.print(counter.total);
Serial.print("\t");
Serial.print(counter.ok);
Serial.print("\t");
Serial.print(counter.crc_error);
Serial.print("\t");
Serial.print(counter.time_out);
Serial.print("\t");
Serial.print(counter.connect);
Serial.print("\t");
Serial.print(counter.ack_l);
Serial.print("\t");
Serial.print(counter.ack_h);
Serial.print("\t");
Serial.print(counter.unknown);
Serial.println("\n");
}
delay(2000);
}
// -- END OF FILE --