DHT-sensor-library icon indicating copy to clipboard operation
DHT-sensor-library copied to clipboard

Start listening to the sensor right after releasing the start signal …

Open khjoen opened this issue 8 years ago • 0 comments

Hi all,

Here is my pull request for the changes I have done relate to how the library sends the start signal to the sensor and the hope is it will solve and that it will have the effect of a closed #48. It also relates to PR #51 and PR #58.

  • Firstly, there is an unnecessary wait of 250ms before the start signal. This is the reason I started to look at fixing the init sequence. I remember reading that it could be needed by those not using a pull up, in 85a02c70fb32c351f8cac71ecf8961d704b39fa4. ( If that were the case, the pin is set HIGH in begin(), it could be set again before exiting the read method. The pin state should stay HIGH as no other read can be made in the following two seconds, so more than enough time to cover that 250ms that I would like to have removed. We would also need to make sure the first read is done after proper period if sensor needs time to wake up upon start. )

  • Second, from what I conclude after a read of the datasheet and from what I have read on several forums, the MCU should only pull the line LOW for a period of time and then leave the line to the sensor. There is a possible variable amount of time before the sensor will signal its LOW and HIGH for ~80us each while preparing the data. This part was changed for a busy-wait loop to ensure the library gets it at a correct time and not have the guess the wait period for all possible sensors. This has made the delayMicroseconds() calls redundant. That should also satisfy the change that was originally suggested by Wolfgang and referenced in 5ed981893ccf66c886214c2863f0d4482af27bbd.

The changes' goal is to ensure the MCU and sensor do not talk at the same time. A few comments were also added to support the code changes.

Thank you,

Pascal

khjoen avatar Jan 06 '17 19:01 khjoen