2016-12-17 15:03:32 -05:00
|
|
|
//
|
|
|
|
// FILE: DHT2pin.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-01-29 06:31:58 -05:00
|
|
|
// VERSION: 0.1.2
|
2016-12-17 15:03:32 -05:00
|
|
|
// PURPOSE: demo reading an DHT with 2 pins iso 1
|
|
|
|
// DATE: 2016 sep 5
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DHT2pin
|
|
|
|
// http://arduino.cc/playground/Main/DHTLib
|
|
|
|
//
|
2016-12-17 15:03:32 -05:00
|
|
|
// HISTORY:
|
2021-01-29 06:31:58 -05:00
|
|
|
// 0.1.2 nade it arduino-CI compatible
|
|
|
|
// 0.1.01 changed name to DHT2pin
|
|
|
|
// 0.1.00 initial version
|
2016-12-17 15:03:32 -05:00
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <DHT2pin.h>
|
|
|
|
|
|
|
|
DHT2pin DHT(2, 3);
|
|
|
|
|
|
|
|
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};
|
2016-12-17 15:03:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
DHT.begin();
|
|
|
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(DHT2PIN_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();
|
|
|
|
uint32_t stop = micros();
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.total++;
|
2016-12-17 15:03:32 -05:00
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.ok++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.crc_error++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.time_out++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Time out error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CONNECT:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.connect++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Connect error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_L:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.ack_l++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Ack Low error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_ACK_H:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.ack_h++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Ack High error,\t");
|
|
|
|
break;
|
|
|
|
default:
|
2021-01-29 06:31:58 -05:00
|
|
|
counter.unknown++;
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("Unknown error,\t");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
|
|
|
Serial.print(DHT.humidity, 1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.print(DHT.temperature, 1);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.println();
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
if (counter.total % 20 == 0)
|
2016-12-17 15:03:32 -05:00
|
|
|
{
|
|
|
|
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.total);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ok);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.crc_error);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.time_out);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.connect);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ack_l);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.ack_h);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.print("\t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(counter.unknown);
|
2016-12-17 15:03:32 -05:00
|
|
|
Serial.println("\n");
|
|
|
|
}
|
|
|
|
delay(2000);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// END OF FILE
|
|
|
|
//
|