Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHT11 not working #748

Closed
tshaug opened this issue Sep 29, 2019 · 10 comments
Closed

DHT11 not working #748

tshaug opened this issue Sep 29, 2019 · 10 comments
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio bug Something isn't working

Comments

@tshaug
Copy link

tshaug commented Sep 29, 2019

Describe the bug

Hi everybody,

I installed the latest version of system.Device.GIO (v.1.0.0) and Iot.Device.Bindings (1.0.0)
Reading the DHT11 fails using the mentioned assemblies and .NET core 2.2 and 3.0

I used two different breakout boards (have DHT11 each). I have been using them with WIndows IOT so they could be "ok" (regarding the wiring).

I always receive no temp and humidity and IsLastReadSuccessful is always false.
I randomly receive results, like this (5 seconds delay between each measurement):
Guiding Proxy Console 1.2
Temp: NaN
Humi: NaN
ok?: False

Temp: NaN
Humi: NaN
ok?: False

Temp: 23
Humi: 44
ok?: True

Temp: 23
Humi: 44
ok?: True

Temp: 23
Humi: 44
ok?: True

Temp: 23
Humi: 44
ok?: True

Temp: 23
Humi: 44
ok?: True

Temp: NaN
Humi: $NaN
ok?: False

Temp: 23
Humi: 44
ok?: True

Temp: NaN
Humi: NaN
ok?: False

Any ideas?

Thank you very much!
Thomas

Steps to reproduce

  using (Dht11 dht = new Dht11((4), PinNumberingScheme.Logical))
            {
                for (int i = 0; i < 3; i++)
                {
                    Temperature temperature = dht.Temperature;
                    double humidity = dht.Humidity;

                    Console.WriteLine($"Temp: {temperature.Celsius}");
                    Console.WriteLine($"Humi: {humidity}");
                    Console.WriteLine($"ok?: {dht.IsLastReadSuccessful}");
                    Thread.Sleep(5000);

                }
            }

Expected behavior

print temp and humidity

Actual behavior

Temp: NaN
Humi: NaN

(same behaviour for .NET Core 2.2 and 3.0)

Versions used

Add following information:

  • dotnet on rasppi 3:
    2.2 and 3.0

2.2
.NET Core SDK (reflecting any global.json):
Version: 2.2.102
Commit: 96ff75a873

Runtime Environment:
OS Name: raspbian
OS Version: 9
OS Platform: Linux
RID: linux-arm
Base Path: /home/pi/dotnet/sdk/2.2.102/

 Host (useful for support):
    Version: 2.2.1
    Commit:  878dd11e62

    .NET Core SDKs installed:
     2.2.102 [/home/pi/dotnet/sdk]

   .NET Core runtimes installed:
         Microsoft.AspNetCore.All 2.2.1 [/home/pi/dotnet/shared/Microsoft.AspNetCore.All]
         Microsoft.AspNetCore.App 2.2.1 [/home/pi/dotnet/shared/Microsoft.AspNetCore.App]
        Microsoft.NETCore.App 2.2.1 [/home/pi/dotnet/shared/Microsoft.NETCore.App]

.NET Core 3.0
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-rc1-014190
Commit: c4d43f672d

Runtime Environment:
     OS Name:     raspbian
     OS Version:  9
     OS Platform: Linux
     RID:         linux-arm
     Base Path:   /home/pi/dotnet3/sdk/3.0.100-rc1-014190/

     Host (useful for support):
        Version: 3.0.0-rc1-19456-20
        Commit:  8f5d7b1ba4

      .NET Core SDKs installed:
          3.0.100-rc1-014190 [/home/pi/dotnet3/sdk]

       .NET Core runtimes installed:
            Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 
            [/home/pi/dotnet3/shared/Microsoft.AspNetCore.App]
             Microsoft.NETCore.App 3.0.0-rc1-19456-20 [/home/pi/dotnet3/shared/Microsoft.NETCore.App]

Build machine:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

  Runtime Environment:
        OS Name:     Windows
        OS Version:  10.0.17763
        OS Platform: Windows
        RID:         win10-x64
       Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

    Host (useful for support):
      Version: 3.0.0
      Commit:  7d57652f33

       .NET Core SDKs installed:
           2.1.701 [C:\Program Files\dotnet\sdk]
           2.1.801 [C:\Program Files\dotnet\sdk]
           2.1.802 [C:\Program Files\dotnet\sdk]
           2.2.301 [C:\Program Files\dotnet\sdk]
           2.2.401 [C:\Program Files\dotnet\sdk]
           2.2.402 [C:\Program Files\dotnet\sdk]
           3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • Version of System.Device.Gpio package = 1.0.0
  • Version of Iot.Device.Bindings package = 1.0.0
@tshaug tshaug added the bug Something isn't working label Sep 29, 2019
@krwq
Copy link
Member

krwq commented Sep 30, 2019

Yes, 1-wire currently does not work too well. I believe we will need to fix this first though: #197 and then update DHT code

@tshaug
Copy link
Author

tshaug commented Sep 30, 2019

Good morning Krzysztof,

thank you for your feedback.
The referenced item 197 is quite old.
is there already somne rough idea when an updated 1.wire implementartion will be released (even i beta) I am happy to test ;-)

Cheers
Thomas

@krwq
Copy link
Member

krwq commented Sep 30, 2019

@tshaug it's currently on our roadmap for the next release but we prioritize based on demand so definitely this issue will bump the priority a bit.

1-wire in general is quite not reliable (it's timing based and we're not working under real-time OS so any thread/context switch at a bad time can destroy the reading process).

Having said that there are two ways we can go about improving the current state of DHT11:

  • improve (current) bit banging implementation - currently it works around 10% of the time which I bet we can improve
  • add proper implementation like mentioned in Support one-wire protocol #197 which is based on the kernel driver and later convert bit-banging implementation to SoftwareOneWire (similar done as we've done for SpiDevice and SoftwareSpiDevice) which will allow people to swap based on demand.

The fastest way to get it would probably be to contribute, otherwise we are talking about around 1 year timeline with a maybe factor (even though we want we we might not have time to focus on this).

I believe in general using kernel driver implementation will not be super hard and I can help with that - all you need to do is to read and parse couple of files from under /dev/ as per pointers in the other issue.

Alternative and simpler solution might be to change thermometer to anything not 1-wire based (I2C/SPI/analog). You can see supported thermometers here: https://github.com/dotnet/iot/tree/master/src/devices#thermometers

@tshaug
Copy link
Author

tshaug commented Oct 1, 2019

Good morning Krzysztof

thank you for your explanation and the alternatives.
I assume that I will go for an I2C based sensor (I would like to contribute, but I have not programmed in C for almost 20 years, so I would assume that it will take me to long to get to speed...)".
I need a sensor for humidity so the list of thermometers provide some alternatives - thanks

Cheers
Thomas

@krwq
Copy link
Member

krwq commented Oct 1, 2019

@tshaug for humidity sensors see:
https://github.com/dotnet/iot/tree/master/src/devices#hygrometers

My personal preference: I'd take something from https://github.com/dotnet/iot/blob/master/src/devices/Bmxx80/README.md family (i.e. BME280) but if you just need humidity it might be better to get something cheaper

@tshaug
Copy link
Author

tshaug commented Oct 1, 2019

Hi Krzysztof

thank you once again for yur advice.
I have already order 3 BME sensor I have alsoray exerience using BMP180 and BMP 280, but I did't know that the BME280 is also providing humidity. I found that based on your previous advice.
I hope to receive them tomorrow then I can start to "integrate" ;-)

Thanks again
Thomas

@krwq
Copy link
Member

krwq commented Oct 1, 2019

@tshaug cool to hear. Please also make sure to look at #753 and #752

If you are only reading humidity/temperature then it won't affect you - for pressure the first issue mentions that you also need to change the power mode before using it - otherwise you'll get incorrect pressure reading.

The issues will likely result in some usability improvements and therefore some APIs will change shortly (there won't be anything drastic but if you happen to upgrade Iot.Device.Bindings package soon you might notice that something works a bit differently).

If you just copy & paste the sample code then you don't need to change anything

@joperezr joperezr added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Oct 10, 2019
@joperezr joperezr added this to the Future milestone Oct 10, 2019
@joperezr
Copy link
Member

@krwq do you want to close this one as a dupe of the other existing issues of DHT?

@krwq
Copy link
Member

krwq commented Oct 10, 2019

Yes, I think there is no new work this issue introduces comparing to other issues although this one describes user facing problem a bit clearer

@krwq krwq closed this as completed Oct 10, 2019
@tshaug
Copy link
Author

tshaug commented Oct 11, 2019

Hi everybody, yes can be closed.
I switched to the BME280 ;-) I2C instead of One Wire.
Thanks for your support

@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants