adafruit / Adafruit_CircuitPython_DHT

CircuitPython support for DHT11 and DHT22 type temperature/humidity devices
MIT License
179 stars 62 forks source link

Addition of test timing script #68

Closed yeyeto2788 closed 3 years ago

yeyeto2788 commented 3 years ago

Hey guys!

I stumble across issue #66 and just wanted to create a script so we can test best timing on reading data from the DHT sensor.

Example output:

(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/dht_test/venv/bin/python dht_time_calibration.py

Initializing test.

Using 'trig_wait' of 500
Total read(s): 4

Using 'trig_wait' of 600
Total read(s): 6

Using 'trig_wait' of 700
Total read(s): 6

Using 'trig_wait' of 800
Total read(s): 6

Using 'trig_wait' of 900
Total read(s): 6

Using 'trig_wait' of 1000
Total read(s): 5

Using 'trig_wait' of 1100
Total read(s): 5

Using 'trig_wait' of 1200
Total read(s): 10

Using 'trig_wait' of 1300
Total read(s): 9

Using 'trig_wait' of 1400
Total read(s): 10

Using 'trig_wait' of 1500
Total read(s): 9

Using 'trig_wait' of 1600
Total read(s): 8

Using 'trig_wait' of 1700
Total read(s): 8

Using 'trig_wait' of 1800
Total read(s): 6

Using 'trig_wait' of 1900
Total read(s): 6

Maximum reads: 10 with the following times: 1200 ,1400
jposada202020 commented 3 years ago

@yeyeto2788 Thanks for the contribution, as discussed I will try on my side also after our discussion. After this initial verification I can share my results and let people comment on this example, and then we could work on the code format in order to the CI to pass if you agree. Thanks for your contribution

yeyeto2788 commented 3 years ago

@jposada202020 Sure, no problem on my side.

jposada202020 commented 3 years ago

@yeyeto2788 in case of need you cold take a look at these guide https://learn.adafruit.com/improve-your-code-with-pylint, however feel free to contact me to guide you in this process

yeyeto2788 commented 3 years ago

Sample output for latest commit.


(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test1.py
[sudo] password for yeyeto2788:

Initializing test with the following parameters:

Maximum retries per waiting time: 10
Start time (ms): 500
End time (ms): 2000
Increment time (ms): 100

This execution will try to read the sensor 10 times
for 15 different wait times values.

Using 'trig_wait' of 500
Total read(s): 4

Using 'trig_wait' of 600
Total read(s): 2

Using 'trig_wait' of 700
Total read(s): 5

Using 'trig_wait' of 800
Total read(s): 6

Using 'trig_wait' of 900
Total read(s): 6

Using 'trig_wait' of 1000
Total read(s): 5

Using 'trig_wait' of 1100
Total read(s): 6

Using 'trig_wait' of 1200
Total read(s): 5

Using 'trig_wait' of 1300
Total read(s): 5

Using 'trig_wait' of 1400
Total read(s): 6

Using 'trig_wait' of 1500
Total read(s): 8

Using 'trig_wait' of 1600
Total read(s): 8

Using 'trig_wait' of 1700
Total read(s): 0

Using 'trig_wait' of 1800
Total read(s): 6

Using 'trig_wait' of 1900
Total read(s): 8

Maximum reads: 8  out of 10 with the following times: 1500, 1600, 1900
jposada202020 commented 3 years ago

I have tested the code above, I did make some changes to use it with my RP4.

RP4 with a DHT22
Maximum reads: 10  out of 10 with the following times: 400, 700, 1200, 1300, 1400, 1600
Maximum reads: 10  out of 10 with the following times: 400, 700, 1300, 1600, 1700
Maximum reads: 10  out of 10 with the following times: 400, 500, 600, 900, 1100, 1200
Maximum reads: 10  out of 10 with the following times: 300, 600, 700, 1000, 1100, 1300, 1400, 1600, 1800, 1900
Maximum reads: 10  out of 10 with the following times: 500, 800, 1000, 1300, 170
Maximum reads: 10  out of 10 with the following times: 1600
Maximum reads: 10  out of 10 with the following times: 500, 700, 900, 1000, 1100, 1300, 1900
Maximum reads: 10  out of 10 with the following times: 400, 800, 1000, 1300, 1400, 1500, 1600, 1800, 1900
Maximum reads: 10  out of 10 with the following times: 1000, 1100, 1200, 1300, 1400

RP4 with a DHT11
Maximum reads: 10  out of 10 with the following times: 15600, 15800, 16200, 16600, 17400, 17600, 18000, 18200, 18600, 19400, 20400, 21000, 21200, 23000, 23400, 23800, 24200
Maximum reads: 10  out of 10 with the following times: 15800, 16200, 16600, 16800, 17000, 17200, 17800, 18000, 18600, 18800, 19000, 19600, 19800, 20000, 20600, 21000, 21400, 22200, 22600, 22800, 24200
Maximum reads: 10  out of 10 with the following times: 15000, 15600, 16000, 16200, 16400, 17200, 17600, 17800, 18000, 18200, 20800, 21000, 21400, 22800, 23600, 24600, 24800
Maximum reads: 10  out of 10 with the following times: 16600, 17800, 18000, 18200, 22000, 22200, 22400, 24000, 24600
Maximum reads: 10  out of 10 with the following times: 15000, 15400, 15600, 16000, 16600, 17000, 17200, 17800, 18200, 19000, 19200, 19400, 19600, 20000, 20200, 20600, 21000, 21200, 22200, 22600, 23000, 23200, 23800
Maximum reads: 10  out of 10 with the following times: 15400, 16200, 16400, 17000, 17200, 17800, 18200, 18400, 20000, 20600, 20800, 22000, 22400, 22600, 23400, 24000, 24200, 24400
Maximum reads: 10  out of 10 with the following times: 15200, 15600, 15800, 16400, 16600, 16800, 17000, 17200, 17400, 17600, 18000, 18400, 18600, 19200, 21800, 22600, 23800, 24400
Maximum reads: 10  out of 10 with the following times: 16000, 16400, 17000, 17200, 17400, 17800, 18000, 18200, 18400, 19400, 19800, 20600, 21200, 22000, 22200, 22400, 22600, 24200, 24800
Maximum reads: 10  out of 10 with the following times: 15000, 15600, 16200, 16400, 16600, 17000, 17800, 18200, 19000, 19200, 19400, 19800, 20400, 20600, 21200, 22000, 22200, 22600, 23000, 23200, 23800, 24200, 24600, 24800

I have some comments for the code, I will given my feedback shortly thanks.

jposada202020 commented 3 years ago

@yeyeto2788 Thanks again I have a couple of comments. Please do not hesitate to contact me here or in discord if you need help/guidance with anything.

  1. Could you add the example to the following file : https://github.com/adafruit/Adafruit_CircuitPython_DHT/blob/master/docs/examples.rst this would allow the readthedocs documentation to use the example when building the docs. Just follow the conventions as for the previous example.
  2. I would suggest a change in the name of the example, maybe if you could add _advanced at the end. I think that this example uses a private attribute in the library and is in some ways higher level
  3. As discussed also, if you could add some description of the purpose of the script, as in example dht_to_led_display.py. that would help folks understand the purpose of the example. https://github.com/adafruit/Adafruit_CircuitPython_DHT/blob/ce00fb8b5199c01947e0b0ec6c3a32bec199d18e/examples/dht_to_led_display.py#L5
  4. Include the mention that, timing for the DHT11 and DHT22 are different. maybe add in the comments that usually they are 0.001 DHT22 and 0.018 for DHT11, but that always verify the datasheet.

Feel free to ignore the following comments if you disagree, there are just to have use the same standard as in other code and no a requirement. Spaces between lines in the import libraries.

Thanks again for your contribution.