DHT11/22 sensor managed driver - Page 2 - Project Showcase - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DHT11/22 sensor managed driver


  • Please log in to reply
59 replies to this topic

#21 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 13 September 2012 - 03:00 PM

Look at the specs here:
http://learn.adafruit.com/dht
You are probably reading to fast/often

Sampling rate:
dht11: No more than 1 Hz sampling rate (once every second)
dht22: No more than 0.5 Hz sampling rate (once every 2 seconds)


Thanks for your reply neslekkin,
I didn't check in the code how often is reading the values from the sensor, I will check tonight that I get home but thanks for pointing that out.

#22 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 13 September 2012 - 03:06 PM

The pull-up resistor is mandatory, but you can use Netduino built-in one. There is parameter in the DHT sensor class constructor to specify that (PullUpResistor.Internal, External).

[/color][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font][/color]
Hm, I am not sure I understand - you get the exception even if you have the two pins connected together?


I have got similar reports from other NetduinoPlus users - I think the reason is that there are more interrupts on NetduinoPlus (e.g. network-related) that disturb the sensor communication.
[/size][/font][/size][/font][/size][/font]


Thanks for your reply CW2,

As suggested, I will use PullUpResistor.Internal in the class constructor instead.

Yes, I have the splitted wires coming from pin # 2 on the sensor going to D0 and D1 inputs and still get the error, however if I put the breakpoint the the CheckPins methods, then it works all the time, maybe a MF issue. I also noticed that if I don't run it in debug mode, all is fine, and I can tell that because I turn the blue built-in led when there is a good read and I turn it off when it fails to read its values.

I unplugged my network cable just in case but the issue persists, I am going to try neslekkin suggestion and see if reading the value every 2 seconds or longer intervals fixes the problem. I can't check the code right now because I am not at home, so I have to double check what interval you're using.

Thanks

#23 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 14 September 2012 - 02:00 AM

Quick update:

It doesn't make a difference if I use:

var dhtSensor = new Dht22Sensor(Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12, PullUpResistor.Internal);
or
var dhtSensor = new Dht22Sensor(Pins.GPIO_PIN_D11, Pins.GPIO_PIN_D12, PullUpResistor.External);

The error persist, the CheckPins method returns false in debugging mode all the time but like I mentioned before, if I put a breakpoint inside CheckPins then the program works fine by pressing F5 after the breakpoint is reached in the code. But again this is just in debugging mode. The program seems to be running fine if I just deploy it and run it in the N+.

Another thing I found out is that if I change the reading interval from what you have choosen which is 2 seconds to something either smaller or bigger, the readings are actually worst, it fails 90% of the time.

So, I guess I'll leave it the way it is but I don't understand the PullUpResistor thing. Any clues? Should I try a resistor from 3.3V to Data (signal)? What resistor should I use? As you may notice, I am using D11 and D12 inputs, would that be the problem?

Thank you


#24 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 16 September 2012 - 07:07 PM

I have been using the RHT03 sensor in my N+ for the last 3 days. Very often the sensor gets a negative reading of the temperature as shown in the COSM graph below. The himidity sometimes jumps really high but it is not as often as I get the negative temperature reading. Has someone experienced the same issue in the past? I am not using a resistor, would that fixed this issue?

Posted Image

#25 MrCalico

MrCalico

    New Member

  • Members
  • Pip
  • 2 posts
  • LocationLos Angeles, CA

Posted 16 October 2012 - 11:47 PM

Works Wonderfully on my Netduino Plus with the occasional checksum! Thank you for all the effort! :)

#26 Slayman

Slayman

    New Member

  • Members
  • Pip
  • 1 posts

Posted 01 December 2012 - 07:41 PM

Hello, First of all thank you for your code! This is my very first post here and I just received my very first N+2 and DHT11 yesterday. I have been a C# dev for 7 years but never done anything on the hardware side, so please excuse my complete ignorance :). I downloaded your code and wired everything as it was said to but I'm failing at DhtSensor.Read(), specifically at the dataReceived.WaitOne(50, false) if block. I have tried both PullUpResistor options Internal (without resistor) end external (with resistor), and also tried adjusting DhtSensor.BitThreshold at both 1050 and 1650. Any help or insight would be very helpful. Thanks In Advance Richard

#27 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 03 December 2012 - 08:10 AM

... N+2 and DHT11 yesterday. ... failing at DhtSensor.Read(), specifically at the dataReceived.WaitOne(50, false)...

Hm, WaitOne(...) failing means that not all pulses have been received successfully during the specified time. Just to be sure, are you using Dht11Sensor class? I have not tested the code on Netduino Plus 2, theoretically it should work without any changes. The best thing to do would be to check the sensor signal using a logic analyzer or an oscilloscope, but I guess you don't have access to them, so I would recommend checking the value of bitMask after WaitOne(...) call, it will contain binary number with '1' set at bit position that represent number of remaining edges (8 = 1000 binary -> 4 edges remaning, 4 = 100 binary -> 3 edges remaining, 2 = 10 binary -> 2 edges etc.; in simple math numberOfEdgesRemaining = log2(bitMask) + 1). You can try increasing the timeout value and see if the number in bitMask changes (decreases) - if yes, there is probably problem with timing on Netduino Plus 2, otherwise it could be that signal edges/pulses are not recognized correctly.

#28 zorlack

zorlack

    New Member

  • Members
  • Pip
  • 9 posts

Posted 27 December 2012 - 04:12 PM

Has anyone had problems getting this to work on N+2?

I'm using .NET 4.2, Netduino 4.2.1 and the internal Pull-Up resistor.

 

My DHT22 is connected as in the drawing:

  • Pin 1 -> 3.3V
  • Pin 2 -> GPIO 0 and 1
  • Pin 4 -> Gnd
     

When I run the example program I just get:

 

DHT sensor Read() failedDHT sensor data timeout.

 

Has anyone seen this?

 

Thanks very much!

 

-Z



#29 RonZon

RonZon

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationWaukesha, WI

Posted 30 December 2012 - 06:07 PM

I have a Netduino Plus 2 with 4.2.1.2 firmware, and was able to get this code working with the DHT11 sensor.

NO external pullup resistor necessary (website agrees with this)...

var dhtSensor = new Dht11Sensor(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, PullUpResistor.Internal);

 

I did, however, have to change (in DhtSensor.cs):

bitMask = 1L << 42;

to read:

bitMask = 1L << 41;

 

I tried changing other parameters, without any luck.  But this worked like a charm :-)

 

I also found that the check to see if the two pins were tied together would occassionally fail, especially if you do a reboot in software.

So, once I got it working,  I commented out the check:

  //if (!CheckPins())   //{   //   throw new InvalidOperationException("DHT sensor pins are not connected together.");   //}

 

 

I know the original post is older,  but THANKS to the poster !!!



#30 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 31 December 2012 - 12:23 PM

I did, however, have to change (in DhtSensor.cs): bitMask = 1L << 42; to read: bitMask = 1L << 41;

 

This change means there is one edge not detected or received, at the beginning of the communication (otherwise the data from the sensor would be corrupted). Unfortunately, I don't have Netduino Plus 2 to check whether this is a bug or just different behavior.

 

Thank you for posting that, and welcome to the community!



#31 plamb

plamb

    New Member

  • Members
  • Pip
  • 1 posts

Posted 06 January 2013 - 02:00 AM

Thanks zonfoto the dht11 now works with my netduino plus 2.



#32 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 20 February 2013 - 02:59 AM

the temperature that is being read seems to jump around a few degrees, between 71 and 75 degrees F, but the << 41 and setting the BitThreshold to 1150. leaving it at 1050 did not work. How do you get sensor pulse durations? can anyone point me to the correct resource on how to do that and using what kind of tool? I have not played with hardware/electronics in a very long time and I want to get my feet wet again.



#33 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 20 February 2013 - 06:31 AM

Thanks to zonfoto's suggestion (and also thanks to the original poster) my RHT03 (RHT-22 ) from Sparkfun(https://www.sparkfun.../products/10167) works like a charm in my N+2 and guess what I get good readings all the time every 2 seconds, something I couldn't accomplish in my N+, it would fail with either these two errrors below most of the time and sometimes reading negative values in it:

 

DHT sensor data has invalid checksum.

DHT sensor data timeout.

 

Attached is the code I use that maybe of some value to other members in the community.

Attached Files



#34 GenEric

GenEric

    New Member

  • Members
  • Pip
  • 2 posts

Posted 26 February 2013 - 08:12 PM

I tried the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;] [/color]NetduinoPlus2RHT03.zip[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]  [/color]94.78K[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]  [/color]2 downloads

 

It reads:

The thread '<No Name>' (0x2) has exited with code 0 (0x0).

DHT sensor data timeout.
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, etc etc etc
untill i unplug and replug pin D1, while running!
And then it reads:
DHT sensor data timeout.
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, etc etc
Can hardly do that every run:)
 

Does anyone have any clue what that's about?



#35 Jakkes

Jakkes

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 February 2013 - 09:36 PM

The code[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;] [/color]NetduinoPlus2RHT03 on a N+2 with firmware .NET 4.2.2.2 and no resistor works like charm. No faulty values at all.

 

Thnx for sharing.



#36 Casmer

Casmer

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationGrant, FL

Posted 01 March 2013 - 02:16 PM

Eventually it just started working for me on my Net Duino Plus 2 on 4.2, maye a connection on my breadboard was loose.



#37 garymscott

garymscott

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 March 2013 - 01:26 PM

I tried the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;] [/color]NetduinoPlus2RHT03.zip[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]  [/color][color=rgb(119,119,119);font-family:helvetica, arial, sans-serif;]94.78K[/color][color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]  [/color][color=rgb(164,164,164);font-family:helvetica, arial, sans-serif;]2 downloads[/color]

 

[color=rgb(164,164,164);font-family:helvetica, arial, sans-serif;]It reads:[/color]

The thread '<No Name>' (0x2) has exited with code 0 (0x0).

DHT sensor data timeout.
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, etc etc etc
untill i unplug and replug pin D1, while running!
And then it reads:
DHT sensor data timeout.
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, etc etc
Can hardly do that every run:)
 

Does anyone have any clue what that's about?

 

Firstly, Giuliano - thank you for kindly posting the code to get the RHT03 running! I am able to get readings but only after pulling pin D1 out and then re-inserting it as described by GenEric :( Does anybody have any ideas why this is happening?

 

I am using a Netduino Plus 2 (latest firmware and SDK) with the RHT03 sensor. I have the pull up resistor set to internal.

 

Cheers



#38 Fred Werneck

Fred Werneck

    New Member

  • Members
  • Pip
  • 3 posts

Posted 15 April 2013 - 07:28 PM

I tried the [font="helvetica, arial, sans-serif;color:rgb(40,40,40);"] [/font]NetduinoPlus2RHT03.zip[font="helvetica, arial, sans-serif;color:rgb(40,40,40);"]  [/font][font="helvetica, arial, sans-serif;color:rgb(119,119,119);font-size:12px;"]94.78K[/font][font="helvetica, arial, sans-serif;color:rgb(40,40,40);"]  [/font][font="helvetica, arial, sans-serif;color:rgb(164,164,164);font-size:12px;"]2 downloads[/font]

 

[font="helvetica, arial, sans-serif;color:rgb(164,164,164);font-size:12px;"]It reads:[/font]

The thread '<No Name>' (0x2) has exited with code 0 (0x0).

DHT sensor data timeout.
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, Temp = 0.0°C 32.0°F
DHT sensor Read() ok, RH = 0.0%, etc etc etc
untill i unplug and replug pin D1, while running!
And then it reads:
DHT sensor data timeout.
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.0%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, Temp = 23.6°C 74.5°F
DHT sensor Read() ok, RH = 30.2%, etc etc
Can hardly do that every run:)
 

Does anyone have any clue what that's about?

 

I have this issue too, but on Read() of DhtSensor.cs i put a verification:

 

 

if(checksum == (byte)(data & 0xFF))

{

dataValid = true;

if (bytes[0] == 0)

portIn.DisableInterrupt();

else

Convert(bytes);

}

else

{

Debug.Print("DHT sensor data has invalid checksum.");

}



#39 @LLmIxEdUp

@LLmIxEdUp

    New Member

  • Members
  • Pip
  • 2 posts

Posted 03 May 2013 - 07:00 AM

First thanks to CW2 for this project. I have some observations to make. I am using a Netduino Plus 2 with the supplied project. Note that the SecretLabs.NETMF.Hardware include for this project is for 'Netduino'. This seems to cause problems with other functionality if using the Plus 2. (for example using the SD card).

 

I was able to resolve this by referencing and including both SecretLabs.NETMF.Hardware.Netduino and SecretLabs.NETMF.Hardware.NetduinoPlus in my project. Naturally, this caused namespace conflicts which I resolved by providing the full class names in some of the constructors. For example:

 

static Dht22Sensor RHT03 = new Dht22Sensor(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D0, SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D1, PullUpResistor.Internal);

 

Using the NetduinoPlus libraries in this statement resulted in 'DHT sensor timeout' errors. Changing to the Netduino library fixed it.

 

I leave the implications of this behaviour to others who are more knowledgeable, but it seems a little odd to me. Nevertheless, I hope this helps any others who run into oddities when using Netduino Plus with this really excellent contribution from CW2 et al.



#40 @LLmIxEdUp

@LLmIxEdUp

    New Member

  • Members
  • Pip
  • 2 posts

Posted 03 May 2013 - 07:14 AM

Oops! A correction. I am using the NetduinoPlus2RHT03.zip project submitted by Giuliano. It worked as posted. However but I ran into problems when adding functionality for SD card writing. The SD problem was resolved by including the NetduinoPlus libraries instead of the Netduino ones. However, this then broke the sensor functionality. My solution to the problem was as posted above. Sorry if this is a bit muddled.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.