2015-08-20 17:02:36 -04:00
|
|
|
//
|
|
|
|
// FILE: dht22_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-05-28 07:22:49 -04:00
|
|
|
// VERSION: 1.0.0
|
2015-08-20 17:02:36 -04:00
|
|
|
// PURPOSE: DHT library test sketch for DHT22 && Arduino
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DHTstable
|
|
|
|
//
|
2015-08-20 17:02:36 -04:00
|
|
|
// HISTORY:
|
2021-05-28 07:22:49 -04:00
|
|
|
// 1.0.0 2021-05-26 class name changed to DHTStable (breaking change)
|
2015-08-20 17:02:36 -04:00
|
|
|
//
|
2021-05-28 07:22:49 -04:00
|
|
|
// 0.2.0 use getHumidity() and getTemperature()
|
|
|
|
// 0.1.4 add URL in header
|
|
|
|
// 0.1.03 extended stats for all errors
|
|
|
|
// 0.1.02 added counters for error-regression testing.
|
|
|
|
// 0.1.01 ?
|
|
|
|
// 0.1.00 initial version
|
|
|
|
//
|
|
|
|
|
2015-08-20 17:02:36 -04:00
|
|
|
|
2021-05-28 07:22:49 -04:00
|
|
|
#include "DHTStable.h"
|
2015-08-20 17:02:36 -04:00
|
|
|
|
2021-05-28 07:22:49 -04:00
|
|
|
DHTStable DHT;
|
2015-08-20 17:02:36 -04:00
|
|
|
|
|
|
|
#define DHT22_PIN 5
|
|
|
|
|
2021-05-28 07:22:49 -04:00
|
|
|
|
2015-08-20 17:02:36 -04:00
|
|
|
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;
|
2021-01-29 06:31:58 -05:00
|
|
|
} counter = { 0,0,0,0,0,0,0,0};
|
2015-08-20 17:02:36 -04:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.println(__FILE__);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("LIBRARY VERSION: ");
|
2021-05-28 07:22:49 -04:00
|
|
|
Serial.println(DHTSTABLE_LIB_VERSION);
|
2015-08-20 17:02:36 -04:00
|
|
|
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();
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.total++;
|
2015-08-20 17:02:36 -04:00
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.ok++;
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.crc_error++;
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.time_out++;
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
|
|
|
default:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.unknown++;
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-08-20 17:02:36 -04:00
|
|
|
// DISPLAY DATA
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(DHT.getHumidity(), 1);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print(",\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(DHT.getTemperature(), 1);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println();
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// DISPLAY COUNTERS
|
|
|
|
if (counter.total % 20 == 0)
|
2015-08-20 17:02:36 -04:00
|
|
|
{
|
|
|
|
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.total);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ok);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.crc_error);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.time_out);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.connect);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ack_l);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ack_h);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.unknown);
|
2015-08-20 17:02:36 -04:00
|
|
|
Serial.println("\n");
|
|
|
|
}
|
|
|
|
delay(2000);
|
|
|
|
}
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-05-28 07:22:49 -04:00
|
|
|
// -- END OF FILE --
|