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.
blckpstv
Posts: 28
Joined: Thu Dec 15, 2016 9:11 pm
Location: Belgium

Re: Problems with the DHT example

Post by blckpstv » Fri Jan 20, 2017 10:49 pm

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.

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

Re: Problems with the DHT example

Post by blckpstv » Sat Jan 21, 2017 8:56 pm

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.

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dht.py", line 13, in measure
When using humidity & temperature I get 0.0 instead of 0?

Still not working though

Empyreal
Posts: 1
Joined: Mon Sep 18, 2017 1:22 am

Re: Problems with the DHT example

Post by Empyreal » Mon Sep 18, 2017 1:35 am

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.

albertogomcas
Posts: 2
Joined: Sat Dec 16, 2017 8:16 am

Re: Problems with the DHT example

Post by albertogomcas » Sat Dec 16, 2017 8:29 am

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 :roll:

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]

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: Problems with the DHT example

Post by mcauser » Tue Dec 26, 2017 2:02 am

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

albertogomcas
Posts: 2
Joined: Sat Dec 16, 2017 8:16 am

Re: Problems with the DHT example

Post by albertogomcas » Tue Dec 26, 2017 7:19 am

Yes!, Kudos to you.

Post Reply