Skip to content

Unable to read DHT22 sensor #191

Answered by aburnett397
aburnett397 asked this question in Q&A
Discussion options

You must be logged in to vote

Turns out it works well enough by ditching the edge listeners for active polling. You only need to do this for a few ms on the DHT22 so GC pauses are no big issue. The hardest part remains the delay to reconfigure the pin which often exceeds the 40-80us window meaning some bits can be lost. But you can always repeat the operation on a loop until you get a clean read.
For anyone interested I used this instead of listeners and got a similar result to what I had with wiringPi:

		now = System.nanoTime();
		DigitalState state = in.state();
		long val = 0, lastHi = now;
		int read = 0;
		//active polling for 10ms (5.5ms is enough according to datasheet)
		while (System.nanoTime()-now < 10000000…

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by FDelporte
Comment options

You must be logged in to vote
1 reply
@aburnett397
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #190 on January 26, 2022 14:44.