David and Gunner,
The request for the library stems from the fact that without the proper timeout setting for the faster ESP 8266, the reading of the device fails. The code below is from the Arduino.cc link I posted to the original version of the library. David has a version that has a hard coded setting for the timeout and it is too short for the ESP 8266. I have used UNO, ESP 8266 and ESP 32 with the DHT 22 and the timeout must be set up properly for each. For the ESP 8266, a timeout of 1200 works.
[ this is more of a count of machine instructions than reading a clock or microsecond function. Faster processors need more clock cycles to give the same timeout delay}
// max timeout is 100 usec.
// For a 16 Mhz proc 100 usec is 1600 clock cycles
// loops using DHTLIB_TIMEOUT use at least 4 clock cycli
// so 100 us takes max 400 loops
// so by dividing F_CPU by 40000 we "fail" as fast as possible
#define DHTLIB_TIMEOUT (F_CPU/40000)
Davidās library has a hard coded value of 100. This may be fine for an Arduino Uno, but this value should be set to 1200 for the ESP 8266. ie it should read:
#define DHTLIB_TIMEOUT (1200)
David ā make this change with whatever program you used to view the dht.h file and save the modified program making sure you use the option to save as plain text. Notepad doesnāt show good line breaks so Word Pad is easier to read and edit, but you must save the file as plain text.
You will need this library change to get the Blynk example code to run. Gunnerās suggestion to just use example code from here is good ā but you may be well served by just getting the DHT to read with no wifi, no blynk first ā and understanding, more or less, how the code accomplishes this.
I have copied the example code from the Arduino link below for you.
//
// FILE: dht_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.07
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// Released to the public domain
//
#include <dht.h>
dht DHT;
#define DHT11_PIN 4
#define DHT21_PIN 5
#define DHT22_PIN 6
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("DHT22, \t");
int chk = DHT.read22(DHT22_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(1000);
// READ DATA
Serial.print("DHT21, \t");
chk = DHT.read21(DHT21_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(1000);
// READ DATA
Serial.print("DHT11, \t");
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(1000);
}
//
// END OF FILE
Cheers