Wednesday, April 8, 2015

DHT 22 Humidity and Temperature Sensor

I bought a DHT 22 a while back from Adafruit for use on the Arduino and just got around to trying it on the MSP-EXP430F5529LP.  They supply a good write-up and a library for using it as well but it is another one of those libraries that almost, but not quite, works with Energia.  To make it work you need to do the following:

Inside the sketch itself you will need to adjust the "threshold for cycled for cycle counts".  The remarks state that the default is 6 which works with a 16mhz AVR.  It definitely does not work with the 430F5529.  I played around and ended up assigning with the following statement and seemed to get good results:

DHT dht(DHTPIN, DHTTYPE, 12);

It does bother me that I'm not really sure what this is doing or how it impacts results.  I compared it to what my local weather station was reporting and was within 1% but that is just one data point.

You will also need to make a change to DHT.cpp in the library.  There are function that attempt to return NAN (not a number).  The gcc compiler for the 430 does not like this.  I fixed it in a way I'm not too proud of.  Instead of return NAN, I used return 0/0 which of course is "not a number".  I could have used a negative number outside of normal values but that didn't seem right either since I didn't explore what the consequences of that might be.  This code needs to be cleaned up.

The Adafruit library does not calculate dew point and I wanted that.  It can be calculated from the August-Roche-Magnus approximation as follows:

td =243.04*(logf(h/100)+((17.625*t)/(243.04+t)))/(17.625-logf(h/100)-((17.625*t)/(243.04+t)));

Where:

td = dew point, degrees C
h = relative humidity, % from the DHT 22
t = air temperature, degrees C from the DHT 22





No comments:

Post a Comment