2018-01-08 17:22:13 -05:00
|
|
|
//
|
|
|
|
// FILE: dhtnew_test.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: DHTNEW library test sketch for Arduino
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/DHTNew
|
2021-12-16 11:24:05 -05:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// DHT PIN layout from left to right
|
|
|
|
// =================================
|
|
|
|
// FRONT : DESCRIPTION
|
|
|
|
// pin 1 : VCC
|
|
|
|
// pin 2 : DATA
|
|
|
|
// pin 3 : Not Connected
|
|
|
|
// pin 4 : GND
|
2018-01-08 17:22:13 -05:00
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
#include <dhtnew.h>
|
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
DHTNEW mySensor(5); // ESP 16 UNO 5 MKR1010 5
|
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2021-11-18 03:48:40 -05:00
|
|
|
while(!Serial); // MKR1010 needs this
|
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("dhtnew_test.ino");
|
|
|
|
Serial.print("LIBRARY VERSION: ");
|
|
|
|
Serial.println(DHTNEW_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
// MKR1010
|
|
|
|
// mySensor.setDisableIRQ(false);
|
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
Serial.println("\n1. Type detection test, first run might take longer to determine type");
|
|
|
|
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
|
|
|
test();
|
|
|
|
test();
|
|
|
|
test();
|
|
|
|
test();
|
|
|
|
|
|
|
|
Serial.println("\n2. Humidity offset test");
|
|
|
|
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
|
|
|
mySensor.setHumOffset(2.5);
|
|
|
|
test();
|
|
|
|
mySensor.setHumOffset(5.5);
|
|
|
|
test();
|
|
|
|
mySensor.setHumOffset(-5.5);
|
|
|
|
test();
|
|
|
|
mySensor.setHumOffset(0);
|
|
|
|
test();
|
|
|
|
|
|
|
|
Serial.println("\n3. Temperature offset test");
|
|
|
|
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
|
|
|
|
mySensor.setTempOffset(2.5);
|
|
|
|
test();
|
|
|
|
mySensor.setTempOffset(5.5);
|
|
|
|
test();
|
|
|
|
mySensor.setTempOffset(-5.5);
|
|
|
|
test();
|
|
|
|
mySensor.setTempOffset(0);
|
|
|
|
test();
|
|
|
|
|
|
|
|
Serial.println("\n4. LastRead test");
|
|
|
|
mySensor.read();
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
if (millis() - mySensor.lastRead() > 1000)
|
|
|
|
{
|
|
|
|
mySensor.read();
|
|
|
|
Serial.println("actual read");
|
|
|
|
}
|
2020-11-27 05:10:47 -05:00
|
|
|
Serial.print(mySensor.getHumidity(), 1);
|
2018-01-08 17:22:13 -05:00
|
|
|
Serial.print(",\t");
|
2020-11-27 05:10:47 -05:00
|
|
|
Serial.println(mySensor.getTemperature(), 1);
|
2018-01-08 17:22:13 -05:00
|
|
|
delay(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.println("\nDone...");
|
|
|
|
}
|
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
void test()
|
|
|
|
{
|
|
|
|
// READ DATA
|
|
|
|
uint32_t start = micros();
|
|
|
|
int chk = mySensor.read();
|
|
|
|
uint32_t stop = micros();
|
|
|
|
|
|
|
|
switch (chk)
|
|
|
|
{
|
|
|
|
case DHTLIB_OK:
|
|
|
|
Serial.print("OK,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_CHECKSUM:
|
|
|
|
Serial.print("Checksum error,\t");
|
|
|
|
break;
|
2020-11-27 05:10:47 -05:00
|
|
|
case DHTLIB_ERROR_TIMEOUT_A:
|
|
|
|
Serial.print("Time out A error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT_B:
|
|
|
|
Serial.print("Time out B error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT_C:
|
|
|
|
Serial.print("Time out C error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_TIMEOUT_D:
|
|
|
|
Serial.print("Time out D error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_SENSOR_NOT_READY:
|
|
|
|
Serial.print("Sensor not ready,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_ERROR_BIT_SHIFT:
|
|
|
|
Serial.print("Bit shift error,\t");
|
|
|
|
break;
|
|
|
|
case DHTLIB_WAITING_FOR_READ:
|
|
|
|
Serial.print("Waiting for read,\t");
|
2018-01-08 17:22:13 -05:00
|
|
|
break;
|
|
|
|
default:
|
2020-11-27 05:10:47 -05:00
|
|
|
Serial.print("Unknown: ");
|
|
|
|
Serial.print(chk);
|
|
|
|
Serial.print(",\t");
|
2018-01-08 17:22:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2020-11-27 05:10:47 -05:00
|
|
|
|
2018-01-08 17:22:13 -05:00
|
|
|
// DISPLAY DATA
|
2020-11-27 05:10:47 -05:00
|
|
|
Serial.print(mySensor.getHumidity(), 1);
|
2018-01-08 17:22:13 -05:00
|
|
|
Serial.print(",\t");
|
2020-11-27 05:10:47 -05:00
|
|
|
Serial.print(mySensor.getTemperature(), 1);
|
2018-01-08 17:22:13 -05:00
|
|
|
Serial.print(",\t");
|
|
|
|
uint32_t duration = stop - start;
|
|
|
|
Serial.print(duration);
|
|
|
|
Serial.print(",\t");
|
|
|
|
Serial.println(mySensor.getType());
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-18 03:48:40 -05:00
|
|
|
// -- END OF FILE --
|
|
|
|
|