-
Notifications
You must be signed in to change notification settings - Fork 64
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
DHT11 not working properly #66
Comments
Thanks, for the report, @yeyeto2788 V3.5.6 Adafruit_CircuitPython_DHT/adafruit_dht.py Line 142 in 85b6a36
V3.5.7 Adafruit_CircuitPython_DHT/adafruit_dht.py Line 142 in ceb883d
|
Hey @jposada202020, Thanks for the quick reply. I try both versions you mentioned and none of those worked. The code/wiring still remain the same but changing the library version give a completely different output import time
import board
import adafruit_dht
dhtDevice = adafruit_dht.DHT11(board.PG6)
for try_number in range(1,200):
print(f"Try number {try_number}")
try:
print(f"Got temp of: {dhtDevice.temperature}")
print(f"And hum of: {dhtDevice.humidity}")
break
except RuntimeError as e:
print(e)
time.sleep(2.1)
else:
time.sleep(2.1)
print("\n")
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ pip install adafruit-circuitpython-dht==3.5.7
Collecting adafruit-circuitpython-dht==3.5.7
Downloading adafruit-circuitpython-dht-3.5.7.tar.gz (28 kB)
Requirement already satisfied: Adafruit-Blinka in ./venv/lib/python3.8/site-packages (from adafruit-circuitpython-dht==3.5.7) (6.4.1)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.7) (1.1.8)
Requirement already satisfied: Adafruit-PlatformDetect>=3.1.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.7) (3.4.0)
Requirement already satisfied: pyftdi>=0.40.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.7) (0.52.9)
Requirement already satisfied: pyserial>=3.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.7) (3.5)
Requirement already satisfied: pyusb>=1.0.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.7) (1.1.1)
Building wheels for collected packages: adafruit-circuitpython-dht
Building wheel for adafruit-circuitpython-dht (setup.py) ... done
Created wheel for adafruit-circuitpython-dht: filename=adafruit_circuitpython_dht-3.5.7-py3-none-any.whl size=6837 sha256=64936289ef4ee9d95648779129c46efd18e8aaab255f6156d5a1735d1977b4e8
Stored in directory: /home/yeyeto2788/.cache/pip/wheels/30/3e/2b/c43aa6a3c0afd819cf5cadd2089a674b9f2a580e1b3ef25b0b
Successfully built adafruit-circuitpython-dht
Installing collected packages: adafruit-circuitpython-dht
Attempting uninstall: adafruit-circuitpython-dht
Found existing installation: adafruit-circuitpython-dht 3.5.6
Uninstalling adafruit-circuitpython-dht-3.5.6:
Successfully uninstalled adafruit-circuitpython-dht-3.5.6
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
A full buffer was not returned. Try again.
Try number 2
A full buffer was not returned. Try again.
Try number 3
A full buffer was not returned. Try again.
Try number 4
A full buffer was not returned. Try again.
Try number 5
A full buffer was not returned. Try again.
^CTraceback (most recent call last):
File "test.py", line 11, in <module>
print(f"Got temp of: {dhtDevice.temperature}")
File "/home/yeyeto2788/workspace/mudpi-core/venv/lib/python3.8/site-packages/adafruit_dht.py", line 244, in temperature
self.measure()
File "/home/yeyeto2788/workspace/mudpi-core/venv/lib/python3.8/site-packages/adafruit_dht.py", line 200, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 16, in <module>
time.sleep(2.1)
KeyboardInterrupt
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ pip install adafruit-circuitpython-dht==3.5.6
Collecting adafruit-circuitpython-dht==3.5.6
Using cached adafruit_circuitpython_dht-3.5.6-py3-none-any.whl
Requirement already satisfied: Adafruit-Blinka in ./venv/lib/python3.8/site-packages (from adafruit-circuitpython-dht==3.5.6) (6.4.1)
Requirement already satisfied: pyftdi>=0.40.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.6) (0.52.9)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.6) (1.1.8)
Requirement already satisfied: Adafruit-PlatformDetect>=3.1.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.6) (3.4.0)
Requirement already satisfied: pyusb>=1.0.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.6) (1.1.1)
Requirement already satisfied: pyserial>=3.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.6) (3.5)
Installing collected packages: adafruit-circuitpython-dht
Attempting uninstall: adafruit-circuitpython-dht
Found existing installation: adafruit-circuitpython-dht 3.5.7
Uninstalling adafruit-circuitpython-dht-3.5.7:
Successfully uninstalled adafruit-circuitpython-dht-3.5.7
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py )
Try number 1
DHT sensor not found, check wiring
Try number 2
DHT sensor not found, check wiring
Try number 3
DHT sensor not found, check wiring
Try number 4
DHT sensor not found, check wiring
^CTraceback (most recent call last):
File "test.py", line 11, in <module>
print(f"Got temp of: {dhtDevice.temperature}")
File "/home/yeyeto2788/workspace/mudpi-core/venv/lib/python3.8/site-packages/adafruit_dht.py", line 244, in temperature
self.measure()
File "/home/yeyeto2788/workspace/mudpi-core/venv/lib/python3.8/site-packages/adafruit_dht.py", line 196, in measure
raise RuntimeError("DHT sensor not found, check wiring")
RuntimeError: DHT sensor not found, check wiring
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 16, in <module>
time.sleep(2.1)
KeyboardInterrupt
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ pip install adafruit-circuitpython-dht==3.5.5
Collecting adafruit-circuitpython-dht==3.5.5
Using cached adafruit_circuitpython_dht-3.5.5-py3-none-any.whl
Requirement already satisfied: Adafruit-Blinka in ./venv/lib/python3.8/site-packages (from adafruit-circuitpython-dht==3.5.5) (6.4.1)
Requirement already satisfied: Adafruit-PlatformDetect>=3.1.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.5) (3.4.0)
Requirement already satisfied: pyftdi>=0.40.0 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.5) (0.52.9)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in ./venv/lib/python3.8/site-packages (from Adafruit-Blinka->adafruit-circuitpython-dht==3.5.5) (1.1.8)
Requirement already satisfied: pyserial>=3.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.5) (3.5)
Requirement already satisfied: pyusb>=1.0.0 in ./venv/lib/python3.8/site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-dht==3.5.5) (1.1.1)
Installing collected packages: adafruit-circuitpython-dht
Attempting uninstall: adafruit-circuitpython-dht
Found existing installation: adafruit-circuitpython-dht 3.5.6
Uninstalling adafruit-circuitpython-dht-3.5.6:
Successfully uninstalled adafruit-circuitpython-dht-3.5.6
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
DHT sensor not found, check wiring
Try number 2
Got temp of: 22
And hum of: 20 So I looked what was on the library of the (venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ find ./ -name adafruit*dht*
./venv/lib/python3.8/site-packages/__pycache__/adafruit_dht.cpython-38.pyc
./venv/lib/python3.8/site-packages/adafruit_dht.py
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sed -n -e 138,152p ./venv/lib/python3.8/site-packages/adafruit_dht.py
dhtpin.value = True
time.sleep(0.1)
dhtpin.value = False
time.sleep(0.001)
timestamp = time.monotonic() # take timestamp
dhtval = True # start with dht pin true because its pulled up
dhtpin.direction = Direction.INPUT
try:
dhtpin.pull = Pull.UP
# Catch the NotImplementedError raised because
# blinka.microcontroller.generic_linux.libgpiod_pin does not support
# internal pull resistors.
except NotImplementedError:
dhtpin.pull = None And this might correspond to Line 141 on commit e22d289ab480468fa305a451e3b9c1961c7f0fb2 To summarize I don't really see a difference on using |
@yeyeto2788 No problem, Adafruit_CircuitPython_DHT/adafruit_dht.py Line 265 in ceb883d
In a note, yes 3.5.6 would not work as the waiting time was 0 as you get an python int division. That was my mistake.Could you make some test changing the value, maybe hardcoded it. it is very interesting. maybe is something that I am not seeing. I did as you can see in here some testing, so for me the library works in both sensors. with the trigger time https://github.com/jposada202020/DHT_Investigation But I am very curious |
Sure, so want me to try out your script (modified with the pin used on my SBC) or you just want me to manually change the values on the library itself? It is almost the same as mine except for the checksum. |
Both :) but for this case it would be better to verify the library behaviour, understand why when we use 0.001 works and when we use the division in the trigger do not. So if you could manually change the library values that would really helpful. |
Based on your script I get this output: (venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test_a.py
DHT sensor not found, check wiring
DHT sensor not found, check wiring
Temp: 69.8 F / 21.0 C Humidity: 20%
Traceback (most recent call last):
File "test_a.py", line 34, in <module>
print(f"Cycle: {i}--Checksum Errors: {dhtDevice.checksum_test}--Data Buffer Error: {dhtDevice.data_buffer_test}"
AttributeError: 'DHT11' object has no attribute 'checksum_test' I also tried with manual changes and my code and the results are below. 0.001 Gives 3 out of 10 reads 141 # Using the time to pull-down the line according to DHT Model
142 time.sleep(0.001)
143 timestamp = time.monotonic() # take timestamp
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
Got temp of: 21
And hum of: 20
Try number 2
DHT sensor not found, check wiring
Try number 3
DHT sensor not found, check wiring
Try number 4
DHT sensor not found, check wiring
Try number 5
DHT sensor not found, check wiring
Try number 6
DHT sensor not found, check wiring
Try number 7
Got temp of: 21
And hum of: 20
Try number 8
Got temp of: 21
And hum of: 20
Try number 9
DHT sensor not found, check wiring
Try number 10
DHT sensor not found, check wiring 0.0001 Gives 2 out of 10 141 # Using the time to pull-down the line according to DHT Model
142 time.sleep(0.0001)
143 timestamp = time.monotonic() # take timestamp
144 dhtval = True # start with dht pin true because its pulled up
145 dhtpin.direction = Direction.INPUT
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
DHT sensor not found, check wiring
Try number 2
DHT sensor not found, check wiring
Try number 3
Got temp of: 21
And hum of: 20
Try number 4
DHT sensor not found, check wiring
Try number 5
Got temp of: 21
And hum of: 20
Try number 6
DHT sensor not found, check wiring
Try number 7
DHT sensor not found, check wiring
Try number 8
DHT sensor not found, check wiring
Try number 9
DHT sensor not found, check wiring
Try number 10
DHT sensor not found, check wiring 0.1 Gives NO reads 142 time.sleep(0.1)
143 timestamp = time.monotonic() # take timestamp
144 dhtval = True # start with dht pin true because its pulled up
145 dhtpin.direction = Direction.INPUT
146
147 try:
148 dhtpin.pull = Pull.UP
149 # Catch the NotImplementedError raised because
150 # blinka.microcontroller.generic_linux.libgpiod_pin does not su>
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
A full buffer was not returned. Try again.
Try number 2
A full buffer was not returned. Try again.
Try number 3
A full buffer was not returned. Try again.
Try number 4
A full buffer was not returned. Try again.
Try number 5
A full buffer was not returned. Try again.
Try number 6
A full buffer was not returned. Try again.
Try number 7
A full buffer was not returned. Try again.
Try number 8
A full buffer was not returned. Try again.
Try number 9
A full buffer was not returned. Try again.
Try number 10
A full buffer was not returned. Try again. 0.002 Gives 8 of 10 141 # Using the time to pull-down the line according to DHT Model
142 time.sleep(0.002)
143 timestamp = time.monotonic() # take timestamp
144 dhtval = True # start with dht pin true because its pulled up
145 dhtpin.direction = Direction.INPUT
146
147 try:
148 dhtpin.pull = Pull.UP
149 # Catch the NotImplementedError raised because
150 # blinka.microcontroller.generic_linux.libgpiod_pin does not su>
151 # internal pull resistors.
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
Got temp of: 21
And hum of: 20
Try number 2
DHT sensor not found, check wiring
Try number 3
Got temp of: 21
And hum of: 20
Try number 4
Got temp of: 21
And hum of: 20
Try number 5
Got temp of: 21
And hum of: 20
Try number 6
Got temp of: 21
And hum of: 20
Try number 7
Got temp of: 21
And hum of: 20
Try number 8
DHT sensor not found, check wiring
Try number 9
Got temp of: 21
And hum of: 20
Try number 10
Got temp of: 21
And hum of: 20 0.00185 BEST RESULTS 😄 141 # Using the time to pull-down the line according to DHT Model
142 time.sleep(0.00185)
143 timestamp = time.monotonic() # take timestamp
144 dhtval = True # start with dht pin true because its pulled up
145 dhtpin.direction = Direction.INPUT
146
147 try:
148 dhtpin.pull = Pull.UP
149 # Catch the NotImplementedError raised because
150 # blinka.microcontroller.generic_linux.libgpiod_pin does not su>
151 # internal pull resistors.
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
Got temp of: 21
And hum of: 20
Try number 2
Got temp of: 21
And hum of: 20
Try number 3
Got temp of: 21
And hum of: 20
Try number 4
DHT sensor not found, check wiring
Try number 5
Got temp of: 21
And hum of: 20
Try number 6
Got temp of: 21
And hum of: 20
Try number 7
Got temp of: 21
And hum of: 20
Try number 8
Got temp of: 21
And hum of: 20
Try number 9
Got temp of: 21
And hum of: 20
Try number 10
Got temp of: 21
And hum of: 20 I hope it gives you an idea more or less on timing. Of course I haven't test it on other boards so would be great to test same timings on other boards. |
@yeyeto2788 did you try with the division :) why on earth it does not work hen dividing, do we need to use an if statemt. 😄 Thanks for testing. so timing is good, at least. why is not working with the class attribute ❓ 😞 |
@yeyeto2788 by the way thanks for testing :) |
@jposada202020 I forgot about it 😛 Here you have the test: 141 # Using the time to pull-down the line according to DHT Model
142 time.sleep(self._trig_wait / 1000000)
143 timestamp = time.monotonic() # take timestamp
144 dhtval = True # start with dht pin true because its pulled up
145 dhtpin.direction = Direction.INPUT
146
147 try:
148 dhtpin.pull = Pull.UP
149 # Catch the NotImplementedError raised because
150 # blinka.microcontroller.generic_linux.libgpiod_pin does not su>
151 # internal pull resistors.
(venv) yeyeto2788@orangepilite:~/workspace/mudpi-core$ sudo /home/yeyeto2788/workspace/mudpi-core/venv/bin/python test.py
Try number 1
DHT sensor not found, check wiring
Try number 2
A full buffer was not returned. Try again.
Try number 3
A full buffer was not returned. Try again.
Try number 4
Got temp of: 21
And hum of: 20
Try number 5
A full buffer was not returned. Try again.
Try number 6
A full buffer was not returned. Try again.
Try number 7
A full buffer was not returned. Try again.
Try number 8
A full buffer was not returned. Try again.
Try number 9
A full buffer was not returned. Try again.
Try number 10
A full buffer was not returned. Try again. So the thing is that it is actually working but giving more false positives or false reads using that conversion NOTE: This is a total different number to let's say |
@yeyeto2788 :) are you sure that you have a DHT11, if so, it is pretty good.... 💨 , look at page 5 of this datasheet https://osoyoo.com/driver/DHT11-datasheet.pdf |
I hope it is a DHT11 because it actually looks like one, my sensor is this one which was bought on other site. Regarding that datasheet it states the following:
So it has to be AT LEAST 18ms and I'm actually getting better results with less than that (1.85ms)🤮 If you need me to test something else just let me know. P.D: I can also contact me through Discord and probably it would be more faster. |
@yeyeto2788 Thanks. See.. 👀 that is why I am so confused. I will contact you in the Adafruit discord :) |
@yeyeto2788 Hello I tried to contact you in the Adafruit discord channel. but there are two people with the same nickname, if you could leave me a message in the help-with-circuitpython channel, I can trace it. Thanks I have an idea of what to do but I would need your help, and need to discuss also what your think and feedback. thanks |
I wanted to add some testing to help give more data. I have a RPi4 that works fine with both the DHT11 and DHT22. I also have a RPi zero w but it has more trouble getting reads from both the DHT11 and DHT22. I thought I would run tests on the zero and see if it helps reveal more on the timings. Here are some details: Installed packaged
Board: RPi Zero W Test Script Results
|
Using version
3.5.8
in a loop it almost never gets a reading with the following code:The weird part is that using the version
3.5.5
it actually get the readings correctly.More data:
Python: 3.8.5
SBC: Orange Pi Lite
Installed libraries:
The text was updated successfully, but these errors were encountered: