Skip to content
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

A full buffer was not returned. Try again. #33

Open
fniko opened this issue Feb 14, 2020 · 46 comments
Open

A full buffer was not returned. Try again. #33

fniko opened this issue Feb 14, 2020 · 46 comments
Labels

Comments

@fniko
Copy link

fniko commented Feb 14, 2020

Hi,
using Raspberry Pi Zero with DHT11 sensor and I am observing this issue:
"A full buffer was not returned. Try again." after running dht_simpletest.py.
I edited values to match DHT11 and P4 (i use)

dhtDevice = adafruit_dht.DHT11(board.D4)

I tested the sensor using the old library and it works (90+ % succ read rate), but using the new library I can barely make one successful request.
Also I tried to increase sleep period to 5 sec with no result.

How should I troubleshoot this?

@scholi
Copy link

scholi commented Mar 7, 2020

same problem here with DHT11: Python 3.7.3, raspeberry pi 0, Linux raspberrypi 4.19.97+ #1294
adafruit_dht.version '0.0.0-auto.0'

@thatsjet
Copy link

Same here. I've implemented a try/raise with sleep of 2 seconds but it's a LOT less reliable than the old Python 2.7 library.

@Iril
Copy link

Iril commented Apr 26, 2020

This was also my problem and so back to the Adafruit_DHT library. Working 95% of the time on Python3 and Balena.

@lilcoltsmith
Copy link

I'm getting the same issue. I have the following:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian

  • Raspberry Pi Zero W v1.1
  • DHT-22
  • Python 3.8
  • adafruit-circuitpython-dht==3.4.1

Here is a sample of the output from my script:

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] A full buffer was not returned. Try again.
[DHT-22] Sensor failure. Check wiring.
+-----------------------------------------------------------------+

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] A full buffer was not returned. Try again.
[DHT-22] Sensor failure. Check wiring.
+-----------------------------------------------------------------+

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] A full buffer was not returned. Try again.
[DHT-22] Sensor failure. Check wiring.
+-----------------------------------------------------------------+

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] Temperature: 20.0C Humidity: 53.7% Date/Time: 2020-05-01 23:41:14
[DHT-22] Queue size: 1
[DHT-22] Local Mode: False, Zip Code Exists: False
[DHT-22] Writing queue to file.
+-----------------------------------------------------------------+

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] Temperature: 19.9C Humidity: 53.0% Date/Time: 2020-05-01 23:41:25
[DHT-22] Queue size: 1
[DHT-22] Local Mode: False, Zip Code Exists: False
[DHT-22] Writing queue to file.
+-----------------------------------------------------------------+

+-----------------------------------------------------------------+
[DHT-22] Connection to API refused. Starting in local mode.
[DHT-22] A full buffer was not returned. Try again.
[DHT-22] Sensor failure. Check wiring.
+-----------------------------------------------------------------+

This is with a 10 second interval between checks. The only message that isn't from my script is:
A full buffer was not returned. Try again.

@kattni kattni added the bug label May 4, 2020
@raucao
Copy link

raucao commented Jul 3, 2020

Just ran into the same error. Any news on this one?

@jerryneedell
Copy link

jerryneedell commented Jul 3, 2020

FYI -- I just tried this on a Pi ZeroW -- it is intermittent for me as well-- This has been a common problem with the DTH22.

pi@gjnpideck:~/projects/blinka $ python3 dht_simpletest.py 
Temp: 78.4 F / 25.8 C    Humidity: 48.2% 
A full buffer was not returned. Try again.
A full buffer was not returned. Try again.
Temp: 76.6 F / 24.8 C    Humidity: 52.1% 
Temp: 76.6 F / 24.8 C    Humidity: 52.1% 
Temp: 76.6 F / 24.8 C    Humidity: 52.1% 
Temp: 76.6 F / 24.8 C    Humidity: 52.2% 
Temp: 76.6 F / 24.8 C    Humidity: 52.2% 
Temp: 76.6 F / 24.8 C    Humidity: 51.3% 
A full buffer was not returned. Try again.
Temp: 76.6 F / 24.8 C    Humidity: 52.2% 
Temp: 76.6 F / 24.8 C    Humidity: 52.1% 
Temp: 76.6 F / 24.8 C    Humidity: 52.0% 
Temp: 76.6 F / 24.8 C    Humidity: 52.0% 

BTW -- I also tried it on a Pi4 -- it appears to be respond better, but still some CRC errors in the brief test I ran,

@lane-maxwell
Copy link

Same here, it intermittently fails

 humidity = dhtDevice.humidity

File "/home/pi/.local/lib/python3.7/site-packages/adafruit_dht.py", line 252, in humidity
self.measure()
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_dht.py", line 198, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.

@dbforma
Copy link

dbforma commented Jul 26, 2020

I have run into the same problems. I have made some slight changes to the code and now I do not get these errors anymore.

DHTSensor = adafruit_dht.DHT22(board.D27)


class AirMoistureAndTemperatureSensor(SensorRepository):

    AirMoistureValue = DHTSensor.humidity
    AirTemperatureValue = DHTSensor.temperature

    def getSensorValues(self):
        try:
            return self.AirMoistureValue,  self.AirTemperatureValue

        except RuntimeError as error:
            print(error.args[0])

        time.sleep(2)

sbkirby added a commit to sbkirby/imagenode that referenced this issue Aug 13, 2020
Added DHT11 and DHT22 Temp/Humidity Sensors to file.  Added 'unit' parameter to 'sensors' section of YAML file.  User can select Centigrade or Fahrenheit output.  Note: There is currently an issue with these sensors and the adafruit_dht module "Error: A full buffer was not returned. Try again" Refn: adafruit/Adafruit_CircuitPython_DHT#33
@snrkl
Copy link

snrkl commented Sep 5, 2020

I am having the same issues.. If I pop out to a python 2.7.2 environment, the old library works a charm...

Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import board
>>> import adafruit_dht
>>> dhtDevice = adafruit_dht.DHT11(board.D17)
>>> temperature_c = dhtDevice.temperature
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 253, in temperature
self.measure()
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 209, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.>

>>> temperature_c = dhtDevice.temperature
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 253, in temperature
self.measure()
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 209, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.>

>>> temperature_c = dhtDevice.temperature
>>> temperature_c
>>> str(temperature_c)
'None'>

>>> dhtDevice.humidity
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 263, in humidity
self.measure()
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 209, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.
>>> dhtDevice.humidity>

>>> dhtDevice.temperature
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 253, in temperature
self.measure()
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 209, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.>

>>> dhtDevice.humidity
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 263, in humidity
self.measure()
File "/home/snrkl/python-venvs/envlogd/lib/python3.7/site-packages/adafruit_dht.py", line 209, in measure
raise RuntimeError("A full buffer was not returned. Try again.")
RuntimeError: A full buffer was not returned. Try again.>

Python 2 with the old library:

0 /home/snrkl/snrkl/bin $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_DHT
>>> humidity, temperature = Adafruit_DHT.read_retry(11, 17)
>>> humidity
59.0
>>> temperature
24.0

@gnorbsl
Copy link

gnorbsl commented Sep 6, 2020

same here, after reboot nothing works anymore... I'm going to switch back to the old since this one seems to be not maintained either.

@austin7777
Copy link

Same problem

@WinBase
Copy link

WinBase commented Oct 10, 2020

same problems, i've tried for hours with no luck

the old deprecated library (on latest python 3.7.3) works, even though i get plenty of misreads and have a 'retry' loop every 3 seconds to eventually get a good read, but circuitpython is total bllcks, it gives the following messages in a random order:

sometimes at the start it says: 'unable to set line 23' to input (the old library works just fine on this pin)

then:

Timed out waiting for PulseIn message. Make sure libgpiod is installed. - FYI: latest libgpiod2 IS installed)
Reading from DHT failure: ('DHT sensor not found, check wiring',)
Reading from DHT failure: ('Checksum did not validate. Try again.',)
Reading from DHT failure: ('A full buffer was not returned. Try again.',)

i rebooted the pi zero, and whoopee started to get the occasional reading inbetween 10-20 failures, used ctrl-c to cancel, re-tried a minute later, and then no readings at all, just error messages.

to deprecate a working library replacing it with a buggy non-working one leaves me (almost) speechless, and i'm unlikely to consider adafruit software or products for my projects, i think i'll look elsewhere if it aint sorted soon.

btw my pi is fully upgraded and updated

GL

Bob

@davidoesch
Copy link

same here ---Adafruit_CircuitPython_DHT does not work in 80% of the cases

@mafrosis
Copy link

Some more anecdata. From my logs - successful reads are followed by 10 second sleep, failed reads are followed by 0.2 secs sleep.

.. snip
19.8 45.8
19.9 45.8
A full buffer was not returned. Try again.
19.9 45.8
DHT sensor not found, check wiring
19.9 45.8
19.8 44.5
A full buffer was not returned. Try again.
19.8 44.5
19.8 45.6
19.8 45.6
19.8 45.7
19.8 45.7
A full buffer was not returned. Try again.
19.8 45.7
19.8 45.8
19.8 45.7
19.8 45.6
DHT sensor not found, check wiring
19.8 45.6
19.8 45.8
A full buffer was not returned. Try again.
19.8 45.8
19.8 45.8
.. snip

Likewise, the old non-circuitpython library works fine, but the new one is unreliable. Possibly the old library hid the unreliability of the DHT22 itself?

@jerryneedell @dherrada @kattni @ladyada - As major contributors and/or representatives of Adafruit, could you comment on this thread? I'm interested to know if this is by design / fixable / on the roadmap etc. Thanks

@tannewt
Copy link
Member

tannewt commented Oct 26, 2020

Possibly the old library hid the unreliability of the DHT22 itself?

This appears to be the case: https://github.com/adafruit/Adafruit_Python_DHT/blob/master/Adafruit_DHT/common.py#L83-L98

If you used read_retry in the old library, it would retry 15 times by default and wait 2 seconds between each retry. Folks above didn't specify the old code they were comparing against so I can't be sure.

The underlying pulse code of the old library is written in C here: https://github.com/adafruit/Adafruit_Python_DHT/blob/master/source/Raspberry_Pi/pi_dht_read.c I'm not sure how pulses are counted via Blinka. @makermelissa would know.

I'm interested to know if this is by design / fixable / on the roadmap etc. Thanks

My API design preference is to not hide unreliability because it allows the user to decide what to do. It's simple enough to rewrite read_retry in your own code.

It's important to note this library is shared with CircuitPython and problems with this library would show with it as well. Linux isn't great for real-time so this is more likely an issue with the underlying pulse tracking on Linux.

@WinBase
Copy link

WinBase commented Oct 27, 2020

Possibly the old library hid the unreliability of the DHT22 itself?

quite possibly indeed, but at least you can get readings to some degree, which i'm finding almost impossible in the new circuitpython version. I think i stumbled across a library written by someone else that said it worked fine with the DHT22, so maybe i'll try find it again when i get the opportunity and give it a spin.

regards.

@shawnerz
Copy link

shawnerz commented Nov 2, 2020

I thought it was just me!
I spent over 8 hours today (Sunday) trying to figure out what went wrong. I switched between a Pi Zero 1.2 and a Pi Zero W 1.1. I tried a 1K resistor (as mentioned in the manufacture's datasheet) and a 10K resistor (in the Adafruit and Pimylifeup pages. I didn't try 4.7k). I tried sample rates as slow as 30 seconds. I'm getting about a 95% failure rate.
In the process, I heat damaged a SD card (from soldering too close to it) and had to reload the OS and what I had done to a new SD card. Nothing seemed to work.
Interestingly enough, 2 months ago (early September), I used an old Pi Zero ver. 1.2 (no wi-fi), a DHT22, and 10K resistor to monitor room temperature. I am getting about a 75% success rate.
Because the DHT22's are so cheap, I bought 6 on Amazon. I'm using the ones from that purchase. I duplicated the set up, and getting about a 95% failure rate. Something had to have changed in the code base from September.
It just so happens I am going to that site tomorrow (Monday). I'm going to image that SD card and run it here at home to see if I get different results.
-Shawn

@andrewhao
Copy link

andrewhao commented Nov 2, 2020 via email

@shawnerz
Copy link

shawnerz commented Nov 2, 2020

Thank you for your response! How do I get and install the old library?

@fniko
Copy link
Author

fniko commented Nov 2, 2020

@shawnerz
Copy link

shawnerz commented Nov 2, 2020 via email

@shawnerz
Copy link

shawnerz commented Dec 5, 2020

Oh, I forgot to leave an update.
My problem was on one Pi Zero, I got a 75% response rate. It is currently in use at a site and monitoring the temperature.
On another Pi Zero, I got a 25% response rate.
The Pi Zero'd are the same types (no Wi-Fi). Same Class 10 SD cards. The same IO's are enabled/disabled in raspi-config. I have 4 DHT22's. I cycled through DHT22's. No change. I even captured the communication waveforms with my digital oscilloscope. I compared waveforms between the 75% and 25%. Very little difference.
I followed Adafruit's instructions here: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup. Pip installs the library as adafruit_dht.
fniko's link did give me the older library. But it installs the library as Adafruit_DHT. I made the changes in my Python code, but then started getting an error about a variable in the library being used as a float. I felt myself going down a rabbit hole of code changes deep in libraries. I didn't feel like going down that hole.
On both the 75% Pi and the 25% Pi, I did sudo apt list --installed and saved the results to a file. I thought I installed the same version of Raspbian on both Pi's. I did not. I do not know which version I installed. I cat-ed /etc/os-release and they are the same.
The 25% Pi did not have all of the same GPIO packages installed. I installed them, but there was no change. I felt myself going down another rabbit hole.
But, I solved my problem. I switched to the MCP9808. The Relative Humidity (RH) measurement on the DHT22 is nice. But, I don't need it. For my application, temperature is important.
Version 2 of my temperature monitor will be installed this month. The MCP9808 responds every time when it is queried.
Thank for the suggestions, though.
-Shawn

@TerryHowe
Copy link

I changed the print to show the buffer size that it gets and on my Zero W and I'm getting between 30-65 instead of the required 80+. Maybe my sensor is even slower than most. I switched to the deprecated library and that works fine. I wonder if 80 is just too high an expectation.

@shawnerz
Copy link

I don't know. All I know is the MCP9808 responds every time.
I don't know if anyone is interested, but it's chance for me to show off some of my hardware. :) During the troubleshooting process, I wondered if there was an issue with the line levels, or timing, or something I could see with an oscilloscope. I have a capture of a waveform where I did get a result, and a waveform where I did not get a result. They look almost identical-which tells me that the problem is not a physical interface problem.
did_catch_1
didnt_catch_2
The capture was with a Digilent Analog Discovery 2 module.
Enjoy,
-Shawn

@roslynn
Copy link

roslynn commented Jan 1, 2021

@shawnerz - in a process of validating whether it is the sensor being broken or maybe PEBCAK - I check with mine too haha I used PicoScope though (PS5444D) with x10 probe and pulse-width trigger 😄
Do you maybe happen to know what standard do they use (if not custom)? It would be cool to add a decoder for it :)

dht22-packet

This data should represent something ~ 21.5*C and 55.6% humid.

Anyway, my story was - first figuring out what is the mapping for board python module and the pins (I thought it was wrong) then I realised I missed the pin name (PEBCAK) - and it finally worked 🥳 but with this message A full buffer was not returned. Try again. 🤔
I updated my code to run in a loop (similar to the simpletest one) and I can confirm that it transmits the data fine (no distortion) but the python library must be doing something wrong... (I will check the sources next!)

About 20% it is correct, other times it flickers between the mentioned message, "Checksum did not validate. Try again." and occasionally even "DHT sensor not found, check wiring" - which makes me think that maybe the connection on the board might be wacky - thresholds are not met appropriately and the information is misinterpreted. 🤷

Good luck :)

@adafruit adafruit deleted a comment from Markrwp Jan 20, 2021
@m-keller
Copy link

m-keller commented Feb 6, 2021

Experienced the same error and issue was that I have been using bitbanging instead of PulseIO (CircuitPython) because CircuitPython was not installed yet on my RPi Zero W.

I followed https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi with an additional “pip3 install sysv-ipc” (no idea why missing ...) and now my DHT22 works perfectly fine. Bitbanging is likely more of a last resort nevertheless clearly not working well - I got about 60 of the 81 required pulses when bitbanging was used.

@grigal
Copy link

grigal commented Feb 9, 2021

I'm getting the same errors A full buffer was not returned. Try again. and less frequently Checksum did not validate. while measuring every 60 seconds (with use_pulseio=False).

  • Raspberry Pi 3b Linux piberry 4.19.68-v7+ #1255
  • 3-pin DHT22 sensor
  • adafruit-circuitpython-dht==3.5.4
  • Running on a docker image, python 3.8.7

I used to use the old library, but as it was deprecated I decided to switch to this one.
Hope this will be fixed, as I wouldn't like to use the deprecated one.

@blosloos
Copy link

blosloos commented Feb 13, 2021

Same error here, continuously A full buffer was not returned. Try again. Will this be fixed in the future? However, 40% of readings at a rate of 1 per sec work with old library.

@bsolino
Copy link

bsolino commented Feb 17, 2021

Similar issues here, with a Pi Zero W.
I get the DHT sensor not found, check wiring. error more often, so I've left my full comment there: #49 (comment)

@QS3445
Copy link

QS3445 commented Mar 6, 2021

I'm having similar issue "A full buffer was not returned. Try again.." with Pi Zero WH and the DHT22, reading through these comments, there doesn't seem to be a definitive answer yet on how to fix.

My software setup seems to be good using python3, a Blinka test is good, the wiring i have checked and is good. So what can i try now.... and troubleshoot further steps I could try. Thanks for any suggestions.

@shawnerz
Copy link

shawnerz commented Mar 7, 2021

As I understand it, there is something wrong in Adafruit's library. I don't know what it is. The transmit and receive waveforms look good on a 'scope.
@roslynn Sorry I missed your comment a few months ago.
I switched to the MCP9808, commented out my DHT22 code, and haven't looked back.
The MCP9808 doesn't measure humidity. The funny thing was, here in TX, we had a big thaw after the snow. The humidity went way up in our equipment trailer. Our ham radio club's Acurite sensor reported the high humidity alert but mine didn't. :( Oh well, maybe one day in the future.

@olixr
Copy link

olixr commented Mar 28, 2021

Confirmed problem. Works okish on the Pi4 and I can get readings. About a 95%+ failure rate on the Pi zero W. I let some code run on the pi zero all night and it never once was able to get a reading. Exact same code on Pi 4 is able to get a reading 50% of the time.

Other DHT libraries work perfectly fine so it must be a software issue. Hope there is a discovery on the issue soon as we are now reverting to old / other libraries in the meantime for better stability.

@injectedfusion
Copy link

Can confirm as well the older libraries work better.

@bitsvital
Copy link

Confirmed problem. Works okish on the Pi4 and I can get readings. About a 95%+ failure rate on the Pi zero W. I let some code run on the pi zero all night and it never once was able to get a reading. Exact same code on Pi 4 is able to get a reading 50% of the time.

Other DHT libraries work perfectly fine so it must be a software issue. Hope there is a discovery on the issue soon as we are now reverting to old / other libraries in the meantime for better stability.

I did the same test late last week with same results. I concur, it has to be a software issue.

@ikorbln
Copy link

ikorbln commented May 31, 2021

Same problem here. Unfortnetly the old library did not work anymore on a fresh pi light install.

@stepanselyuk
Copy link

Thanks @m-keller for:

pip3 install sysv-ipc

Installing this package fixed the problem for me.

@alejandrobalderas
Copy link

I had the same issues when trying to read from a sensor on a pi zero however when using the pi zero 2w it works . I used the same SD card for both tests

@shawnerz
Copy link

That's very interesting. If you query the sensor every 10 seconds for 10 minutes, what is the success rate?
I wanted to try stepselyuk's suggestion. But, I haven't had the need/motivation to do it. I might in the future.
Thanks.

@jrc
Copy link

jrc commented Apr 21, 2022

From https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka/faq-troubleshooting

Some libraries, like Adafruit_CircuitPython_DHT will try to bit-bang if pulsein [sic] isn't available. Slow linux boards (<700MHz) may not be able to read the pins fast enough), you'll just have to try!

Installing libgpiod (apt-get install libgpiod2) and the missing dependency sysv-ipc (as mentioned in #33 (comment)) enables the use of pulseio.

@ryanw
Copy link

ryanw commented Apr 24, 2022

I installed sysv-ipc but it didn't seem to make any difference for me. It fails about 90% of the time. I testing from pulseio import PulseIn in the shell and that works without an exception.

@ricdijk
Copy link

ricdijk commented Jun 8, 2022

I understood the old library used a retry function, so I use a simple retry function one myself. Seems to do the job ok;

import adafruit_dht
DHT_SENSOR = adafruit_dht.DHT22(4) #use your own PIN

succes=False
tries=15
while (succes == False and tries > 0):
	try:
		temperature = DHT_SENSOR.temperature
		humidity    = DHT_SENSOR.humidity
		succes=True
	except:
		tries-=1
		print ('Warning: Adafruit read error, remaining tries:', tries)
		if (tries<1):
			raise
	
print('Temparature: ', temperature)
print('Humidity; ', humidity)

@olastor
Copy link

olastor commented Sep 25, 2022

It seems like adding the use_pulseio=True option (adafruit_dht.DHT22(board.D3, use_pulseio=True)) fixed it for me on a pi zero w.

@bananenfisch
Copy link

bananenfisch commented Feb 21, 2024

I have adopted the script from @ricdijk, because the loop stops after the 2nd try (it doesn't raise an exception, and the values are type none). The trick is to reinit the sensor (exit on exception an recreate in the loop):

#!/usr/bin/env python3
import board
import adafruit_dht

succes=False
tries=30
while (succes == False and tries > 0):
  print('run', tries)
  try:
    DHT_SENSOR = adafruit_dht.DHT22(board.D4)
    temperature = DHT_SENSOR.temperature
    humidity    = DHT_SENSOR.humidity
    if temperature is None:
      raise
    succes=True
  except:
    tries-=1
    print ('Warning: Adafruit read error, remaining tries:', tries)
    DHT_SENSOR.exit()

DHT_SENSOR.exit()
print('Temparature: ', temperature)
print('Humidity; ', humidity)

@christianstehning
Copy link

Two years late, still ran into the same problem. Following olastor's suggestion and using "use_pulseio = True" (i.s.o False, as stated in most manuals) worked for me.

@shawnerz
Copy link

shawnerz commented Mar 29, 2024 via email

@TheRaven500
Copy link

TheRaven500 commented Oct 28, 2024

Option "use_pulseio=True" does not work for me. As soon i switch from "False" to "True" i get:
RuntimeError: Timed out waiting for PulseIn message. Make sure libgpiod is installed.
"libgpiod2" is installed and "sysv-ipc" also.
It is a Pi ZeroW.
It is working with "use_pulseio=False" but very slow (need about 2min to read).
Any idea why "True" is not working?
Full output:
Unable to open chip: gpiochip0 Traceback (most recent call last): File "/scripts/./test.py", line 15, in <module> dhtDevice = adafruit_dht.DHT22(board.D17, use_pulseio=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/adafruit_dht.py", line 304, in __init__ super().__init__(False, pin, 1000, use_pulseio) File "/usr/local/lib/python3.11/dist-packages/adafruit_dht.py", line 86, in __init__ self.pulse_in = PulseIn(self._pin, maxlen=self._max_pulses, idle_state=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py", line 89, in __init__ message = self._wait_receive_msg(timeout=0.25) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py", line 107, in _wait_receive_msg raise RuntimeError( RuntimeError: Timed out waiting for PulseIn message. Make sure libgpiod is installed.
Hint: Sensor is very difficult to read!
Work a round for Pi Zero:

  • Add "dtoverlay=dht11,gpiopin=PINNR" to /boot/config.txt
  • Read Temp: awk "BEGIN {print ($(cat /sys/bus/iio/devices/iio\:device0/in_temp_input))/(1000)}"
  • Read Hum: awk "BEGIN {print ($(cat /sys/bus/iio/devices/iio\:device0/in_humidityrelative_input))/(1000)}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests