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

Python lesson 28-DHT11 doesn't work reliably #1

Closed
Martin-HiPi opened this issue Sep 12, 2020 · 3 comments
Closed

Python lesson 28-DHT11 doesn't work reliably #1

Martin-HiPi opened this issue Sep 12, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@Martin-HiPi
Copy link
Owner

Martin-HiPi commented Sep 12, 2020

This code needs to be reviewed for bad behaviour: https://github.com/Martin-HiPi/HiPi-Sensor-kit-v4.0/blob/f8d8c8ecc70f6f9e8cb72e3602bd26bba3683e8c/Python/28_humiture.py

@Martin-HiPi Martin-HiPi added the bug Something isn't working label Sep 12, 2020
@Martin-HiPi
Copy link
Owner Author

Martin-HiPi commented Sep 12, 2020

I think I found the root cause: the pin is not pulled low long enough!
The datasheet asks for at least 18ms and I'm measuring ~8us!

Edit: It's weirder than this, now the timing is good, but the DHT11 is not even responding...

@Martin-HiPi
Copy link
Owner Author

I find that the issue is those two lines:

GPIO.setup(DHTPIN, GPIO.OUT)
GPIO.output(DHTPIN, GPIO.HIGH)

Reason:
When the pin is set up as an output, it goes low for ~7us before the next code line brings it UP.

Solution:
Set up the GPIO as output and specify the initial level at the same time:
GPIO.setup(DHTPIN, GPIO.OUT, initial=GPIO.HIGH)

Replacing the two lines with the above code fixes initialization issues, and the lesson code works reliably!

@Martin-HiPi Martin-HiPi changed the title Python lesson 28-DHT11 runs only once Python lesson 28-DHT11 doesn't work reliably Sep 13, 2020
Martin-HiPi added a commit that referenced this issue Sep 13, 2020
@Martin-HiPi
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant