DHT22 problem #896
Replies: 12 comments
-
Posted at 2016-11-04 by @gfwilliams You know about it returning -1 if there are problems reading the data? That will happen occasionally so you need to be sure to ignore them. Running two reads at the same time is a really bad idea as multiple watches/timeouts get queued up - see the actual code: https://github.com/espruino/EspruinoDocs/blob/master/devices/DHT22.js Are you sure you've got it wired up right? I suppose you might expect this if the 3.3v line wasn't connected properly? I guess you could try copy/pasting the code from the module and fiddling with the value used for |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-04 by Frida The only real downside of this sensor is you can only get new data from it once every 2 seconds. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-04 by @gfwilliams Ahh - so polling every second might well have confused it? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-06 by ClearMemory041063 Let me restate the problem.
The example code
Produces the following output:
Notice that the module code produces a lot of retries n. 1st try n=10, 2nd try n=9... By changing the example code to
Which gives to following output
This gives correct temperature and humidity readings without all the retries in the module code. From a programming perspective it is troubling as Gordon outlined above. And finally changing the example code one more time so that the one dht.read completes before the 2nd one starts.
This gives;
Changing the set interval from 1000 to 2000 helps. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-07 by @gfwilliams
Is it substantially better? What about going slower still like 3000ms? As @frida says, if the sensor can only provide a signal every 2 sec then I don't see what we can do if you request something every second? Possibly the module could be updated to warn the user if they call it too often? My guess is that sending the pulse twice as you were doing might reset the sensor somehow - but that's probably not going to give you very good readings. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-07 by luwar If you need a higher data rate then a different sensor could be an alternative. One of the cheapest is the HTU21D/SHT21: http://www.ebay.com/itm/112049178633 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by ClearMemory041063 Data rate is not an issue as I use the DH22 to turn my window AC on and off based on keeping temperature and RH within a comfort zone. In my climate humidity is a factor in maintaining comfort and temperature alone either freezes me or I wake up in the night with too much humidity. Sampling every minute or longer should suffice. As to the two second interval, the module code does up to 10 retires one after the other. Perhaps the 2 second specification is related to the accuracy of the reading and not to the ability to read data from the device. The hardware is setup on a solder less breadboard with 6 inch jumper wires and a 4.7k pullup resistors. As to the double pulse idea, I tried that and it doesn't trigger the device any better than the single pulse. Thanks for the alternate parts list, I will investigate. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by ClearMemory041063 Found a solution changed 6 to 60 on the outer setInterval of the module
Sample output Temperature in F.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by @gfwilliams How many retries does it use then? That looks like a good fix - I can't see it causing any problems. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by Frida We had a discussion over at:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by @gfwilliams Ok, just updated with a longer timeout. Sorry about that @frida, looks like I missed your suggestion |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-08 by Frida Don't be, we all can't know everything, it's now a big forum, so keep up the good work. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-03 by ClearMemory041063
Running a PICO V1.87
This code
produces the following output
But this code
Produces this output
Is there something missing in the module code?
Pin initialization?
A bit?
Beta Was this translation helpful? Give feedback.
All reactions