Hi everybody,
can you please take a look at my code below? I am trying to connect multiple MCP23017
to a WeMos D1 Mini
.
The wiring is
3V3 (MC) > VCC (#1)
GND (MC) > GND (#1)
D8 (MC) > SDA (#1)
D7 (MC) > SCL (#1)
VCC (#1) > VCC (#2)
GND (#1) > GND (#2)
D6 (MC) > SDA (#2)
D5 (MC) > SCL (#2)
Then there is an binary_sensor
(in this case, a button) connected to each VCC and A0 per MCP23017 (it won’t work when I use B0).
However, currently, both button entities in Home Assistant will initially show as OFF
(which is correct), but then switch to ON
when I just press one of the buttons. I expected them to react to the corresponding MCP23017 individually.
Is this a code or a wiring issue? I assumed because I use different SDA/SCL pins on the D1 Mini, both MCP23017 could be on 0x20
. I didn’t see anything in the docs for the MCP23017 that would allow me to use 0x20
on one, and 0x21
on the other.
And: can I utilize even more than two MCP23017 on this one D1 Mini (or similar MC running ESPHome)? This project was supposed to provide 18 binary_sensors alone; 18 buttons would mean >2 individual MCP23017 devices. If possible, I’d even like to have additional LEDs, perhaps sensors, and tactile switch(es), so at the very least, I’d need those three MCP23017 running.
This is supposed to be a portable Home Assistant controller. It would be supposed to always be connected to power via USB cable; however, this cable would actually charge the power bank inside this box, which, in turn, would be connected to the WeMos D1 Mini
. So you could move around with it a bit without losing connectivity, but eventually have to plug it in to make sure the power bank won’t die.
Thank you in advance for your ideas
substitutions:
devicename: holzbox
upper_devicename: Holzbox
platform: ESP8266
board: d1_mini
esphome:
name: $devicename
platform: $platform
board: $board
wifi:
ssid: !secret wifineu_ssid
password: !secret wifineu_pass
use_address: $devicename.local
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${upper_devicename} Fallback Hotspot"
password: !secret pw_accesspoint
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret pw_api
ota:
safe_mode: true # WICHTIG, falls mal was nicht klappt
password: !secret pw_ota
web_server:
port: 80
auth:
username: !secret user_http
password: !secret pw_http
i2c:
- id: bus_a
sda: D8
scl: D7
scan: true
- id: bus_b
sda: D6
scl: D5
scan: true
mcp23017:
- id: 'mcp23017_hub'
address: 0x20
- id: 'zweiter_hub'
# I also tried address: 0x21 here
address: 0x20
binary_sensor:
- platform: gpio
name: "MCP23017 Pin #1"
pin:
mcp23017: mcp23017_hub
# Use pin number 1
number: 0
# One of INPUT or INPUT_PULLUP
mode: INPUT_PULLUP
inverted: true
- platform: gpio
name: "MCP23017 ZWEI Pin #1"
pin:
mcp23017: zweiter_hub
# Use pin number 1
number: 0
# One of INPUT or INPUT_PULLUP
mode: INPUT_PULLUP
inverted: true