Skip to main content

You are here

DHT22 Library

3 posts / 0 new
Last post
DHT22 Library


Been spending some time reading your blog, it has been very interesting. Nice work.

I am at the moment redeveloping my weather station after my SHT11 failed. I am changing it so that I have an external sensor section and a base station. I am using cheap rf link. The aim is to run the external section on batteries with either an ATTiny45 or 84.

I got a DHT22 and tried the jeelabs example for the sensor, but it was returning the incorrect values. I tried other libraries and the values returned are correct, so it is not the sensor at fault. As far as I can tell.

I had a look in the ports library and think the problem is in this line.

Line 1017 humi = ((h >> 3) * 5) >> 4; // careful with overflow


Line 1021 temp = ((t >> 3) * tmul) >> 4; // careful with overflow

At the moment I have changed them to temp = t and humi = h

I think it is shifting to many bits right?




Indeed - looks like these calculations are wrong.

That's a heavy bag of tricks, BTW. Same as "((h / 8) * 5) / 16", which translates to: drop the last hex digit and convert the other one from hex (i.e. BCD) to decimal. On a DHT11, the lower 4 bits are 0, but on a DHT22 they aren't always and causing trouble. Never tried this with a DHT22, I must admit.

Trying to be too clever was not so wise after all!


Thanks for getting back. I'll stick with my mod for now.


Premium Drupal Themes by Adaptivethemes