I have ESP12E devkit and AM2301 sensor, a while ago tried that with LUA firmware and it worked well, now trying micropython and it does not, reports timeout on .measure(), debugging (built my own + printf) points to: https://github.com/micropython/micropyt ... /dht.c#L67
The very first (after the am2301 gets powered) call to .measure() actually does not time out and seems succeeded even though .temperature() shows 0 (which it wrong) and consequent calls give "tmeout". Why is that?
Tried different pins, verified with LED that the pin is correct:
>>> p = machine.Pin(13, machine.Pin.OUT)
>>> p.on()
>>> p.off()
Then replaced LED with the am2301 + pullup, reset the esp, and:
>>> import machine, dht
>>> d=dht.DHT11(machine.Pin(13))
>>> d.measure()
>>> d.temperature()
0
>>> d.measure()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dht.py", line 16, in measure
OSError: [Errno 110] ETIMEDOUT
update:
I added some printfs into the 40bit loop, the ticks (%d) are (but timeout always occurs in 38th or 39th iteration):
25 5 25 25 26 73 25 25 73 74 75 26 73 27 72 25 26 27 27 27 25 25 25 74 26 73 25 26 27 74 25 26 25 26 73 74 26 26 72
which translates to:
04 ea 01 44 99
which does not seem right. Hmmm.
DHT11/AM2301 does not work
Re: DHT11/AM2301 does not work
The AM2301 is equivalent to the DHT22.
So try:
d=dht.DHT22(machine.Pin(13))
That works for me.
So try:
d=dht.DHT22(machine.Pin(13))
That works for me.
Re: DHT11/AM2301 does not work
Tried DHT22 too, same problem. The problem code is common for both so it could not have made a difference really.
Re: DHT11/AM2301 does not work
Try the following code:
from machine import Pin
import dht
# Use GPIO14 (D5 - NodeMCU)
my_dht = dht.DHT22(Pin(14, Pin.IN, Pin.PULL_UP))
# Read and show the data from DHT
my_dht.measure()
my_dht.temperature()
my_dht.humidity()
This is working on a NodeMCU board.
from machine import Pin
import dht
# Use GPIO14 (D5 - NodeMCU)
my_dht = dht.DHT22(Pin(14, Pin.IN, Pin.PULL_UP))
# Read and show the data from DHT
my_dht.measure()
my_dht.temperature()
my_dht.humidity()
This is working on a NodeMCU board.
Re: DHT11/AM2301 does not work
Thanks, this is definitely some progress - now measure() works once and the readings are correct but the consequent call to measure() fails after timeout, only reconnecting power to am2301 helps. It is not a deal breaker though as I can power it via another gpio but kinda ugly What is the problem now?
Re: DHT11/AM2301 does not work
How quickly are you using .measure() to read the AM2301?
I believe these sensors work best when read no more than once every two seconds.
I believe these sensors work best when read no more than once every two seconds.
Re: DHT11/AM2301 does not work
Yeah, I know that "feature", I tried with more than 10 seconds, same thing. The driver in nodemcu/lua firmware does some dance before talking to dht, may be mpython should too, I'll give it a try.