Esphome D1 mini and pcf8575 expander

Anyone knows how to wire a D1 mini and a pcf8575 module such as this one

Also what would the code in esphome look like?

Connect the I2C bus (SDA to D2, SCL to D1) and power (Vcc to 3.3V, GND to GND).

It would look like the example in the documentation:

# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub'
    address: 0x21
    pcf8575: false

# Individual outputs
switch:
  - platform: gpio
    name: "PCF8574 Pin #0"
    pin:
      pcf8574: pcf8574_hub
      # Use pin number 0
      number: 0
      # One of INPUT or OUTPUT
      mode:
        output: true
      inverted: false

With the addition of the i2C configuration that is also required:

i2c:
  sda: 4 # D2
  scl: 5 # D1
  scan: true

This is my code:

i2c:
  - id: bus_a
    sda: GPIO15
    scl: GPIO4
    scan: true
  - id: bus_b
    sda: GPIO4 # D2
    scl: GPIO5 # D1
    scan: true

pcf8574:
  - id: 'pcf8575_hub'
    i2c_id: bus_b
    address: 0x21
    pcf8575: true


switch:
  - platform: gpio
    name: "Probe1 Green"
    pin:
      pcf8574: pcf8575_hub
      # Use pin number 0
      number: 0
      # One of INPUT or OUTPUT
      mode:
        output: true
      inverted: false

  - platform: gpio
    name: "Probe1 Red"
    pin:
      pcf8574: pcf8575_hub
      # Use pin number 1
      number: 1
      # One of INPUT or OUTPUT
      mode:
        output: true
      inverted: false

display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    id: oled
    brightness: 1
    update_interval: 0.5s
    address: 0x3C

Now my screen is not working nor is this io extender (It just keeps my rgb led on green).
I have the the RGB connected as follows to the io expander: “-” → Gnd, “G” ->P00 and “R”–> P01
rgb led

Sorry I am using an ESP32 board such as this one:

I used this but still nothing:

i2c:
  - id: bus_b
    sda: GPIO21
    scl: GPIO22
    scan: true

The pins on the io expander never turn off…

Keep getting:
Communication with PCF8574 failed!

OK got it to work finally…

What is the final config, problem and solution? I have the same board and i want to used it for extra GPIO pens for multicolor leds.

I used the following code to initialize the expansion board:

i2c:
  - id: bus_a
    sda: GPIO15
    scl: GPIO4
  - id: bus_b
    sda: GPIO13
    scl: GPIO14
    scan: true

pcf8574:
  - id: 'pcf8575_hub'
    address: 0x20
    i2c_id: bus_b
    pcf8575: true

Important field is “address” without it my setup for some reason did not work.
I had 2 i2c hence the i2c_id field requirement.

And here is an example of a pin call:

switch:
  - platform: gpio
    restore_mode: RESTORE_DEFAULT_OFF
    name: "Probe1 Green"
    id: probe1_green
    pin:
      pcf8574: pcf8575_hub
      # Use pin number 0
      number: 2
      # One of INPUT or OUTPUT
      mode:
        output: true
      inverted: false