Need help working with Wemos D1 Mini and PCF8574 expansion board

I’m trying to connect a PCF8574 to a Wemos D1 Mini. I would like to eventually daisy-chain 4 of the PCF8574 to one Wemos D1 Mini. Supposedly, you can connect up to 8.

If you daisy chain the pcf8574 board each board needs a different address. The addresses range from 0x20 to 0x27. From what I understand, you change the address by adjusting jumpers on the board. (address table). If I’m understanding this right, and I’m no expert, the image below would show an address of 0x21, correct?

Moving all the jumpers to the right (-) is the default and has an address of 0x20. When the jumpers are in that position (address 0x20) everything works great. I can connect the board to the Wemos D1 Mini, the Wemos boots, and ESPhome reads the GPIO pins on the pcf8574 board. But, with the address pins in any other position (any address other than 0x20) the Wemos D1 Mini board won’t even boot.

My connections from Wemos D1 Mini to first pcf8574
pcf8574 -> Wemos D1
vcc -> 3.3v
gnd -> G
SDA -> D2
SCL -> D1

This is my ESPhome YAML file for this device

pcf8574 configuration entry

# pcf8574 configuration entry
i2c:
  sda: D2
  scl: D1

pcf8574:
  - id: 'pcf8574_hub'
    address: 0x20
    pcf8575: False
  - id: 'pcf8574_hub2'
    address: 0x21
    pcf8575: False

# Individual outputs
binary_sensor:
  - platform: gpio
    name: "PCF8574 Pin #0"
    pin:
      pcf8574: pcf8574_hub
      # Use pin number 0
      number: 0
      # One of INPUT, INPUT_PULLUP or OUTPUT
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #1"
    pin:
      pcf8574: pcf8574_hub
      number: 1
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #2"
    pin:
      pcf8574: pcf8574_hub
      number: 2
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #3"
    pin:
      pcf8574: pcf8574_hub
      number: 3
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #4"
    pin:
      pcf8574: pcf8574_hub
      number: 4
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #5"
    pin:
      pcf8574: pcf8574_hub
      number: 5
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #6"
    pin:
      pcf8574: pcf8574_hub
      number: 6
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #7"
    pin:
      pcf8574: pcf8574_hub
      number: 7
      mode: INPUT
      inverted: False

#Hub2
  - platform: gpio
    name: "PCF8574 Pin #0"
    pin:
      pcf8574: pcf8574_hub2
      # Use pin number 0
      number: 0
      # One of INPUT, INPUT_PULLUP or OUTPUT
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #1"
    pin:
      pcf8574: pcf8574_hub2
      number: 1
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #2"
    pin:
      pcf8574: pcf8574_hub2
      number: 2
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #3"
    pin:
      pcf8574: pcf8574_hub2
      number: 3
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #4"
    pin:
      pcf8574: pcf8574_hub2
      number: 4
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #5"
    pin:
      pcf8574: pcf8574_hub2
      number: 5
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #6"
    pin:
      pcf8574: pcf8574_hub2
      number: 6
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 Pin #7"
    pin:
      pcf8574: pcf8574_hub2
      number: 7
      mode: INPUT
      inverted: False

Does anyone have an idea what I’m doing wrong?

Just to clarify, does it work with just one expansion board set to 0x21, or does it only fail once you add a second board?

I take it if you say it doesn’t boot, I assume it compiles, uploads and then fails on reboot? Is there anything in the log?

Correct, it fails even if one expansion board is set 0x21.

If I unplug the wemos, set the address to 0x20, the plug the wemos back in I get a quick flash of the LED on the wemos and within 10 seconds ESPhome connects to the board. If I then unplug the wemos, set the address to 0x21 (or any other address) and plug the wemos back in the blue LED on the wemos board doesn’t flash and ESPhome can’t find the board. The ESPho.e log just says “can’t connect”

If it is possible to connect the D1 to the computer running esphome, can you get any log via serial?

The esphome.io page says 0x21 is the default for PCF8574. All very odd.

How about just commenting out everything below this line

scl: D1

and seeing what the i2c scan shows?

If I connect the Wemos to my Pi running HA with the pcf8574 on address 0x21 I just see this in the log.

INFO Connecting to 192.168.1.31:6053 (192.168.1.31)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.31: [Errno 113] No route to host). Re-Trying in 30 seconds

Here is what the log shows after commenting out those lines
When the pcf8574 is set to 0x20

[08:04:58][C][i2c:028]: I2C Bus:
[08:04:58][C][i2c:029]:   SDA Pin: GPIO4
[08:04:58][C][i2c:030]:   SCL Pin: GPIO5
[08:04:58][C][i2c:031]:   Frequency: 50000 Hz
[08:04:58][I][i2c:033]: Scanning i2c bus for active devices...
[08:04:58][I][i2c:040]: Found i2c device at address 0x20
[08:04:58][C][logger:175]: Logger:
[08:04:58][C][logger:176]:   Level: DEBUG
[08:04:58][C][logger:177]:   Log Baud Rate: 115200
[08:04:58][C][logger:178]:   Hardware UART: UART0
[08:04:58][C][captive_portal:169]: Captive Portal:
[08:04:58][C][ota:029]: Over-The-Air Updates:
[08:04:58][C][ota:030]:   Address: 192.168.1.31:8266
[08:04:58][C][api:095]: API Server:
[08:04:58][C][api:096]:   Address: 192.168.1.31:6053
[08:05:02][D][api.connection:583]: Client 'Home Assistant 0.102.2 (192.168.1.111)' connected successfully!

And when it is set to 0x21

INFO Connecting to 192.168.1.31:6053 (192.168.1.31)
WARNING Couldn't connect to API (Error connecting to 192.168.1.31: [Errno 113] No route to host). Trying to reconnect in 25 seconds

Are you always trying the same board when attempting to set a single device to address 0x21?

Do you have a multi-meter handy?
Address 0x20 should be GND on pins 1-3,
Address 0x21 should have VCC on pin 3

I have tried two different PCF8574 boards with the same results. I have not tried to switch out the Wemos D1 Mini.

I do have a multimeter. Can you clarify what pins you are referring to? Do you mean that all 3 address pins (A0-A2) should be GND when on address 0x20? And address 0x21 should have VCC on address in A2? Or are you referring to different pins?

I’m referring to the pins 1-3 on the PCF8574 chip, these should be connected to the middle header on the corresponding address jumpers.

I checked with a multi-meter and I have GND on pins 1-3 when on 0x20 address and VCC on pin 3 when on 0x21 address.

I also tried with a new Wemos D1 Mini. Still no luck.

If I have the Wemos D1 powered up and the pcf8574 address as 0x21 the wemos won’t boot. Once I pull off that A2 address header the wemos boots up.

I bought a NodeMCU to see if it would work with that. It doesn’t I have the same issue. I even seemed to have the problem before installing ESPhome on the NodeMCU. With the PCF8574 in 0x20 the LED on the non-programmed NodeMCU flashed. With any other address I don’t get an LED flash when I power up the NodeMCU.

I think you should file an issue on the esphome github.

I filed an issue on github.

Do I need to add any resistors or anything between the pcf8574 and the Weoms D1 Mini? I currently just have bread board jumper wires connect directly from the pcf8574 to the wemos d1 mini.

I’ve just checked some of my schematics for i2c projects and i have 4k7 pullup resistors on both sda and scl to VCC.

Edit: this is when using ATmega MCUs and MCP23017 but i’m fairly certain i2c always needs pullup resistors.

Edit again: On closer inspection it looks like your module includes pullup resistors already.

Nevertheless @sturgeo you seem to be on to something. The online Amazon reviews refer to the need for pullups on sda and scl.

Whether this will help this particular problem I don’t know.

I’m getting the same issue with a different project connecting the board to my Arduino Uno. Whenever I set the address to anything other than 0x20my Arduino won’t boot up at all. Even if I only have a single board connected to the Arduino

I have 4 PCF 8574 boards. They all behave exactly the same way. I. Getting ready to send them back thinking there is some kind of manufacturing issue

I found this in the header for the arduino library. In the past I’ve had similar issues myself and couldn’t work it out. To me the it’s hardcored for that 0x21 address?!

**void begin(uint8_t address = 0x21);**