0

I've read some sensors/devices take time to return result since they're interacting with environment or some other resource that takes time. One example is DHT-11 temperature sensor that takes ~2seconds to give results.

So what they mean is if we read() from GPIO at that moment, it'll block for ~2 seconds or will it contain garbage value and return immediately till actual result is obtained. I'm trying to mock gpio pins for some testing till I get my raspi and sensors so I'm asking here. Thankyou :)

2

When you read a GPIO you get its current level at that instant. There is no block and no delay (other than the fraction of a microsecond needed to read the port).

A DHT11 returns a bit stream of 40 bits. Each bit is encoded as a low period followed by a long or short high period which determines whether the bit is 1 or 0. That doesn't take 2 seconds to read, it takes about 4 milliseconds. You may be thinking of the recommended minimum delay between DHT22 readings which is a two second minimum (the DHT11 is one second).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.