Micropython docs - DHT

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Micropython docs - DHT

Post by blckpstv » Thu Jan 19, 2017 6:04 pm

I followed and correctly wired my DHT11 & 22 to my wemos D1 mini.

When d.measure() I get

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dht.py", line 13, in measure
OSError: [Errno 110] ETIMEDOUT
When d.humidity() I get & same for temperature

Code: Select all

0

blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Re: Micropython docs - DHT

Post by blckpstv » Thu Jan 19, 2017 8:13 pm

blckpstv wrote:I followed and correctly wired my DHT11 & 22 to my wemos D1 mini.

When d.measure() I get

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dht.py", line 13, in measure
OSError: [Errno 110] ETIMEDOUT
When d.humidity() I get & same for temperature

Code: Select all

0
Do I need to copy the dht.py to the board?

User avatar
ernitron
Posts: 84
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

Re: Micropython docs - DHT

Post by ernitron » Tue Jan 24, 2017 9:17 pm

It happened the same to me. No way to make it working with DHT11.
I use the dht11 shield from WeMos and D1 mini.

Can somebody confirm latest firmware and library work properly?

mws
Posts: 3
Joined: Mon Nov 14, 2016 7:13 pm

Re: Micropython docs - DHT

Post by mws » Wed Jan 25, 2017 5:02 pm

Sorry if I miss the point.

I have a Adafruit Feather HUZZAH ESP8266 here and a DHT22 (same with DHT11).

I have Micropython 1.8.6 and no libs installed, just my own (mylib).

Code: Select all

import machine
def get_dht():
    import dht
    at = dht.DHT22(machine.Pin(13))
    at.measure()
    return(at.temperature(), at.humidity())

Code: Select all

>>> import mylib
>>> mylib.get_dht()
(16.7, 44.29999)
The wiring is as in the attachement, resistor is 10k.
Attachments
2017-01-25_17-59-33.png
2017-01-25_17-59-33.png (97.79 KiB) Viewed 3218 times

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Micropython docs - DHT

Post by randmor » Wed Aug 29, 2018 2:47 pm

To "mws". Your code example looks hopeful, but I have two problems with your wiring diagram. First, the data line from your DHT22 looks to be connected to GPIO14, but your code example uses GPIO13. The second problem is with the 10K ohm resistor which is supposed to be a pull-up resistor. Your drawing shows it used 'in series' between the data output line of the DHT22 and GPIO14. It should be wired from the data output line and 3V3. These two issues may mislead some readers. I am in the process of attempting to use a DHT-11 on an ESP-8266 using MicroPython for ESP8266 version 1.9.4. I will let you know if I got it to work. I will be using a NodeMCU ESP8266 board and I will attach the data output of the DHT-11 to GPIO4 (the "D2" pin on the NodeMCU board). Additionally, I will be modifying line 4 of your 'mylib.py' code as follows:

at=dht.DHT11(machine.Pin(4))

Notice the DHT11 method is being used and machine.Pin(4) (i.e. GPIO4) is being used.

Finally, I will save the source file as 'mylib.py' and use the 'ampy' utility to copy this file over to the persistent file system that MicroPython has set up in the ESP8266 flash memory. The 'ampy' utility was written by Tony DeCola at Adafruit and you can search the internet to find how to install and use. There is also a YouTube video on it. Quite useful. Now back to my experiment...

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Micropython docs - DHT

Post by randmor » Thu Aug 30, 2018 2:05 pm

Update. Tried the code proposed by "mws" and it fails with the same timeout error. Here's the code I used. It straightens out
the code by mws (don't really need the function, it just convolutes things). Not sure why he had to import dht.py every time
he calls his loop (tried his code but it also fails).

# Modified code example from this URL:
# viewtopic.php?f=16&t=2930&p=29723#p29723

import machine
import time
import dht

while True:
at = dht.DHT11(machine.Pin(4))
at.measure()
sleep_ms(1000)
print(at.temperature(), at.humidity())
sleep_ms(2000)

# Final error message points to a time out error in the "dht.py" module:
# ... In file "dht.py", line 16, in measure\r\nOSError: [Errno 110] ETIMEOUT\r\n')
#
# See if can locate file "dht.py", suspect it is burnt into the image file
# "esp8266-20180511-v1.9.4.bin". So, will need to go back to GitHub source code.
#

So, I guess we need to focus on the "dht.py" module in MicroPython v1.9.4 to find the
cause of the problem. [Seems I read somewhere that the later version(s) implement a
multi-threading capability which disrupts the dht support. That the timing for accessing
data from the DHT modules is very touchy. But consider this 'heresay'.]

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: Micropython docs - DHT

Post by randmor » Thu Aug 30, 2018 3:22 pm

I reloaded Micropython for ESP8266 latest build (08/30/2018) onto my ESP8266 board using esptool.py.exe (I'm a Windows user), and tried the script again and got the same error:

... File "dht.py", line 16, in measure\r\nOSError: [Errno 110] ETIMEDOUT\r\n')

So, it seems the developer has not corrected this bug to date. Not sure if MicroPython source is actually on GitHub, but will search there next.

LaurentStrodiot
Posts: 1
Joined: Sun May 05, 2019 8:17 pm

Re: Micropython docs - DHT

Post by LaurentStrodiot » Sun May 05, 2019 8:26 pm

For the issue related to measurement using DHT22 on ESP8266: OSError: [Errno 110] ETIMEOUT
I realized that the min Voltage for the DHT sensor to work is 3.3V so power supply may be an issue if you have, like me, an additional TM1637 led module, I measured the voltage at 3.0 with both module connected to the 3.3V pin, so I guess this may have caused the issue.

I change the VCC of the DHT22 and of my TM1637 to the Vin of the ESP8266 (supplied by the USB port of my computer, measure the voltage at 4.5 V) and the issue was gone, I was able to measure without any issue the T° and Humidity again along with my TM1637 module displaying the measured T°.


Maybe you can try the same ? Let me know.

Laurent

Post Reply