Page 1 of 1

DHT22 - Random ERRNO [116] error...

Posted: Wed Jan 12, 2022 6:34 pm
by Ambo1
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

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

Posted: Wed Jan 12, 2022 7:13 pm
by Roberthh
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.

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

Posted: Wed Jan 12, 2022 8:50 pm
by scruss
This is what DHT22s do: work most of the time, sometimes fail without warning

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

Posted: Wed Jan 12, 2022 9:31 pm
by Ambo1
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

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

Posted: Thu Jan 20, 2022 10:26 pm
by Ambo1
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