jeelabs / jeelib

JeeLib for Arduino IDE: Ports, RF12, and RF69 drivers from JeeLabs
https://jeelabs.org/202x/sw/jeelib/
The Unlicense
490 stars 215 forks source link

DHT22 won't read correct valus #47

Closed octplane closed 11 years ago

octplane commented 11 years ago

Hello,

I've been attempting to read data from a DHT22 sensor and the Jeelib built-in DHT calls give wrong data:

I've used the example from http://jeelabs.org/2012/04/14/reading-out-dhtxx-sensors/ and got the following data out of the board:

[dht_demo]
DHT 15 4 4 4 4 4 4 4 13 4 13 13 13 4 14 4 3 4 4 4 4 4 4 5 3 13 13 13 14 13 13 13 4 4 13 13 13 4 4 14 13
HEX 3 1 74 0 FE 73 : 73
temperature = 9
humidity = 14

Although the humidity value seemed weird, the temperature value is definitely false.

I then tried using the Adafruit DHT22 Library (living at https://github.com/adafruit/DHT-sensor-library) and get much better result:

Humidity: 36.20 %   Temperature: 25.20 *C

From looking at the code, it seems that the DHT library handles temperature a bit differently il the DHT22 case (cf https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.cpp#L37 and following).

Thank you for your time :)

octplane commented 11 years ago

I tried to reply to http://jeelabs.net/boards/7/topics/1469 but the forum won't let me write anything. Note that I am not mikeacar from the forum. I just joined the forum a few minutes ago and I think my account needs to be validated in order to post there...

jcw commented 11 years ago

I'll look into this. Last time I tried a DHT22 here, it all seemed to work. No idea what could have messed this up...

danward79 commented 11 years ago

Hi,

I reported this on the (old) forum, you need to edit line 1017 and 1021 in ports.cpp to read humi = h and temp = t

http://forum.jeelabs.net/node/1487.html

Ideally the initialisation for this sensor should take a parameter to say if it is a DHT22 or not.

Dan

martynj3 commented 11 years ago

@octplane - your Forum access is confirmed now.