-
Notifications
You must be signed in to change notification settings - Fork 585
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
Dht22 failed to read. I can read it using Python to make sure that the connection is OK. #1153
Comments
What is rhe error you get? I have no Dht22, but I know the Dht11 works fine. |
I have also tested DHT11, but I can't get any data. Nan, I don't know why. |
Which hardware platform are you using? Which OS? |
Im having the same problem with all values on a DHT11 sensor being NaN. Im using a CrowPi(Raspberry pi 3 b+) as hardware platform on Raspbian operating system. |
You are the same as me. I use Python code to make sure that dht22 and DHT11 can be read normally, but if you use net core, you can't read it. They are both Nan |
It may be because of the latest system problems, but there are many answers. My English is not good. I don't know which is the correct solution. Can you tell me? |
I have got it working now again, both with and without explicitly instantiating RaspberryPi3Driver. It takes some second before the Dht returns correct data. The way to check if there is valid values is, in my opinion, a little bit cumbersome. Dht has a property called IsLastReadSuccessful, to see if last read was successful, but there is only one way to read data and this is to make a call to the Temperature property on the Dht11 object. The Dht11 Temperature device's get property returns
The problem is that temp is double.NaN the first couple of seconds, so the last line throws an "System.ArgumentException: 'NaN is not a valid number.'" in the FromDegreesCelsius method without you can make any check for valid values other than wrap the call to the Dht.Temperature get property in a try/catch. In the old implementation before using the new Unit type, it would just return double.NaN and you could just ignore those values with a simple if check. It might also be a little confusing to have the IsLastReadSuccessful property public, unless you know the internals of the class. People could maybe think it was possible to poll on that property, and first make a call to the Temperature property when it was true, because the Temperature property throws an exception if the last read is not successful. But the IsLastReadSuccessful will always remain false until you make the call to the Temperature property. So the Dht11 is working again on my end, with some adjustments to my code. |
@sokiha , good news. And I understand the issue, if the temperature is not correct, you'll get an exception. |
It doesn't seem to work out? |
I tested with creating the dht device in the following ways:
In my case both worked the same. I then made some code to read the temperature, this code may need to be called several times until dht.IsLastReadSuccessful is true, with some delay between each call. It could take 5-10 seconds maybe before it was stable, but I did'nt really time it.
When it was up and running I used something like this
But the get properties should probably always be wrapped in a try/catch as the IsLastReadSuccessful only account for the last call not the new one made by the call to the Temperature property. I haven't used this code for anyting serious, just some fun programming exercise with my nephew on the CrowPi. |
It seems that the current bug is not suitable for development. |
|
Dht22 acquisition often fails, but when the temperature is obtained, it is also wrong. Why? Temperature: NaN ℃, Humidity: 76.3 % |
Seems like the calculation for DHT22 is wrong. Should be more like: var temp = (((readBuff[2] & 0x7F) << 8) + readBuff[3] )* 0.1;
if (readBuff[2] & 0x80 == 0x80)
{
temp = -temp;
} Can anyone try? Not sure if I have the hardware to test it out. |
Dht22 failed to read. I can read it using Python to make sure that the connection is OK.
using (Iot.Device.DHTxx.Dht22 dht = new Iot.Device.DHTxx.Dht22(26, PinNumberingScheme.Logical))
{
while (true)
{
Console.WriteLine($"Temperature: {dht.Temperature.Celsius.ToString("0.0")} ℃, Humidity: { dht.Humidity} %");
Thread.Sleep(1000);
}
}
The text was updated successfully, but these errors were encountered: