2014-06-26 14:48:20 -04:00
|
|
|
//
|
|
|
|
// FILE: dht_tuning.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// VERSION: 0.1.00
|
|
|
|
// PURPOSE: DHT test sketch for DHT22 && Arduino => find minimum time between reads
|
|
|
|
// URL:
|
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <dht.h>
|
|
|
|
|
|
|
|
dht DHT;
|
|
|
|
|
2015-11-14 15:50:01 -05:00
|
|
|
#define DHT22_PIN 2
|
2014-06-26 14:48:20 -04:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("DHT TEST PROGRAM ");
|
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(DHT_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Type,\tstatus,\t\tHumidity (%),\tTemperatur (C),\tT_Read (us)\tT_Cycle (us)\tT_Delay (us)");
|
2014-06-26 14:48:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int del = 500;
|
2015-11-14 15:50:01 -05:00
|
|
|
uint32_t startRead = 0;
|
|
|
|
uint32_t stopRead = 0;
|
|
|
|
uint32_t startCycle = 0;
|
|
|
|
uint32_t stopCycle = 0;
|
|
|
|
uint32_t tempCycle = 0;
|
2014-06-26 14:48:20 -04:00
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2015-11-14 15:50:01 -05:00
|
|
|
while(del > 0){
|
2014-06-26 14:48:20 -04:00
|
|
|
// READ DATA
|
|
|
|
Serial.print("DHT22, \t");
|
2015-11-14 15:50:01 -05:00
|
|
|
|
|
|
|
startRead = micros();
|
2014-06-26 14:48:20 -04:00
|
|
|
int chk = DHT.read22(DHT22_PIN);
|
2015-11-14 15:50:01 -05:00
|
|
|
stopRead = micros();
|
2014-06-26 14:48:20 -04:00
|
|
|
|
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("OK,\t\t");
|
|
|
|
del -= 10;
|
|
|
|
break;
|
2014-06-26 14:48:20 -04:00
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Checksum,\t");
|
|
|
|
break;
|
2014-06-26 14:48:20 -04:00
|
|
|
case DHTLIB_ERROR_TIMEOUT:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Time out,\t");
|
|
|
|
del += 10;
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_CONNECT:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Connect,\t");
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_ACK_L:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Ack Low,\t");
|
|
|
|
break;
|
2014-10-23 10:15:26 -04:00
|
|
|
case DHTLIB_ERROR_ACK_H:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Ack High,\t");
|
|
|
|
break;
|
2014-06-26 14:48:20 -04:00
|
|
|
default:
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("Unknown,\t");
|
|
|
|
break;
|
2014-06-26 14:48:20 -04:00
|
|
|
}
|
|
|
|
// DISPLAY DATA
|
|
|
|
Serial.print(DHT.humidity, 1);
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print(",\t\t");
|
2014-06-26 14:48:20 -04:00
|
|
|
Serial.print(DHT.temperature, 1);
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print(",\t\t");
|
|
|
|
Serial.print(stopRead - startRead);
|
|
|
|
Serial.print(",\t\t");
|
|
|
|
stopCycle = micros();
|
|
|
|
tempCycle = micros();
|
|
|
|
Serial.print(stopCycle - startCycle);
|
|
|
|
startCycle = tempCycle;
|
|
|
|
Serial.print(",\t\t");
|
2014-06-26 14:48:20 -04:00
|
|
|
Serial.print(del);
|
2015-11-14 15:50:01 -05:00
|
|
|
Serial.print("000");
|
2014-06-26 14:48:20 -04:00
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
delay(del);
|
2015-11-14 15:50:01 -05:00
|
|
|
}
|
|
|
|
while(1);
|
2014-06-26 14:48:20 -04:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// END OF FILE
|
2015-11-14 15:50:01 -05:00
|
|
|
//
|
|
|
|
|