Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

DHT11 crashes with OverflowError
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DHT11 crashes with OverflowError

by infinisean on Fri Jun 05, 2020 5:56 pm

Hi all.

I am having some trouble getting my DHT11 sensor to work consistently with my Raspberry Pi 4 running the latest raspbianand python.
I have tried this with several DHT11 sensors which all exhibit the same error with this code but all run just fine with Arduino, so I am confident this is a code issue rather than a hardware issue.

It keeps crashing with an overflow error after just a few reads. Please see below.
Any insight would be greatly appreciated.

Thanks!

Error:
Code: Select all | TOGGLE FULL SIZE
py3) pi@MushPi4:~ $ python dhttest.py | tee dht.output
Time: 06/05/2020 17:40:12   Temp: 24.0 C    75.2 F     Humidity: 57%
Traceback (most recent call last):
  File "dhttest.py", line 22, in <module>
    temperature_c = dhtDevice.temperature
  File "/home/pi/py3/lib/python3.7/site-packages/adafruit_dht.py", line 242, in temperature
    self.measure()
  File "/home/pi/py3/lib/python3.7/site-packages/adafruit_dht.py", line 187, in measure
    pulses = self._get_pulses_pulseio()
  File "/home/pi/py3/lib/python3.7/site-packages/adafruit_dht.py", line 126, in _get_pulses_pulseio
    pulses.append(self.pulse_in.popleft())
OverflowError: unsigned short is greater than maximum


Python (virtualenv):
(py3) pi@MushPi4:~ $ python --version
Python 3.7.3

Code:

Code: Select all | TOGGLE FULL SIZE
(py3) pi@MushPi4:~ $ cat dhttest.py
import time
import board
import sys
import adafruit_dht
from datetime import datetime

# datetime object containing current date and time
now = datetime.now()

# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D4)

while True:
    try:
                # Print the values to the serial port
        dt_string = now.strftime("%m/%d/%Y %H:%M:%S")
        #print(dt_string)
        temperature_c = dhtDevice.temperature
        temperature_f = temperature_c * (9 / 5) + 32
        humidity = dhtDevice.humidity
        print("Time: {}   Temp: {:1.1f} C    {:.1f} F     Humidity: {}% ".format(dt_string, temperature_c, temperature_f,  humidity))
        #print("Temp:")
        #print('{:.1f} F'.format(temperature_f))
    except RuntimeError as error:
        # Errors happen fairly often, DHT's are hard to read, just keep going
        print(error.args[0])
    sys.stdout.flush()
    time.sleep(10.0)

infinisean
 
Posts: 5
Joined: Thu May 28, 2020 9:18 pm

Re: DHT11 crashes with OverflowError

by siddacious on Tue Jun 30, 2020 12:52 pm

Please use the \[code\] tags around any code, errors, etc. for easier reading. I've edited your post to include them.

Please also post a clear, well lit picture of your setup that makes it easy to see all the connections.

siddacious
 
Posts: 275
Joined: Fri Apr 21, 2017 3:09 pm

Please be positive and constructive with your questions and comments.