+ add samples to DHTstable

This commit is contained in:
rob tillaart 2015-08-20 23:02:36 +02:00
parent 8c0fe83507
commit 7827cc186e
3 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,56 @@
//
// FILE: dht11_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.01
// PURPOSE: DHT library test sketch for DHT11 && Arduino
// URL:
//
// Released to the public domain
//
#include <dht.h>
dht DHT;
#define DHT11_PIN 5
void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT11, \t");
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
delay(2000);
}
//
// END OF FILE
//

View File

@ -0,0 +1,105 @@
//
// FILE: dht22_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.03
// PURPOSE: DHT library test sketch for DHT22 && Arduino
// URL:
// HISTORY:
// 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
//
// Released to the public domain
//
#include <dht.h>
dht 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;
} stat = { 0,0,0,0,0,0,0,0};
void setup()
{
Serial.begin(115200);
Serial.println("dht22_test.ino");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_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();
stat.total++;
switch (chk)
{
case DHTLIB_OK:
stat.ok++;
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
stat.crc_error++;
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
stat.time_out++;
Serial.print("Time out error,\t");
break;
default:
stat.unknown++;
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();
if (stat.total % 20 == 0)
{
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
Serial.print(stat.total);
Serial.print("\t");
Serial.print(stat.ok);
Serial.print("\t");
Serial.print(stat.crc_error);
Serial.print("\t");
Serial.print(stat.time_out);
Serial.print("\t");
Serial.print(stat.connect);
Serial.print("\t");
Serial.print(stat.ack_l);
Serial.print("\t");
Serial.print(stat.ack_h);
Serial.print("\t");
Serial.print(stat.unknown);
Serial.println("\n");
}
delay(2000);
}
//
// END OF FILE
//

View File

@ -0,0 +1,2 @@
2015-08-20 these examples are retrofitted from version 0.1.20 which supports more errors.