Problem with DHT22
Moderator: Benj
Problem with DHT22
Hello. I have tried the example program of Flowcode Wiki but unfortunately the program does not run.
I have tried a 16F877A with 19.9906MHz and tried an 18F46K22 with 64MHz, neither of the two running the program. It remains attached to "Sample Sensor". The output B6 becomes high, the B7 not.
I've also tried another sensor - the same.
I bought DHT22 - but AM2302 got, which supposedly be the same.
Does anyone have an AM2302 that works?
I have tried a 16F877A with 19.9906MHz and tried an 18F46K22 with 64MHz, neither of the two running the program. It remains attached to "Sample Sensor". The output B6 becomes high, the B7 not.
I've also tried another sensor - the same.
I bought DHT22 - but AM2302 got, which supposedly be the same.
Does anyone have an AM2302 that works?
- Attachments
-
- DHT22_Example_v7.fcfx
- (8.07 KiB) Downloaded 570 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
I'll dig out a DHT22 today and see if I can replicate the problems you're having.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Problem with DHT22
Hi Both!
Maybe a little help to Ben during troubleshooting.
I try to test the example program like ressi. I change the Pic to a Pic16F877a and run the program, nothing happen could not see anything in the display. Then I add in top of the loop after init the display, a string "test". After that I could see the text in the display "test" but still nothing else. Then I add port D 1 sec flash in the loop compile again, and again I saw the text "test" but port D not flash.
If I disable the DHT22 componentmacro, port D begin to flash.
Look like the DHT22 component stop the program.
Maybe it could help.
Br Jorgen
Maybe a little help to Ben during troubleshooting.
I try to test the example program like ressi. I change the Pic to a Pic16F877a and run the program, nothing happen could not see anything in the display. Then I add in top of the loop after init the display, a string "test". After that I could see the text in the display "test" but still nothing else. Then I add port D 1 sec flash in the loop compile again, and again I saw the text "test" but port D not flash.
If I disable the DHT22 componentmacro, port D begin to flash.
Look like the DHT22 component stop the program.
Maybe it could help.
Br Jorgen
- Attachments
-
- DHT22_ExampleNot.fcfx
- (8.31 KiB) Downloaded 431 times
Re: Problem with DHT22
Hallo benj.
There is already a solution with the
Component macro?
User jgu1 has the same problem!!
There is already a solution with the
Component macro?
User jgu1 has the same problem!!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Hello,
Sorry for the delay. I now have the sensors with me and will be investigating this morning.
Sorry for the delay. I now have the sensors with me and will be investigating this morning.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
I've found a few issues and now got this working really reliably on an Arduino / AVR.
For some reason PIC is still having issues so just seeing if I can bottom these before sending out an update.
For some reason PIC is still having issues so just seeing if I can bottom these before sending out an update.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Right this seems to be working nicely now and should be much more tolerant to timings and errors. No more blocked programs.
Tested with 16F1937 @ 19.6608MHz & 32MHz / Arduino Uno @ 16MHz
Simply copy the attached file to your "Flowcode 7/components" directory before restarting Flowcode.
Here's the same fix for the DHT11 component.
Here's a slightly improved test file.
Let me know how you get on.
Tested with 16F1937 @ 19.6608MHz & 32MHz / Arduino Uno @ 16MHz
Simply copy the attached file to your "Flowcode 7/components" directory before restarting Flowcode.
Here's the same fix for the DHT11 component.
Here's a slightly improved test file.
Let me know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Problem with DHT22
´Thank´s Ben! I am out in the `field`at the moment, as soon I am home again I test your correction, and you hear.
Br Jorgen
Br Jorgen
Re: Problem with DHT22
Hello. Unfortunately it does not work. The error message "CRC Error" comes.
When I turn off the CRC test, I see a temperature And humidity but it is not correct and jumps around, from 100 to -100 everything is there. It is the same with the humidity.
When I turn off the CRC test, I see a temperature And humidity but it is not correct and jumps around, from 100 to -100 everything is there. It is the same with the humidity.
Re: Problem with DHT22
With the DHT11 is the Same. It jumps from 10 to 40 without CRC test. With CRC Test it comes CRC Error on thr Display.



- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Hello sounds like its right on the edge of working. what micro and clock speed are you using are they the same as listed above. Also are you using pull up resistors on the data line. I found both sensors worked fine without pull ups but the distance was very short.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Problem with DHT22
Hallo. Thanks for the fast replay. I use a 16F877A Witz 19.6608MHz. With pullup (10k) und Very short strips (10cm).
I Test it tomorrow with a 18F46K22 with 64MHz.
You hear from mehr.
I Test it tomorrow with a 18F46K22 with 64MHz.
You hear from mehr.
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Problem with DHT22
Hi!
I have just tested Ben´s new program and component.
I have change the Pic to a Pic16f876 and corrected the config. I see in display "CRC Error" and nothing else.
Only for information.....
Br. Jorgen
I have just tested Ben´s new program and component.
I have change the Pic to a Pic16f876 and corrected the config. I see in display "CRC Error" and nothing else.
Only for information.....
Br. Jorgen
Re: Problem with DHT22
With 18F46K22 with 64MHz it Workshops, BUT Minus degree Not work correct!
- Attachments
-
- 20161221_173628.jpg
- (191.51 KiB) Downloaded 1887 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Hello,
Aha great glad it's working at a faster speed. Here is an updated version of the component which hopefully should work better with negative temperatures.
Aha great glad it's working at a faster speed. Here is an updated version of the component which hopefully should work better with negative temperatures.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Right I have replicated the CRC issue on a 16F877A running at 19.6608MHz.
The attached components should hopefully now solve this issue and allow this to work, at least they are now working nicely for me.
Simply copy the files to your "Flowcode 7/components" directory and restart Flowcode for the changes to be loaded.
The problem seems to be the Free XC8 compiler which is creating 1uS delays which actually last nearly 8uS. So for the 8-bit PICs I have removed the delay altogether and rely on the timeout being long enough.
Please could you also test it with your 64MHz PIC just to check I have not broken this.
The attached components should hopefully now solve this issue and allow this to work, at least they are now working nicely for me.
Simply copy the files to your "Flowcode 7/components" directory and restart Flowcode for the changes to be loaded.
The problem seems to be the Free XC8 compiler which is creating 1uS delays which actually last nearly 8uS. So for the 8-bit PICs I have removed the delay altogether and rely on the timeout being long enough.
Please could you also test it with your 64MHz PIC just to check I have not broken this.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Its possible to use the pro mode for 60 days for free by downloading and installing your own version of XC8 from Microchip. You can then point Flowcode to your compiler using the Compiler options menu.
I'll keep an eye on this as it's strange it's working perfectly for me at 19.6608MHz on a PIC but not for you or martin.
I'll keep an eye on this as it's strange it's working perfectly for me at 19.6608MHz on a PIC but not for you or martin.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Problem with DHT22
After Christmas I will try the Pro compiler and you hear from me how it then works.
Thanks a lot Band marry christmas
Thanks a lot Band marry christmas
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
Re: Problem with DHT22
Hi!
Just tested it with a Pic16f876, work perfect
Later I will test it with an Arduino and you hear.
Thank´s Ben
Br Jorgen
Just tested it with a Pic16f876, work perfect

Later I will test it with an Arduino and you hear.
Thank´s Ben
Br Jorgen
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Problem with DHT22
A fairly old topic - but a couple of questions in a similar vein....
Using the attached code and a DHT11 sensor the temperature jumps occasionally (every 20 or so readings) by about 4C/5C - it might be a faulty sensor but using the Arduino IDE and a DHT11 example didn't show the same problem. (So I sit here with 13/14C and occasional 18C readings - which unless my pet dragon is nearby seem unlikely)
This reads the temp and humidity and then outputs to a Bluetooth port:
Output (Shows temp bytes, tempfloat, tempstring and humidity) :
16 0 16.0C 16.0C Hum = 77.0%
15 0 15.0C 15.0C Hum = 75.0%
21 0 21.0C 21.0C Hum = 74.0% ??
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
16 0 16.0C 16.0C Hum = 74.0%
15 0 15.0C 15.0C Hum = 76.0%
20 0 20.0C 20.0C Hum = 76.0% ??
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
16 0 16.0C 16.0C Hum = 75.0%
Warming up nicely now!
Anyone else come across this?
As an aside:
The library code for GetTempFloat and GetHumidityFloat both convert the required value to a string and then convert the string to a float - which seems a rather inefficient way to do this? The 'float' part of the temperature (& humidity) always seems to be 0 - is this a 'feature' of the sensor? (the Arduino lib example also gets 0 here)
Using the attached code and a DHT11 sensor the temperature jumps occasionally (every 20 or so readings) by about 4C/5C - it might be a faulty sensor but using the Arduino IDE and a DHT11 example didn't show the same problem. (So I sit here with 13/14C and occasional 18C readings - which unless my pet dragon is nearby seem unlikely)
This reads the temp and humidity and then outputs to a Bluetooth port:
Output (Shows temp bytes, tempfloat, tempstring and humidity) :
16 0 16.0C 16.0C Hum = 77.0%
15 0 15.0C 15.0C Hum = 75.0%
21 0 21.0C 21.0C Hum = 74.0% ??
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
16 0 16.0C 16.0C Hum = 74.0%
15 0 15.0C 15.0C Hum = 76.0%
20 0 20.0C 20.0C Hum = 76.0% ??
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
15 0 15.0C 15.0C Hum = 75.0%
16 0 16.0C 16.0C Hum = 75.0%
Warming up nicely now!
Anyone else come across this?
As an aside:
The library code for GetTempFloat and GetHumidityFloat both convert the required value to a string and then convert the string to a float - which seems a rather inefficient way to do this? The 'float' part of the temperature (& humidity) always seems to be 0 - is this a 'feature' of the sensor? (the Arduino lib example also gets 0 here)
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Problem with DHT22
Hello,
I've not experienced the value jumping that you are seeing. It could be a faulty sensor or it could be some noise on the power rails. Maybe add a capacitor across the power rails near the sensor to see if that helps.
You could also add your own filtering to the readings to filter out the occasional strange value.
e.g. this would use 90% of the old value and 10% of the new value.
temperature = (temperature * 0.9) + (newtemp * 0.1)
The DHT11 is only accurate to a whole number degree but the code is compatible with the DHT22 sensor which has a higher accuracy and will give you floating point real values.
The GetTempWhole is probably a better option for the DHT11 as this doesn't involve floats or strings. Just investigating now to see if there is a better way to generate the float value.
I've not experienced the value jumping that you are seeing. It could be a faulty sensor or it could be some noise on the power rails. Maybe add a capacitor across the power rails near the sensor to see if that helps.
You could also add your own filtering to the readings to filter out the occasional strange value.
e.g. this would use 90% of the old value and 10% of the new value.
temperature = (temperature * 0.9) + (newtemp * 0.1)
The DHT11 is only accurate to a whole number degree but the code is compatible with the DHT22 sensor which has a higher accuracy and will give you floating point real values.
The GetTempWhole is probably a better option for the DHT11 as this doesn't involve floats or strings. Just investigating now to see if there is a better way to generate the float value.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Problem with DHT22
Hi Ben,
Thanks - by chance a AM2302 arrived from BangGood today - so popped that into the circuit instead - and much steadier reading (I also need the extra range - must check that things aren't going to go below 0)
Looking at the datasheet https://cdn-shop.adafruit.com/datasheet ... AM2302.pdf
[img]dht22.png[/img]
Woah - sorry that is a bit bigger than expected !- and it appears at the bottom of this post?
Convert (16 bit) binary value to decimal then divide by 10..... Need to check the sign and adjust for negative temps
For the DHT11 - its just convert the integer to a float value as the decimal part is always 0?
Martin
Thanks - by chance a AM2302 arrived from BangGood today - so popped that into the circuit instead - and much steadier reading (I also need the extra range - must check that things aren't going to go below 0)
Looking at the datasheet https://cdn-shop.adafruit.com/datasheet ... AM2302.pdf
[img]dht22.png[/img]
Woah - sorry that is a bit bigger than expected !- and it appears at the bottom of this post?
Convert (16 bit) binary value to decimal then divide by 10..... Need to check the sign and adjust for negative temps
For the DHT11 - its just convert the integer to a float value as the decimal part is always 0?
Martin
- Attachments
-
- dht22.png
- (119.18 KiB) Downloaded 5326 times