Problems with the DHT example

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
garfield_1212
Posts: 1
Joined: Thu Sep 01, 2016 2:47 pm

Problems with the DHT example

Post by garfield_1212 » Thu Sep 01, 2016 2:53 pm

Hi to all,

as written in the topic i can get the dht example to work.

>>> import dht
>>> import machine
>>> d = dht.DHT22(machine.Pin(3))
>>> d.measure()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dht.py", line 13, in measure
OSError: [Errno 110] ETIMEDOUT
>>>

after the error the REPL is frozen and i have to reset the module. m using a esp12 module and a dht22 sensor

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Problems with the DHT example

Post by SpotlightKid » Sat Sep 03, 2016 2:12 pm

There is no pin with number 3 on esp8266 boards. Available pins are: 0, 2, 4, 5, 12, 13, 14, 15, 16.

On the Pyboard and the WiPy you can use

Code: Select all

import pb
pyb.Pin.board
to see what pins are available, but, alas, on the esp8266 port machine.Pin has no such attribute.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Problems with the DHT example

Post by deshipu » Sat Sep 03, 2016 7:52 pm

Actually there is gpio3, but it's used for the UART connection. You can use it for other things if you don't use UART.

Of course, if you start using it, the REPL, which uses UART, will stop working.

quantalume
Posts: 15
Joined: Thu Aug 04, 2016 3:04 pm

Re: Problems with the DHT example

Post by quantalume » Sun Sep 04, 2016 2:44 am

I'm getting the "ETIMEDOUT" message every time I try to use a DHT22 (AM2302) as well. I'm using a Lolin NodeMCU V3. I've tried with and without a pullup resistor. The device works fine on a WiPy (without a pullup resistor). I've even tried configuring the pin as output and toggling it just to make sure I have the pin numbering correct (NodeMCU pin number isn't same as GPIO #).

Code: Select all

>>> from machine import Pin
>>> import dht
>>> d=dht.DHT22(Pin(14))
>>> d.measure()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dht.py", line 13, in measure
OSError: [Errno 110] ETIMEDOUT
Is this a time/frequency issue? machine.freq() returns 80000000. I tried machine.freq(160000000) and then running the code but no joy.

quantalume
Posts: 15
Joined: Thu Aug 04, 2016 3:04 pm

Re: Problems with the DHT example

Post by quantalume » Mon Sep 05, 2016 6:58 pm

After rewiring my circuit onto a different proto board, it appears to be working now. Same NodeMCU and same sensor. There must have been a faulty connection. It does not appear to need a pullup resistor; the internal pullup appears to be sufficient, at least for short leads to the sensor.

orsisam
Posts: 9
Joined: Mon Sep 05, 2016 5:58 pm

Re: Problems with the DHT example

Post by orsisam » Tue Sep 06, 2016 4:48 am

[quote="SpotlightKid"]There is no pin with number 3 on esp8266 boards. Available pins are: 0, 2, 4, 5, 12, 13, 14, 15, 16.

On the Pyboard and the WiPy you can use

[code]import pb
pyb.Pin.board[/code]

to see what pins are available, but, alas, on the esp8266 port [i]machine.Pin[/i] has no such attribute.[/quote]

Why I can't import this library? I am using esp8266 WeMos D1

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: Problems with the DHT example

Post by SpotlightKid » Tue Sep 06, 2016 8:12 am

The "pyb" module isn't present on the esp8266 port, the Pin class is in the "machine" module, but it (annoyingly) has a slightly different interface.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Problems with the DHT example

Post by deshipu » Tue Sep 06, 2016 2:18 pm

All gpio pins, 0-16, are "available". Some of them will just have undesirable side effects if you start using them. The pins 1 and 3 are used for the UART, the pins 6-11 for the flash memory. They are left available because they may be useful if you are careful and know what you are doing.

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

Re: Problems with the DHT example

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

Sorry I didn't quite get why the pin could not be read by the DHT.py (i'm on pin 4)

Or what do I have to change to let it read pin 4.

This on a Wemos D1 mini (pro)

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Problems with the DHT example

Post by deshipu » Fri Jan 20, 2017 9:16 am

First of all, what *physical* pin are you connecting to? The pin marked D4 on the D1 Mini is actually pin 2, and the pin 4 is marked on the D1 Mini as D2...

Post Reply