Problem with DHT22

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Problem with DHT22

Post 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?
Attachments
DHT22_Example_v7.fcfx
(8.07 KiB) Downloaded 430 times

User avatar
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

Post by Benj »

I'll dig out a DHT22 today and see if I can replicate the problems you're having.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Problem with DHT22

Post 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
Attachments
DHT22_ExampleNot.fcfx
(8.31 KiB) Downloaded 372 times

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post by ressi »

Hallo benj.
There is already a solution with the
Component macro?
User jgu1 has the same problem!!

User avatar
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

Post by Benj »

Hello,

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

User avatar
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

Post 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.

User avatar
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

Post 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 468 times
Here's the same fix for the DHT11 component.
DHT11.fcpx
(35.41 KiB) Downloaded 430 times
Here's a slightly improved test file.
DHT22_Example_v7.fcfx
(9.55 KiB) Downloaded 513 times
Let me know how you get on.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Problem with DHT22

Post 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

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post 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.

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post 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. :( :(

User avatar
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

Post 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.

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post 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.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Problem with DHT22

Post 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

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post by ressi »

With 18F46K22 with 64MHz it Workshops, BUT Minus degree Not work correct!
Attachments
20161221_173628.jpg
(191.51 KiB) Downloaded 1887 times

User avatar
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

Post 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 292 times

User avatar
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

Post 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 354 times
DHT11.fcpx
(35.5 KiB) Downloaded 340 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.

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post by ressi »

Hello. It Works great with 64MHz!!
Last edited by ressi on Thu Dec 22, 2016 2:46 pm, edited 1 time in total.

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post by ressi »

With a 16F877A with 19.66Mhz always comes after a few seconds CRC Error

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post by ressi »

It looks like better to change to the XC8 Pro Compiler.

User avatar
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

Post 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.

ressi
Posts: 21
Joined: Fri Mar 25, 2016 6:05 pm
Been thanked: 14 times
Contact:

Re: Problem with DHT22

Post 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

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Problem with DHT22

Post 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

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Problem with DHT22

Post 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 197 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)

User avatar
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

Post 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.

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Problem with DHT22

Post 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
Attachments
dht22.png
(119.18 KiB) Downloaded 5326 times

Post Reply