Skip to content

Commit 9d290fe

Browse files
committed
+ added support for all errors
1 parent 0a3df91 commit 9d290fe

File tree

7 files changed

+151
-57
lines changed

7 files changed

+151
-57
lines changed

libraries/DHTlib/examples/dht11_test/dht11_test.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: dht11_test.ino
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.00
5+
// VERSION: 0.1.01
66
// PURPOSE: DHT library test sketch for DHT11 && Arduino
77
// URL:
88
//
@@ -41,6 +41,15 @@ void loop()
4141
case DHTLIB_ERROR_TIMEOUT:
4242
Serial.print("Time out error,\t");
4343
break;
44+
case DHTLIB_ERROR_CONNECT:
45+
Serial.print("Connect error,\t");
46+
break;
47+
case DHTLIB_ERROR_ACK_L:
48+
Serial.print("Ack Low error,\t");
49+
break;
50+
case DHTLIB_ERROR_ACK_H:
51+
Serial.print("Ack High error,\t");
52+
break;
4453
default:
4554
Serial.print("Unknown error,\t");
4655
break;

libraries/DHTlib/examples/dht21_test/dht21_test.ino

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: dht21_test.ino
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.00
5+
// VERSION: 0.1.01
66
// PURPOSE: DHT library test sketch for DHT21 && Arduino
77
// URL:
88
//
@@ -17,40 +17,49 @@ dht DHT;
1717

1818
void setup()
1919
{
20-
Serial.begin(115200);
21-
Serial.println("DHT TEST PROGRAM ");
22-
Serial.print("LIBRARY VERSION: ");
23-
Serial.println(DHT_LIB_VERSION);
24-
Serial.println();
25-
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
20+
Serial.begin(115200);
21+
Serial.println("DHT TEST PROGRAM ");
22+
Serial.print("LIBRARY VERSION: ");
23+
Serial.println(DHT_LIB_VERSION);
24+
Serial.println();
25+
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
2626
}
2727

2828
void loop()
2929
{
30-
// READ DATA
31-
Serial.print("DHT21, \t");
32-
int chk = DHT.read21(DHT21_PIN);
33-
switch (chk)
34-
{
35-
case DHTLIB_OK:
36-
Serial.print("OK,\t");
37-
break;
38-
case DHTLIB_ERROR_CHECKSUM:
39-
Serial.print("Checksum error,\t");
40-
break;
41-
case DHTLIB_ERROR_TIMEOUT:
42-
Serial.print("Time out error,\t");
43-
break;
44-
default:
45-
Serial.print("Unknown error,\t");
46-
break;
47-
}
48-
// DISPLAY DATA
49-
Serial.print(DHT.humidity, 1);
50-
Serial.print(",\t");
51-
Serial.println(DHT.temperature, 1);
30+
// READ DATA
31+
Serial.print("DHT21, \t");
32+
int chk = DHT.read21(DHT21_PIN);
33+
switch (chk)
34+
{
35+
case DHTLIB_OK:
36+
Serial.print("OK,\t");
37+
break;
38+
case DHTLIB_ERROR_CHECKSUM:
39+
Serial.print("Checksum error,\t");
40+
break;
41+
case DHTLIB_ERROR_CONNECT:
42+
Serial.print("Time out error,\t");
43+
break;
44+
case DHTLIB_ERROR_CONNECT:
45+
Serial.print("Connect error,\t");
46+
break;
47+
case DHTLIB_ERROR_ACK_L:
48+
Serial.print("Ack Low error,\t");
49+
break;
50+
case DHTLIB_ERROR_ACK_H:
51+
Serial.print("Ack High error,\t");
52+
break;
53+
default:
54+
Serial.print("Unknown error,\t");
55+
break;
56+
}
57+
// DISPLAY DATA
58+
Serial.print(DHT.humidity, 1);
59+
Serial.print(",\t");
60+
Serial.println(DHT.temperature, 1);
5261

53-
delay(2000);
62+
delay(2000);
5463
}
5564
//
5665
// END OF FILE

libraries/DHTlib/examples/dht22_test/dht22_test.ino

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
22
// FILE: dht22_test.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.02
4+
// VERSION: 0.1.03
55
// PURPOSE: DHT library test sketch for DHT22 && Arduino
66
// URL:
7-
// HISTORY:
7+
// HISTORY:
8+
// 0.1.03 extended stats for all errors
89
// 0.1.02 added counters for error-regression testing.
9-
// 0.1.01
10+
// 0.1.01
1011
// 0.1.00 initial version
1112
//
1213
// Released to the public domain
@@ -20,12 +21,15 @@ dht DHT;
2021

2122
struct
2223
{
23-
uint32_t total;
24-
uint32_t ok;
25-
uint32_t crc_error;
26-
uint32_t time_out;
27-
uint32_t unknown;
28-
} stat = { 0,0,0,0,0 };
24+
uint32_t total;
25+
uint32_t ok;
26+
uint32_t crc_error;
27+
uint32_t time_out;
28+
uint32_t connect;
29+
uint32_t ack_l;
30+
uint32_t ack_h;
31+
uint32_t unknown;
32+
} stat = { 0,0,0,0,0,0,0,0};
2933

3034
void setup()
3135
{
@@ -61,6 +65,18 @@ void loop()
6165
stat.time_out++;
6266
Serial.print("Time out error,\t");
6367
break;
68+
case DHTLIB_ERROR_CONNECT:
69+
stat.connect++;
70+
Serial.print("Connect error,\t");
71+
break;
72+
case DHTLIB_ERROR_ACK_L:
73+
stat.ack_l++;
74+
Serial.print("Ack Low error,\t");
75+
break;
76+
case DHTLIB_ERROR_ACK_H:
77+
stat.ack_h++;
78+
Serial.print("Ack High error,\t");
79+
break;
6480
default:
6581
stat.unknown++;
6682
Serial.print("Unknown error,\t");
@@ -76,17 +92,23 @@ void loop()
7692

7793
if (stat.total % 20 == 0)
7894
{
79-
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
80-
Serial.print(stat.total);
81-
Serial.print("\t");
82-
Serial.print(stat.ok);
83-
Serial.print("\t");
84-
Serial.print(stat.crc_error);
85-
Serial.print("\t");
86-
Serial.print(stat.time_out);
87-
Serial.print("\t");
88-
Serial.print(stat.unknown);
89-
Serial.println("\n");
95+
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
96+
Serial.print(stat.total);
97+
Serial.print("\t");
98+
Serial.print(stat.ok);
99+
Serial.print("\t");
100+
Serial.print(stat.crc_error);
101+
Serial.print("\t");
102+
Serial.print(stat.time_out);
103+
Serial.print("\t");
104+
Serial.print(stat.connect);
105+
Serial.print("\t");
106+
Serial.print(stat.ack_l);
107+
Serial.print("\t");
108+
Serial.print(stat.ack_h);
109+
Serial.print("\t");
110+
Serial.print(stat.unknown);
111+
Serial.println("\n");
90112
}
91113
delay(2000);
92114
}

libraries/DHTlib/examples/dht33_test/dht33_test.ino

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: dht33_test.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.00
4+
// VERSION: 0.1.01
55
// PURPOSE: DHT library test sketch for DHT33 && Arduino
66
// URL:
77
//
@@ -44,6 +44,15 @@ void loop()
4444
case DHTLIB_ERROR_TIMEOUT:
4545
Serial.print("Time out error,\t");
4646
break;
47+
case DHTLIB_ERROR_CONNECT:
48+
Serial.print("Connect error,\t");
49+
break;
50+
case DHTLIB_ERROR_ACK_L:
51+
Serial.print("Ack Low error,\t");
52+
break;
53+
case DHTLIB_ERROR_ACK_H:
54+
Serial.print("Ack High error,\t");
55+
break;
4756
default:
4857
Serial.print("Unknown error,\t");
4958
break;
@@ -55,8 +64,8 @@ void loop()
5564
Serial.print(",\t");
5665
Serial.print(stop - start);
5766
Serial.println();
58-
59-
// FOR UNO + DHT33 400ms SEEMS TO BE MINIMUM DELAY BETWEEN SENSOR READS,
67+
68+
// FOR UNO + DHT33 400ms SEEMS TO BE MINIMUM DELAY BETWEEN SENSOR READS,
6069
// ADJUST TO YOUR NEEDS
6170
delay(1000);
6271
}

libraries/DHTlib/examples/dht44_test/dht44_test.ino

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: dht44_test.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.00
4+
// VERSION: 0.1.01
55
// PURPOSE: DHT library test sketch for DHT44 && Arduino
66
// URL:
77
//
@@ -44,6 +44,15 @@ void loop()
4444
case DHTLIB_ERROR_TIMEOUT:
4545
Serial.print("Time out error,\t");
4646
break;
47+
case DHTLIB_ERROR_CONNECT:
48+
Serial.print("Connect error,\t");
49+
break;
50+
case DHTLIB_ERROR_ACK_L:
51+
Serial.print("Ack Low error,\t");
52+
break;
53+
case DHTLIB_ERROR_ACK_H:
54+
Serial.print("Ack High error,\t");
55+
break;
4756
default:
4857
Serial.print("Unknown error,\t");
4958
break;
@@ -56,7 +65,7 @@ void loop()
5665
Serial.print(stop - start);
5766
Serial.println();
5867

59-
// FOR UNO + DHT44 500ms SEEMS TO BE MINIMUM DELAY BETWEEN SENSOR READS,
68+
// FOR UNO + DHT44 500ms SEEMS TO BE MINIMUM DELAY BETWEEN SENSOR READS,
6069
// ADJUST TO YOUR NEEDS
6170

6271
delay(1000);

libraries/DHTlib/examples/dht_test1/dht_test1.ino

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: dht_test.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.07
4+
// VERSION: 0.1.08
55
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
66
// URL: http://arduino.cc/playground/Main/DHTLib
77
//
@@ -42,6 +42,15 @@ void loop()
4242
case DHTLIB_ERROR_TIMEOUT:
4343
Serial.print("Time out error,\t");
4444
break;
45+
case DHTLIB_ERROR_CONNECT:
46+
Serial.print("Connect error,\t");
47+
break;
48+
case DHTLIB_ERROR_ACK_L:
49+
Serial.print("Ack Low error,\t");
50+
break;
51+
case DHTLIB_ERROR_ACK_H:
52+
Serial.print("Ack High error,\t");
53+
break;
4554
default:
4655
Serial.print("Unknown error,\t");
4756
break;
@@ -68,6 +77,15 @@ void loop()
6877
case DHTLIB_ERROR_TIMEOUT:
6978
Serial.print("Time out error,\t");
7079
break;
80+
case DHTLIB_ERROR_CONNECT:
81+
Serial.print("Connect error,\t");
82+
break;
83+
case DHTLIB_ERROR_ACK_L:
84+
Serial.print("Ack Low error,\t");
85+
break;
86+
case DHTLIB_ERROR_ACK_H:
87+
Serial.print("Ack High error,\t");
88+
break;
7189
default:
7290
Serial.print("Unknown error,\t");
7391
break;
@@ -93,6 +111,15 @@ void loop()
93111
case DHTLIB_ERROR_TIMEOUT:
94112
Serial.print("Time out error,\t");
95113
break;
114+
case DHTLIB_ERROR_CONNECT:
115+
Serial.print("Connect error,\t");
116+
break;
117+
case DHTLIB_ERROR_ACK_L:
118+
Serial.print("Ack Low error,\t");
119+
break;
120+
case DHTLIB_ERROR_ACK_H:
121+
Serial.print("Ack High error,\t");
122+
break;
96123
default:
97124
Serial.print("Unknown error,\t");
98125
break;

libraries/DHTlib/examples/dht_tuning/dht_tuning.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ void loop()
4848
Serial.print("Time out error,\t");
4949
del += 10;
5050
break;
51+
case DHTLIB_ERROR_CONNECT:
52+
Serial.print("Connect error,\t");
53+
break;
54+
case DHTLIB_ERROR_ACK_L:
55+
Serial.print("Ack Low error,\t");
56+
break;
57+
case DHTLIB_ERROR_ACK_H:
58+
Serial.print("Ack High error,\t");
59+
break;
5160
default:
5261
Serial.print("Unknown error,\t");
5362
break;

0 commit comments

Comments
 (0)