Jump to content
MORA99

[Energia Library] DHT11 / DHT22 Temperature and Humidity Sensors

Recommended Posts

  • A library for reading dht sensors (temperature and humidity).
  • Since dht sensors are pretty slow, I have used highlevel functions in the lib, there should be plenty of cycles even at 1MHz, but I have only tested it on the CC3200 sofar.

Easy example, other functions are available for getting the raw values instead of float.

  if (dht::readFloatData(2, &temperature, &humidity, true) == 0)
  {
    Serial.print("T: ");
    Serial.print(temperature);
    Serial.print(" H: ");
    Serial.println(humidity);    
  }  
  

Zip file included, source code lives at https://github.com/MORA99/Stokerbot/tree/master/Libraries/dht

 

Note: This lib requires working micros, delayMicroseconds and pulseIn functions, if you are using it on CC3200 you may need to patch your Energia installation.

dht.zip

Share this post


Link to post
Share on other sites

Hi MORA99 , I have tried your DHT lib with a DHT22 on a CC3200 and it is not functioning . After reading one more time your post here, I noticed the small letters note, where you say:   "This lib requires working micros, delayMicroseconds and pulseIn" 

What do you mean with this note ? What modifications are needed to make it function ?

Thanks in advance 

Share this post


Link to post
Share on other sites

Hi MORA99 , I have tried your DHT lib with a DHT22 on a CC3200 and it is not functioning . After reading one more time your post here, I noticed the small letters note, where you say:   "This lib requires working micros, delayMicroseconds and pulseIn" 

What do you mean with this note ? What modifications are needed to make it function ?

Thanks in advance 

It means you are supposed to have a sketch framework (Energia or CCS sketch) running, and have not tampered with either of these functions.

He also states that for the CC3200 you may have to get things working, I suppose they're not working out of the box with Energia...

Share this post


Link to post
Share on other sites

Note for future, the current Energia release mentioned above is release 13.

 

Link to similar library: There is another DHT22 library, targeted at the MSP430.

 

http://forum.43oh.com/topic/2865-energia-library-dht22-temp-rh-one-wire-sensor/

 

There have been some efforts to adapt it to the Stellaris LP.

http://forum.43oh.com/topic/2239-solved-dht22-temp-rh-one-wire-sensor-on-energia/page-3

Share this post


Link to post
Share on other sites

anyone noticed that with version 13 the sample libraries for DHT11, which perfectly worked with version 12, doesn't work anymore with 13? talking about the samples for arduino from DFrobot wiki page ...

 

the project is verified, downloaded, but the values from the sensors are something strange. 

 

I tried again with version 12 and it is working good.

 

didn't go in the details why, but something changed with version 13.

 

regards

Share this post


Link to post
Share on other sites

anyone noticed that with version 13 the sample libraries for DHT11, which perfectly worked with version 12, doesn't work anymore with 13? talking about the samples for arduino from DFrobot wiki page ...

 

the project is verified, downloaded, but the values from the sensors are something strange. 

 

I tried again with version 12 and it is working good.

 

didn't go in the details why, but something changed with version 13.

 

regards

 

Would help to mention what platform you are using (MSP430, Tiva, C2k) - obviously not the CC3200, since not supported in 12.

 

(On Tiva would think that the problems with the Energia delay routines might be an issue, and would suggest using the patch.  However that would also be true of version 12.)

Share this post


Link to post
Share on other sites

hi,

i am using the library which is  posted above.since u mentioned energia version 12 i downloaded that.but the problem is i don't see anything in my serial monitor window.i tried with both version 13 and verison 12 of energia but nothing worked out for me.you did not mention any pin numbers.can you help my telling me  what changes i need to do so that it  works on any of the port.for example  can know how i can change it to read data from pin 1.7(port 1 pin 7).

 

Thank you

 

ps:i am a newbie to energia so my questions seems weird.i am sorry for that.

Share this post


Link to post
Share on other sites

So, time has gone by bugs have been fixed and I was trying the DHT code with my CC3200 and DHT11. 

Energia Version 0101E0014 and I'm not able to get the sensor to work.

 

It seems to work ok with the DHT11 if you change true to false.

Share this post


Link to post
Share on other sites

So, time has gone by bugs have been fixed and I was trying the DHT code with my CC3200 and DHT11. 

Energia Version 0101E0014 and I'm not able to get the sensor to work.

 

It seems to work ok with the DHT11 if you change true to false.

static int8_t readFloatData(unsigned char pin, float *temperature, float *humidity, boolean dht22);

 

The true/false is to set if the sensor is a dht11 or dht22, so thats intended.

The main difference is precision and the dht11 requires a bit more delay.

Share this post


Link to post
Share on other sites

 

  • A library for reading dht sensors (temperature and humidity).
  • Since dht sensors are pretty slow, I have used highlevel functions in the lib, there should be plenty of cycles even at 1MHz, but I have only tested it on the CC3200 sofar.

Easy example, other functions are available for getting the raw values instead of float.

  if (dht::readFloatData(2, &temperature, &humidity, true) == 0)
  {
    Serial.print("T: ");
    Serial.print(temperature);
    Serial.print(" H: ");
    Serial.println(humidity);    
  }  
  

Zip file included, source code lives at https://github.com/MORA99/Stokerbot/tree/master/Libraries/dht

 

Note: This lib requires working micros, delayMicroseconds and pulseIn functions, if you are using it on CC3200 you may need to patch your Energia installation.

 

 

Hello, Mora. I tried your library and found that code does not works properly all the time.

 

After system was powered up, few readings is OK and after that readFloatData() and readRawData() returns error (on my MSP430G2553 Launch pad).

 

I fixed this problem and also added two classes which buffers data from DHT22 and saves them in the internal memory. So, when you want get data faster than 1 time per 2 seconds (for DHT22) data will be returned from internal memory.

 

How can I send this fixes to you? Do you want them?

Share this post


Link to post
Share on other sites

Very nice, I noticed that I get quite a few errors on dht in my project, but I sleep the chip alot so didnt investigate it much.

 

You can send the changes to me by mail if you like, and I will update the github/lib.

Share this post


Link to post
Share on other sites

Very nice, I noticed that I get quite a few errors on dht in my project, but I sleep the chip alot so didnt investigate it much.

 

You can send the changes to me (jkn@air-port.dk) by mail if you like, and I will update the github/lib.

 

Hello. I sent you all data. Please, tell me if you like it :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×