DHT22 - Random ERRNO [116] error...

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Ambo1
Posts: 7
Joined: Thu Mar 25, 2021 8:06 pm

DHT22 - Random ERRNO [116] error...

Post by Ambo1 » Wed Jan 12, 2022 6:34 pm

Hi,

I am using a DHT22 temperature / humidity sensor but am having an issue with it when trying to read it.

ESP32 will every now and then (can run for minutes or days) stop due to the error as listed below: -

MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32
Type "help()" for more information.

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 11, in read_humidity
File "dht.py", line 17, in measure
OSError: [Errno 116] ETIMEDOUT
>>>

Code: Select all

import dht
import machine
from machine import Pin
import time


dht22 = dht.DHT22(machine.Pin(16))

def read_humidity():

    dht22.measure()
    time.sleep(0.5)
    humidity = dht22.humidity()
    print(humidity)
    temperature = dht22.temperature()
    print(temperature)

while True:
    time.sleep(2)
    read_humidity()
I have tried using a TRY and EXCEPT in my code but this does not work as once the error has happened the only way to clear it is a power cycle...

Any help would be much appreciated, thanks

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: DHT22 - Random ERRNO [116] error...

Post by Roberthh » Wed Jan 12, 2022 7:13 pm

as once the error has happened the only way to clear it is a power cycle...
Is it the DHT22 that needs a power cycle? If yes, you could try to supply the DHT22 from a GPIO pin, and cycle that pin in case of an error. The DHT22 supply current is 1.5 mA. That can easily be driven by a GPIO.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: DHT22 - Random ERRNO [116] error...

Post by scruss » Wed Jan 12, 2022 8:50 pm

This is what DHT22s do: work most of the time, sometimes fail without warning

Ambo1
Posts: 7
Joined: Thu Mar 25, 2021 8:06 pm

Re: DHT22 - Random ERRNO [116] error...

Post by Ambo1 » Wed Jan 12, 2022 9:31 pm

Roberthh wrote:
Wed Jan 12, 2022 7:13 pm
as once the error has happened the only way to clear it is a power cycle...
Is it the DHT22 that needs a power cycle? If yes, you could try to supply the DHT22 from a GPIO pin, and cycle that pin in case of an error. The DHT22 supply current is 1.5 mA. That can easily be driven by a GPIO.
Interesting point, I will give it a try... thanks for your input

Regards Dave

Ambo1
Posts: 7
Joined: Thu Mar 25, 2021 8:06 pm

Re: DHT22 - Random ERRNO [116] error...

Post by Ambo1 » Thu Jan 20, 2022 10:26 pm

Roberthh wrote:
Wed Jan 12, 2022 7:13 pm
as once the error has happened the only way to clear it is a power cycle...
Is it the DHT22 that needs a power cycle? If yes, you could try to supply the DHT22 from a GPIO pin, and cycle that pin in case of an error. The DHT22 supply current is 1.5 mA. That can easily be driven by a GPIO.
Hi, I did as you suggested and yes it was only the DHT22 that needed resetting!! Connected the supply to one of the GPIO pins and power up only when reading the sensor and then turning back off... been running non stop since!! Thanks for your input, Dave

Post Reply