more G-Labs products

Author Topic: DHT-22 Temperature & Humidity Sensor not working (difference between DHT-11?)  (Read 13372 times)

July 11, 2014, 05:52:42 PM
Read 13372 times

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


I just bought the DHT-22 Temprature and Humidity Sensor (the DHT-11 is hard to find in Belgium) following the Adafruit Lessons.

First I looked up the difference between the two sensors and accoring tot Adafruit they are about the same except that the DHT-22 is more precise. (https://learn.adafruit.com/dht/overview)

Then I followed the exat procedure to connect them to the raspberry pi using http://learn.adafruit.com/downloads/pdf/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.pdf and http://www.homegenie.it/docs/doityourself.php. Both documents follow the same wiring except the Homegenie tutorial doesnt use a pullup resistor.

When I'm testing in Raspbian the testprogram works fine and I get a nice readout :

Code: [Select]
pi@homegenie ~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 22 4
Temp=25.9*C  Humidity=61.3%

Unfortunately activating the DHT-11 program in Homegenie does nothing. First I don't know where to look for the readouts? So I added a Program.Notify() to display hum, tempc and tempf but it is never executed. The program is running without any errors (green lamp) but somehow it does nothing... I even tried without the pullup resistor but I get exactly the same problem.

Does anyone know what is the program difference for both Sensors?


Thanks,
Christophe

July 11, 2014, 06:14:21 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I have not used the DHT-22, only DHT-11.  Also, my experience is with the Arduino and not Raspberry Pi.  However, from what I recall they are very similar as far as how you interface with them.  They have the same pinout and the code (for Arduino anyway) is packaged together.  In the Ardiuno libraries the only difference between the two on the user side is that you need to specify DHT11 or DHT22 when you initialize things.  I don't know at this point, but I suspect the primary difference that might give you issues is that they may respond with some kind of sensor identifier when it initializes and that might cause issues.

July 11, 2014, 06:20:26 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
From the Arduino Playground:

http://playground.arduino.cc/Main/DHTLib

Quote
The DHT21/22 is quite similar to the DHT11 and has a greater accuracy (one decimal) and range (negative temperatures). The hardware pins and handshake are identical but it uses a different data format.


So, The problem is the data being sent back is different.

July 11, 2014, 08:12:53 PM
Reply #3

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi,


Thank you for your reply,

I was using these files already to figure out what is different.

The first thing I noticed in the datasheets is that the start command bit should be at least 500 microseconds low for the DHT-22 while for the DHT-11 it is only a minimum of 80 microseconds low.
Homegenie is programmed to Pause(0,0096) which for me is 9600 microseconds wich should be enough.

What I can figure out from the arduino code is that the return data is both the same but that it needs to be calculated in a different way for the DHT-22.

Actually The homegenie code is entirely based on the arduino code and uses the same structures. I just dont know why i get no output...
The if condition of (if ((j >= 40) && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) )) always returns false resulting in a 2 second pause to retry again.

I'll post the result if i'm able to solve the problem.


July 12, 2014, 12:19:08 AM
Reply #4

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
Hi


I evaluated the output before the if condition of (if ((j >= 40) && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) )) :
It seems that j is almost never reaching 40 (39 is common) and if it does the checksum isnt correct.
The algorythm seems to be about the same as the arduino on so I still have no clue why the condition doesnt trigger a true.

I can understand that when it does trigger a true, the reading won't be right as for the DHT-22 you need to do some extra calculations but for now I cannot get any output...


PROGRAM CODE

Code: [Select]
...
Program.Notify("DHT-22", "COUNT J : " + j + " -> DATA : " + data[0]  + " / " + data[1]  + " / " + data[2]  + " / " + data[3] + " = " + data[4]  );
     
if ((j >= 40) && (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) ) 
{
      //do something with the data
}   
else
{
      Pause(2);
      Program.Notify("DHT-22", "Problem / Pause 2 seconds");
}



OUTPUT

Code: [Select]
00:04:42.385 DHT-22 Program Started 70 HomeAutomation.HomeGenie.Automation
00:04:32.384 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:30.383 DHT-22 COUNT J : 39 -> DATA : 15 / 255 / 255 / 231 = 127 70 HomeAutomation.HomeGenie.Automation
00:04:30.108 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:28.107 DHT-22 COUNT J : 39 -> DATA : 255 / 255 / 255 / 255 = 126 70 HomeAutomation.HomeGenie.Automation
00:04:27.831 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:25.826 DHT-22 COUNT J : 37 -> DATA : 9 / 152 / 8 / 51 = 12 70 HomeAutomation.HomeGenie.Automation
00:04:25.550 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:23.549 DHT-22 COUNT J : 39 -> DATA : 4 / 170 / 2 / 10 = 101 70 HomeAutomation.HomeGenie.Automation
00:04:23.274 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:21.273 DHT-22 COUNT J : 37 -> DATA : 9 / 184 / 8 / 42 = 31 70 HomeAutomation.HomeGenie.Automation
00:04:20.991 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:18.990 DHT-22 COUNT J : 39 -> DATA : 4 / 160 / 2 / 10 = 88 70 HomeAutomation.HomeGenie.Automation
00:04:18.715 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:16.714 DHT-22 COUNT J : 38 -> DATA : 9 / 52 / 4 / 21 = 21 70 HomeAutomation.HomeGenie.Automation
00:04:16.438 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:14.438 DHT-22 COUNT J : 39 -> DATA : 4 / 154 / 2 / 2 = 85 70 HomeAutomation.HomeGenie.Automation
00:04:14.162 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:12.161 DHT-22 COUNT J : 38 -> DATA : 9 / 56 / 4 / 21 = 22 70 HomeAutomation.HomeGenie.Automation
00:04:11.886 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:09.885 DHT-22 COUNT J : 38 -> DATA : 19 / 255 / 132 / 25 = 23 70 HomeAutomation.HomeGenie.Automation
00:04:09.575 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:07.574 DHT-22 COUNT J : 39 -> DATA : 4 / 156 / 2 / 10 = 82 70 HomeAutomation.HomeGenie.Automation
00:04:07.298 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:05.298 DHT-22 COUNT J : 38 -> DATA : 4 / 156 / 2 / 9 = 23 70 HomeAutomation.HomeGenie.Automation
00:04:05.22 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:03.6 DHT-22 COUNT J : 39 -> DATA : 4 / 156 / 2 / 10 = 22 70 HomeAutomation.HomeGenie.Automation
00:04:02.731 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:04:00.730 DHT-22 COUNT J : 38 -> DATA : 1 / 56 / 4 / 21 = 22 70 HomeAutomation.HomeGenie.Automation
00:04:00.454 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:58.454 DHT-22 COUNT J : 39 -> DATA : 4 / 156 / 2 / 10 = 86 70 HomeAutomation.HomeGenie.Automation
00:03:58.178 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:56.177 DHT-22 COUNT J : 39 -> DATA : 4 / 156 / 2 / 8 = 86 70 HomeAutomation.HomeGenie.Automation
00:03:55.902 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:53.901 DHT-22 COUNT J : 39 -> DATA : 4 / 156 / 2 / 10 = 86 70 HomeAutomation.HomeGenie.Automation
00:03:53.626 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:51.624 DHT-22 COUNT J : 26 -> DATA : 0 / 8 / 42 / 2 = 0 70 HomeAutomation.HomeGenie.Automation
00:03:51.344 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:49.269 DHT-22 COUNT J : 39 -> DATA : 4 / 140 / 2 / 10 = 86 70 HomeAutomation.HomeGenie.Automation
00:03:48.994 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:46.993 DHT-22 COUNT J : 38 -> DATA : 9 / 60 / 4 / 21 = 23 70 HomeAutomation.HomeGenie.Automation
00:03:46.717 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:44.717 DHT-22 COUNT J : 39 -> DATA : 4 / 158 / 2 / 10 = 87 70 HomeAutomation.HomeGenie.Automation
00:03:44.425 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:42.425 DHT-22 COUNT J : 39 -> DATA : 191 / 255 / 255 / 255 = 127 70 HomeAutomation.HomeGenie.Automation
00:03:42.149 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:40.148 DHT-22 COUNT J : 38 -> DATA : 4 / 158 / 12 / 21 = 23 70 HomeAutomation.HomeGenie.Automation
00:03:39.873 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:37.872 DHT-22 COUNT J : 40 -> DATA : 4 / 156 / 2 / 10 = 175 70 HomeAutomation.HomeGenie.Automation
00:03:37.597 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:35.596 DHT-22 COUNT J : 39 -> DATA : 4 / 158 / 2 / 10 = 87 70 HomeAutomation.HomeGenie.Automation
00:03:35.320 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:33.319 DHT-22 COUNT J : 38 -> DATA : 4 / 188 / 4 / 21 = 23 70 HomeAutomation.HomeGenie.Automation
00:03:33.44 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:31.43 DHT-22 COUNT J : 39 -> DATA : 4 / 160 / 2 / 10 = 88 70 HomeAutomation.HomeGenie.Automation
00:03:30.768 DHT-22 Problem / Pause 2 seconds 70 HomeAutomation.HomeGenie.Automation
00:03:25.385 DHT-22 Program Started 70 HomeAutomation.HomeGenie.Automation


July 12, 2014, 12:31:11 AM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Documentation for the DHT11 says you can't poll the unit more than 1/second (if I remember correctly).  Your code considers the pause an error, but I believe it is mandatory.  My DHT11's reply with the same data if polled too quickly if I remember correctly.  There is also a delay between initialization and the first poll which is probably why the error after "Program Start".

July 12, 2014, 10:18:15 AM
Reply #6

Boeky

  • **
  • Information
  • Jr. Member
  • Posts: 31
If you look at the code you need two conditions in order to do something with the received data :
1) j schould be 40 or higher which is almost never the case in the 30 times try cycle
2) the sum of data 0,1,2,3 & 0xFF should be the same as data 4 : the very few times j is 40 the checksum is not correct.

Indeed the Pause(2) is not really an error. It is the waiting time to start the next polling algorythm but the program always enters this part of the if, else block. The condition never returns true in 30 attempts.

You can poll the DHT-11 at 1Hz so that is once every second. The pause is 2 seconds so that should be enough for a DHT-11.
But the DHT-12 you can only poll at a rate of 0.5 Hz which means once every 2 seconds. Maybe the Pause(2) is too short...

I'll continue looking for a solution...

July 12, 2014, 04:51:03 PM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
If you poll too soon, I believe it simply does not respond.  If you poll again after the poll rate, it will respond correctly.  There is no benefit to polling too quickly, but it shouldn't cause issues for the DHT22 either.

November 05, 2014, 01:53:35 AM
Reply #8

Luca

  • *
  • Information
  • Newbie
  • Posts: 11
Bkenobi is right. DHT22 is working fine on my rasp, Simply poll DHT22 slowly

Please note that using the DHT11 program I always had -3°C as output because data is coded in a different way from DHT11.

I'm testing the program, if it works I'll post here

Have a fun
L.

November 05, 2014, 05:07:17 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
One other thing I wanted to note.  In the case of my DHT11 modules (I have 6), there was a notable offset between the different units when located next to each other.  I found that the temperature could vary by 2-3°F and ~10%RH from unit to unit.  For my use, I collected data for all sensors in a variety of environments that would book end my use conditions (approximately 32-90°F, 0-100%RH).  I selected the 3 modules that matched the best and added offsets in my code to make the data match better.

If your installation is not relative (one unit compared to another) and the exact set point is not sensitive, you should be able to ignore this.  Also, DHT22 are supposed to be more accurate so HOPEFULLY this won't be an issue.

Be aware that these sensors can fail, though I don't recall the MTBF.  If they do, your code might see error values that you are not currently looking for.

November 05, 2014, 11:03:48 PM
Reply #10

Luca

  • *
  • Information
  • Newbie
  • Posts: 11
Hi Bkenobi,

Temperature offset matches with DHT11 datasheet because the worst accuracy value is +-2°C  around +-3.6 °F with 1 °C resolution...

About RH the accuracy is +-5% so teoretically you could find 10% between two sensors
This value increase when you are out of best working conditions, for example getting data at 32°F with RH < 30% could have more that 10% of discrepancy

that's the reason I choose DHT22 looking for +-0.5°C accuracy value

At the end DHT11 is cheap and easy to use but is not for high precision data
IMHO +-2 °C are too much for the home heating system (expecially for MY home :-D )

this is the program I used

http://www.homegenie.it/forum/index.php?topic=448.0

Cheers
L.
« Last Edit: November 05, 2014, 11:55:06 PM by Luca »

November 11, 2014, 07:54:20 PM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Yes, the DHT11's were within spec.  What I wasn't expecting was that they would vary significantly from one to the next.  But, as I mentioned, by simply adding an offset from what was read by the sensor, I was able to get them to work in my implementation.  I was actually only using them cause they were cheap and readily available.  But, My end goal was originally to replace them with either DHT22 or a much higher quality variant in the $50/each price range (lots more than $1/each DHT11's).  I found that by using the offset to match sensors, I got what I needed without having to invest in expensive sensors.  If/when these ones start to fail I will re-evaluate.

November 17, 2014, 07:08:54 PM
Reply #12

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
I'm running on a rPi B+ using the Homegenie image.  I imported the DHT-22 app (THANKS!), wired up the DHT-22 and I can't get more than 52 bits read in (looking at the 0 to 85 i counter).  I tried the Adafruit program outside of HG and it reads fine.  Is the rPi B+ too slow, is HG getting interrupted too much, am I doing something wrong?

Any help would be greatly appreciated!

Thanks,
JohnS

November 22, 2014, 07:17:36 PM
Reply #13

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
I was unable to get my rPi to read more than ~50 bits of data from my DHT-22.  Looking at the output from the DHT22 through an oscilloscope, the DHT22 was working perfectly so it appears that perhaps the C# app through HG is being interrupted and missing bits when reading in the tight loop.  The Adafruit code (set up as in http://learn.adafruit.com/downloads/pdf/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.pdf) worked perfectly every time.  So I opted to use the Adafruit code and call it from HG and process the output.  I'm using code I found on the web and modified.  I've attached the app, as it appears from prior posts that at least one other person has a similar issue to the one I encountered.  In addition, the code demonstrates how to execute a shell command and retrieve the output so if there are other programs or commands I need to execute outside of HG, this is one way to do it.  Hope it's useful to somebody.
- JohnS

November 28, 2014, 11:31:08 PM
Reply #14

Luca

  • *
  • Information
  • Newbie
  • Posts: 11
>In addition, the code demonstrates how to execute a shell command and retrieve the output
>so if there are other programs or commands I need to execute outside of HG,
>this is one way to do it

really many thanks !!!!

L.