Page 1 of 1

Problem with DHT22

Posted: Thu Dec 15, 2016 8:07 pm
by ressi
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?

Re: Problem with DHT22

Posted: Fri Dec 16, 2016 12:59 pm
by Benj
I'll dig out a DHT22 today and see if I can replicate the problems you're having.

Re: Problem with DHT22

Posted: Sun Dec 18, 2016 4:08 pm
by jgu1
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

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 10:37 am
by ressi
Hallo benj.
There is already a solution with the
Component macro?
User jgu1 has the same problem!!

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 11:10 am
by Benj
Hello,

Sorry for the delay. I now have the sensors with me and will be investigating this morning.

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 1:38 pm
by Benj
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.

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 2:27 pm
by Benj
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.
DHT22.fcpx
(35.56 KiB) Downloaded 552 times
Here's the same fix for the DHT11 component.
DHT11.fcpx
(35.41 KiB) Downloaded 549 times
Here's a slightly improved test file.
DHT22_Example_v7.fcfx
(9.55 KiB) Downloaded 596 times
Let me know how you get on.

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 8:34 pm
by jgu1
´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

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 9:30 pm
by ressi
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.

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 9:36 pm
by ressi
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. :( :(

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 10:37 pm
by Benj
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.

Re: Problem with DHT22

Posted: Tue Dec 20, 2016 11:18 pm
by ressi
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.

Re: Problem with DHT22

Posted: Wed Dec 21, 2016 4:29 pm
by jgu1
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

Re: Problem with DHT22

Posted: Wed Dec 21, 2016 5:54 pm
by ressi
With 18F46K22 with 64MHz it Workshops, BUT Minus degree Not work correct!

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 12:06 pm
by Benj
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.
DHT22.fcpx
(35.54 KiB) Downloaded 415 times

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 1:16 pm
by Benj
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.
DHT22.fcpx
(35.62 KiB) Downloaded 433 times
DHT11.fcpx
(35.5 KiB) Downloaded 469 times
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.

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 2:31 pm
by ressi
Hello. It Works great with 64MHz!!

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 2:46 pm
by ressi
With a 16F877A with 19.66Mhz always comes after a few seconds CRC Error

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 2:47 pm
by ressi
It looks like better to change to the XC8 Pro Compiler.

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 5:06 pm
by Benj
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.

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 6:10 pm
by ressi
After Christmas I will try the Pro compiler and you hear from me how it then works.

Thanks a lot Band marry christmas

Re: Problem with DHT22

Posted: Thu Dec 22, 2016 8:17 pm
by jgu1
Hi!
Just tested it with a Pic16f876, work perfect :D
Later I will test it with an Arduino and you hear.

Thank´s Ben

Br Jorgen

Re: Problem with DHT22

Posted: Sun Oct 15, 2017 2:01 pm
by mnf
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:
bluetooth1.fcfx
(14.36 KiB) Downloaded 314 times
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)

Re: Problem with DHT22

Posted: Mon Oct 16, 2017 10:43 am
by Benj
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.

Re: Problem with DHT22

Posted: Mon Oct 16, 2017 6:24 pm
by mnf
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