ESP8266 and MCP23017, DHT22 sensor addition

hi guys,

I need some coding help. I am trying to add DHT22 sensor via a MCP23017 expander, and it doesn’t seem to work. here’s the code.

i2c:
  sda: GPIO4
  scl: GPIO5

mcp23017:
  - id: mcp23017_hub
    address: 0x27

sensor:
  - platform: dht
    pin:
      mcp23017: mcp23017_hub
      number: 4
    temperature:
      name: Temperature
    humidity:
      name: Humidity
    model: dht22
    update_interval: 300s

If I add it directly to the ESP8266 pins, it works. Here’s the code:

sensor:
  - platform: dht
    pin: GPIO12
    temperature:
      name: Temperature
    humidity:
      name: Humidity
    model: dht22
    update_interval: 300s

There are other binary sensors and switches connected to MCP23017 and they work fine. What am I doing wrong? i get these error messages.

[15:52:45][W][dht:156]: Waiting for DHT communication to clear failed!
[15:52:45][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).

It looks like you’ve entered the wrong address. Are you sure this is correct?
Besides, I’m not sure if you can connect any sensor via MCP23xxx. MCP is probably too slow for that.

The address is correct cos I got it from the i2c scan. If the code is correct then you may be right about the MCP not being able to handle it.

I do have other binary sensors (door and windows) and switches (relays) and they work perfectly fine.

Although I do have another binary sensor (doorbell button) and that stays high all the time when using the MCP, but it works perfectly fine when connected to ESP8266 pins. Not sure what is going on here either.

Why would you want to connect DHT via MCP ? (just wondering)? I think that MCP is too slow for it, too. And, while code may be “officially” correct, it’s a question whether program really search on MCP pins for DHT. I’d say that code for DHT is written in a way that automatically looks at I2C pins…

Connect it parallel to I2C, together with MCP. I have connected in parallel:

  • MCP23017

  • BME280

  • SHT31 (all I2C)

  • DS1820 on separate pin

All work perfectly. Just make sure that addresses on I2C are different, that’s all.

1 Like

no real reason, just wanted to consolidate all the sensors to the MCP. anyways i moved over the DHT and doorbell button to ESP pins and it all works good. i guess the MCP is good just for your basic door/windows sensors and running some relays.

one more thing i noticed is that if i power the MCP with 3.3V, the piezo buzzer doesn’t work since the output voltage is arnd 2.64V. so you have to power the MCP with 5V.