DHT11 Temp/Humidity sensor help
Roxanna77
Posts: 18
in Propeller 1
Has anybody had any luck with the DHT11 obex example code and diver? I kept thinking my dht11 sensors were no good, as I could not get them to read consistently with the example. About 9 of 10 resets on any of my Quickstart boards would show Read Error, and when it would show a temp and humidity, it would not change unless I reset the board. I got an Arduino Uno the other day and tried the sensors on it with the Adafruit library, and the sensors reads perfect. I want to use it on a Propeller though.
So, what is wrong with this code? The way it is written, I can't make heads nor tails of it (no surprise, I'm not that good of a programmer). I tried different pins, same results.
Any help I can get would be greatly appreciated!
So, what is wrong with this code? The way it is written, I can't make heads nor tails of it (no surprise, I'm not that good of a programmer). I tried different pins, same results.
Any help I can get would be greatly appreciated!

Comments
I wrote my own DHT11 driver; it's attached in a demo.
Works nice, object code I can read and really cool display too!
thanks again!
I rule!
And thank you for spelling my name correctly!
I'm working of a PASM version that can report a bad sensor. In this version if the readings count doesn't change then you know something is amiss.
The main code including variables etc is just 59 bytes
--- Define DHTPIN - to change at runtime just <mypin> ' DHTPIN 1+ ! #P14 == DHTPIN LONG httime --- last time DHT was polled WORD htref,rh,dht --- timing reference and last valid readings BYTE htck --- checksum --- Read a single bit and return with the cnt value pri DHTBIT ( -- cnt ) (WAITPEQ) --- wait for it to go high 0 COGREG@ --- get captured CNT (WAITPNE) --- until it goes low 0 COGREG@ SWAP - --- calculate timing of high period ; --- Read in 8 bits using the intial start pulse as a ref in htref for timing pri DHTBYTE ( -- byte ) 0 8 FOR 2* DHTBIT htref W@ > 1 AND OR NEXT DUP htck C+! ; {HELP DHT@ ( -- rh temp | -1 ) Read the relative humidity and temperature from the DHT22 Return with rh and temp in Celsius If an error occurred in the checksum then return last valid reading If the sensor is polled more than once every 2 seconds then use last valid readings Typical acquisition time ~6ms } pub DHT@ ( -- rh temp ) runtime @ httime @ - 2000 => --- don't poll more than once every 2 seconds IF runtime @ httime ! --- mark runtime when this was polled htck C~ DHTPIN MASK 3 COGREG! DHTPIN LOW 1 ms DHTPIN FLOAT --- Generate reset pulse DHTBIT DROP --- wait for start of response DHTBIT 3 / 2* htref W! --- use start bit as reference DHTBYTE 8 SHL DHTBYTE + --- 2 bytes humidity reading DHTBYTE 8 SHL DHTBYTE + --- 2 bytes temperature reading htck C@ DHTBYTE = --- if checksum does not match then use last reading IF dht W! rh W! ELSE 2DROP THEN --- latch readings if valid THEN rh W@ dht W@ --- return with latest valid result ;A version of DHT@ that lets you pass the pin number as a parameter:
True, and I prefer I2C normally, but not when it comes to distance as the single wire sensor can be run up to 30 metres away which is more usual for these types of sensors rather than to have them close to the PCB.
Thanks
Unfortunately, she hasn't been able to test my new version.
I'd be happy to share the new version with anyone who's interested in verifying my fix...
Thanks,
Walter