Re: DHT22 not working with 8mhz clockspeed?

robtillaart: my DHT lib - http://arduino.cc/playground/Main/DHTLib - uses the micros() to measure the duration of pulses so it should be CPUclock insensitive in theory ...

(I crossposted this on another DHT thread 2 seconds ago)

Please let me know if it works.

I tried following up with your library and your code but I was faced with the following display in the serial monitor "DHT 22 Time out error -999.0 -999.0"

Please enlighten me about where have I gone wrong.....

Thanks

Biswajit

apparently there was an error in the handshake.

Which version of the library did you use? Which IDE? Which board? Clockspeed? Can you post your code?

The version 0.1.13 is the most stable version but does not work very well on 8 Mhz. IIRC it reads correctly about 80% of the time on my UNO. The reason is that micros() works roughly in steps of 8 usec (@8Mhz) and the protocol demands accuracy down to ~20 usec. So if no interrupts (serial/timer) or other background code is handled the library can handle it. One interrupt is enough to miss a pulse resulting in timeout.

robtillaart:
apparently there was an error in the handshake.

Which version of the library did you use?
Which IDE?
Which board?
Clockspeed?
Can you post your code?

The version 0.1.13 is the most stable version but does not work very well on 8 Mhz. IIRC it reads correctly about 80% of the time on my UNO.
The reason is that micros() works roughly in steps of 8 usec (@8Mhz) and the protocol demands accuracy down to ~20 usec. So if no interrupts (serial/timer) or other background code is handled the library can handle it. One interrupt is enough to miss a pulse resulting in timeout.

Rob,

The Library version - 0.1.14
IDE - 1.6.4 (latest version)
board - Arduino Uno R 3
clockspeed - 16 MHz

The code is posted below and the .h as well as .cpp files are attached alongwith…

// 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 <stdio.h>
#include <dht.h>

dht DHT;

//#define DHT11_PIN 4
//#define DHT21_PIN 5
#define DHT22_PIN 2

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);

}
//
// END OF FILE
//

dht.h (1.47 KB)

dht.cpp (4.59 KB)