Pages: 1 ... 5 6 [7]   Go Down
Author Topic: Class for DHT11, DHT21 and DHT22 (temperature & humidity)  (Read 53220 times)
0 Members and 2 Guests are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Major update of the DHT library to version 0.1.10

+ improved the WAKEUPSIGNAL
    - 20 -> 18 milliseconds for the DHT11
    - 20 -> 1 millisecond for DHT21 / 22   
    this greatly reduces the blocking fetch from 25 -> 6 milliseconds  ( NOT for the DHT11 )

+ improved the TIMEOUT calculation to fail faster in case of time out
   (tested with no sensor connected to UNO)
   - version 0.1.09 - timeout took ~70.4  milliseconds
   - version 0.1.10 - DHT11 timeout takes ~20.1 milliseconds
   - version 0.1.10 - DHT22 timeout takes ~3.1 milliseconds
      partly of course because the wakeup for the DHT22 is  shorter!

+ some small coding style improvements.

links:
- http://playground.arduino.cc//Main/DHTLib -
- https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib - (code only)

As always comments and remarks are welcome.

Please let me know if the new timings has become too critical!
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

FYI
latest version  0.1.10  confirmed to work on
- UNO, MEGA2560, DUE
- Digistump Digix (84 MHz) - without a level shifter ! using the level shifter caused missing bits or time outs.

Code: (output DUE test)
DHT TEST PROGRAM
LIBRARY VERSION: 0.1.11

Type, status, Humidity (%), Temperature (C) Time (us)
DHT22, OK, 55.2, 21.0, 4705
DHT22, OK, 55.0, 21.0, 4406
DHT22, OK, 54.8, 21.0, 4315
DHT22, OK, 54.6, 20.9, 4361
DHT22, OK, 54.5, 21.0, 4360
DHT22, OK, 54.5, 21.0, 4364
DHT22, OK, 54.5, 21.0, 4367
DHT22, Time out error, -999.0, -999.0, 2640
DHT22, OK, 54.8, 21.0, 4309
DHT22, OK, 55.7, 21.0, 4216
DHT22, OK, 55.6, 21.0, 4108
...
Note the fetch time ~4.4 millis and a timeout  ~2.7 millis.

Note the 0.1.11 version is functional identical to 0.1.10 (not released)
« Last Edit: June 02, 2014, 02:15:46 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Full Member
***
Karma: 1
Posts: 155
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this lib also usable for the DHT33 ?

I found an interesting comparison of different temperature sensors: DHT11, DHT22, DHT33, DS18x20, TMP36, Thermistor 
http://playground.boxtec.ch/doku.php/sensors/temp-hum_sensors_compared

The authors point to your lib, Rob, and write "for all DHT sensors". They say also the DHT33 has a build in DS18B20 but I don't know if they uses a DS18B20-lib for reading DHT33's  temperature or your DHT33-lib for temperature and humidity.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link, indeed very interesting!

I am not familiar with the DHT33, do you have a link to a datasheet?
Then I can check if the data format is compatible with the DHT11-21-22 .
If so I can add it to the library,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

found datasheet for the DHT33 aka RHT04

- http://sensorguys.com/wp-content/uploads/2014/05/Digital-humidity-and-temperature-sensor-RHT04.pdf -

The OEM is here - http://www.humiditycn.com/ -

Handshake is similar to the DHT22 so you should be able to use the DHT33 (RHT04) by using the DHT22 calls.

nevertheless as it is a separate type I will update the library this week (if time permits)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There also exist a DHT44  - http://shop.boxtec.ch/digital-humidity-temperature-sensor-dht44-rht05-p-40846.html -

According to the site the DHTlib does works with it....  Time to rethink the library ...


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Full Member
***
Karma: 1
Posts: 155
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, Rob, to catch this also. Indeed it seems they have tested both, the
DHT33 and the DHT44 with your lib, for the last one they write expicitally "The DHT44 is fully compatible with the Arduini library linked below." Nice job to write working code for a pice you do not know that it exists! ;-)

There is also a dicussion about power saving techniques and the DS18B20 on https://lowpowerlab.com/forum/index.php/topic,219.msg1092.html#msg1092. Because the DHTxx-lib is working for the  DHT33, which has a DS18B20 built in the discussion could be interesting her also. About power saving--and using a power saving lib like LowPower http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/ or Narcoleptic https://code.google.com/p/narcoleptic/ -- you can read in the linked posting

Quote
For example, be sure to put the μC back to sleep while it waits the 750ms needed for the DS18B20s to do their 12-bit conversion, and make sure the DS18B20s all convert at the same time to minimise the number of times the μC has to wake-up.

Seems that you hitting the 750 ms massively with your lib. Or is "fetch time" and "timeout" an other concept than the "conversion time"? Your can read often about the 750 ms, but it is perhaps a conservative rough estimate or could you find any hinf for this in any datasheet?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Seems that you hitting the 750 ms massively with your lib. Or is "fetch time" and "timeout" an other concept than the "conversion time"? Your can read often about the 750 ms, but it is perhaps a conservative rough estimate or could you find any hinf for this in any datasheet?

That are typically things to find out when investigating such a sensor.

<warning assumptions ahead>

the DHT33 uses a 12 bit DS18B20 (needs 750 ms) but can be read by the DHTlib (~25 ms or even ~5ms),
how can one implement this:
1) keep on reading the DS18B20 sensor and return the last valid value as DHTxx  (not power efficient but fast)
2) the sensor starts a new DS18B20 read after the last value has been fetched (fast but the returned value might be outdated)
3) the DS18B20 is read when the DHT is asked for => a delay is needed.

So only an elaborate test will learn how the library could behave. Especially the last update of the lib which optimizes timing might be critical for the DS18 based sensors. We'll see.

« Last Edit: June 11, 2014, 01:27:45 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, Rob, to catch this also. Indeed it seems they have tested both, the
DHT33 and the DHT44 with your lib, for the last one they write expicitally "The DHT44 is fully compatible with the Arduini library linked below." Nice job to write working code for a pice you do not know that it exists! ;-)

Yesterday I contacted the people of - http://shop.boxtec.ch/temperature-c-39_71.html - and I just got an answer.

We are going to do additional testing for the DHT33 and DHT44 to optimize the support for these two "newbies" in the DHTlib.
So expect a new version of the DHTlib in 4-6 weeks (best guess).
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yesterday I got a DHT33 and a DHT44 from boxtec.ch  (thank you !) to test them and add support in the DHTlib. The sensors are also known as the RHT04 and RHT05.

The DHT33 just looks like the DHT22 from the outside, but where my DHT22 is white this one is grey. So far I found no difference while testing but as the DHT33 is DS18B20 based internally it might be more accurate. See the comparison paper mention above by Clemens.

The DHT44 is from the outside a quite different sensor. It includes  a wire 40 cm (1.3 ft) and two mounting options (one see picture below )

image courtesy boxtec.ch

First tests show both the sensors work very well with the latest version of the library, with the optimized wakeup timing.
So integrating them is not a hard job - to be released end next week I hope - but I have to think about the footprint of the lib.

As there are 4 sensors { 21, 22, 33, 44 } that work with identical code, and one that is different { 11 } So I want to make a generic DHT.read(pin) function, and still support the read11() read22() read21() methods. Probably add read33() and read44() for completeness. As the compiler only include the methods actually used this should not be a problem.

Work to be done smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Major update of the DHT library to version 0.1.13

Version 0.1.11 and 0.1.12 are development versions that are not archived.

+ added support for DHT33
+ added support for DHT44
+ added test sketches
+ refactored codestyle + footprint + interface (still backwards compatible)

links:
- https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib - (code only)

Note: playground version is not updated...

As always comments and remarks are welcome.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The playground is now also updated to the 0.1.13 version.
Note: the 0.1.11 and 0.1.12 version are not released (development versions)

Confirmed to work, also for negative temperatures (bug introduced in 0.1.12)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a problem with DHT22.
I have a DHT11 and DHT22, when I connect the circuit starts well DHT11, but DHT22 shows 0 Temp and 0 Humedity.
Only if I connect to the PC and ask the Arduino software that shows what you hear by the USB port, there begins Mega2560 and DHT22 begins to read well.

What I can do to solve this problem start?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What I can do to solve this problem start?
Some questions:

How do you power the Arduino if not connected to the PC?
Are there besides DHT11/22 other devices connected?
How are the DHT's connected? which pins?
Which version of the DHT library do you use? Adafruit? my DHT lib?


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connected 9v.
DS1302 and LCD TFT
DHT11 in pin 8 and DHT22 in pin 9
DHT-master.rar (Written by Mark Ruys)
Logged

Pages: 1 ... 5 6 [7]   Go Up
Jump to: