The physical pin is connected to the D4 on the Wemos DHT22 module board. So D4 to D4 and int the code that's pin2
Still same error.
Problems with the DHT example
Re: Problems with the DHT example
I soldered the wires because I was running other tests with stepper etc... And there was a glitch connection from the pads not touching the pins = (spacers to mount a breadboard).
But still get same error.
When using humidity & temperature I get 0.0 instead of 0?
Still not working though
But still get same error.
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dht.py", line 13, in measure
Still not working though
Re: Problems with the DHT example
Hey, you may want to check the pinout on the MCU. I'm using Node MCU and the GPIO 4 pin is actually marked D2 on the MCU.
Once I switched the data line to that pin, it worked like a champ.
Once I switched the data line to that pin, it worked like a champ.
-
- Posts: 2
- Joined: Sat Dec 16, 2017 8:16 am
Re: Problems with the DHT example
In my case, I had a wemos mini d1 /pro and a dht v2.0.0 shield. After burning a day debugging pins without success, it occurred to me to lift the sensor to read the back of it
Heads up, at least that shield has a DHT12 (not 11 nor 22!). That one has a I2C protocol using two wires so of course the dht example with a single pin can not ever work.
I would like to give kudos to the author of part of this code, but after looking at my browser history for half an hour I cannot find it. Sorry.
[code]
import time
from machine import I2C, Pin
class DHT12_I2C():
def __init__(self, i2c, addr):
self.i2c = i2c
self.addr = addr
self.buf = bytearray(5)
def measure(self):
buf = self.buf
self.i2c.readfrom_mem_into(self.addr, 0, buf)
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
raise Exception("checksum error")
def humidity(self):
return self.buf[0] + self.buf[1] * 0.1
def temperature(self):
t = self.buf[2] + (self.buf[3] & 0x7F) * 0.1
if self.buf[3] & 0x80:
t = -t
return t
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=20000)
d = DHT12_I2C(i2c, 92)
while True:
d.measure()
print(d.temperature(), d.humidity())
time.sleep_ms(2000)
[/code]
Heads up, at least that shield has a DHT12 (not 11 nor 22!). That one has a I2C protocol using two wires so of course the dht example with a single pin can not ever work.
I would like to give kudos to the author of part of this code, but after looking at my browser history for half an hour I cannot find it. Sorry.
[code]
import time
from machine import I2C, Pin
class DHT12_I2C():
def __init__(self, i2c, addr):
self.i2c = i2c
self.addr = addr
self.buf = bytearray(5)
def measure(self):
buf = self.buf
self.i2c.readfrom_mem_into(self.addr, 0, buf)
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
raise Exception("checksum error")
def humidity(self):
return self.buf[0] + self.buf[1] * 0.1
def temperature(self):
t = self.buf[2] + (self.buf[3] & 0x7F) * 0.1
if self.buf[3] & 0x80:
t = -t
return t
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=20000)
d = DHT12_I2C(i2c, 92)
while True:
d.measure()
print(d.temperature(), d.humidity())
time.sleep_ms(2000)
[/code]
Re: Problems with the DHT example
My DHT12 library?
https://github.com/mcauser/micropython-dht12
Waiting on Wemos to release the Pro version with AM2320, which also has dual 1-wire + I2C interfaces and is a bit more accurate than the DHT12. I wrote a library for it too.
https://github.com/mcauser/micropython-am2320
https://github.com/mcauser/micropython-dht12
Waiting on Wemos to release the Pro version with AM2320, which also has dual 1-wire + I2C interfaces and is a bit more accurate than the DHT12. I wrote a library for it too.
https://github.com/mcauser/micropython-am2320
-
- Posts: 2
- Joined: Sat Dec 16, 2017 8:16 am
Re: Problems with the DHT example
Yes!, Kudos to you.