Wemos mini & PCF8574: I2C comm failed

Hi, i’m relative new to Home Assistant, ESPHome, …

Untill now I managed to use inputs/outputs (binary sensor/switches) on the Wemos D1 mini in combination with Home Assistant and ESPhome.

I’m trying to use a I2C I/O extender, the PCF8574AP connected to my Wemos, without any luck.

Hardware & Software:

  • Home Assistant 4.15
  • Wemos D1 Mini
  • ESPHome 1.18.0
  • Wemos is powered with USB.

Connections
Wemos 3.3V connected to pin16 of PCF8574 (VCC)
Wemos Gnd connected to pin 8 of PCF8574 (GND)
Wemos D2 (SDA) + D1 (SCL) connected to pin 15 (SDA) + 14 (SCL) of PCF8574
PCF8574 pin 1+2+3 (A0+A1+A2) connected to gnd (to set the address to 0x20)
optionally: PCF8574 pin 12 (P7) connected through a resistor → LED → gnd (pin will be used as ouput)

The log shows the communication with PCF8574 failed.
It also shows “Found i2c device at address 0x38” (somethimes multiple linex with different hex codes are showed), however I have no idea which these are since no other components are connected.
The output pin (P7) seems to be giving 1.7V (floating?)

Does anyone have an idea of what I’m doing wrong? YAML + logs below…

YAML code (validation = ok)

esphome:
  name: keuken
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "mySSID"
  password: "myPassw"

captive_portal:

# Enable logging
logger:
  level: VERY_VERBOSE

# Enable Home Assistant API
api:

ota:

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

pcf8574:
  - id: 'my_PCF8574AP'
    address: 0x20
    pcf8575: False
    
# Individual inputs
binary_sensor:
  - platform: gpio
    name: "pin_0_input_PCF8574"
    pin:
      pcf8574: my_PCF8574AP
      # Use pin number 0
      number: 0
      mode: INPUT
      inverted: False
switch:
  - platform: gpio
    name: "PCF8574 Pin #7"
    pin:
      pcf8574: my_PCF8574AP
      # Use pin number 7
      number: 7
      mode: OUTPUT
      inverted: False
      
      ```
'
Logs'

[12:14:28][I][app:105]: ESPHome version 1.18.0 compiled on Jun 4 2021, 11:49:08
[12:14:28][C][wifi:443]: WiFi:
[12:14:28][C][wifi:303]: SSID: [redacted]
[12:14:28][C][wifi:304]: IP Address: 192.168.10.24
[12:14:28][C][wifi:306]: BSSID: [redacted]
[12:14:28][C][wifi:307]: Hostname: ‘keuken’
[12:14:28][C][wifi:311]: Signal strength: -65 dB ▂▄▆█
[12:14:28][V][wifi:313]: Priority: 0.0
[12:14:28][C][wifi:315]: Channel: 6
[12:14:28][C][wifi:316]: Subnet: 255.255.255.0
[12:14:28][C][wifi:317]: Gateway: 192.168.10.1
[12:14:28][C][wifi:318]: DNS1: 8.8.8.8
[12:14:28][C][wifi:319]: DNS2: (IP unset)
[12:14:28][C][i2c:028]: I2C Bus:
[12:14:28][C][i2c:029]: SDA Pin: GPIO4
[12:14:28][C][i2c:030]: SCL Pin: GPIO5
[12:14:28][C][i2c:031]: Frequency: 50000 Hz
[12:14:28][I][i2c:033]: Scanning i2c bus for active devices…
[12:14:28][I][i2c:040]: Found i2c device at address 0x38
[12:14:28][C][pcf8574:021]: PCF8574:
[12:14:28][C][pcf8574:022]: Address: 0x20
[12:14:28][C][pcf8574:023]: Is PCF8575: NO
[12:14:28][E][pcf8574:025]: Communication with PCF8574 failed!
[12:14:28][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘pin_0_input_PCF8574’
[12:14:28][C][gpio.binary_sensor:016]: Pin: GPIO0 (Mode: INPUT)
[12:14:28][C][switch.gpio:042]: GPIO Switch ‘PCF8574 Pin #7
[12:14:28][C][switch.gpio:043]: Pin: GPIO7 (Mode: OUTPUT)
[12:14:28][C][switch.gpio:059]: Restore Mode: Restore (Defaults to OFF)
[12:14:28][C][logger:189]: Logger:
[12:14:28][C][logger:190]: Level: VERY_VERBOSE
[12:14:28][C][logger:191]: Log Baud Rate: 115200
[12:14:28][C][logger:192]: Hardware UART: UART0
[12:14:28][C][captive_portal:169]: Captive Portal:
[12:14:28][C][ota:029]: Over-The-Air Updates:
[12:14:28][C][ota:030]: Address: keuken.local:8266
[12:14:28][C][api:095]: API Server:
[12:14:28][C][api:096]: Address: keuken.local:6053
[12:14:31][VV][api.service:220]: on_ping_request: PingRequest {}
[12:14:31][VV][api.service:032]: send_ping_response: PingResponse {}
[12:14:33][VV][api.service:220]: on_ping_request: PingRequest {}
[12:14:33][VV][api.service:032]: send_ping_response: PingResponse {}
[12:14:38][VV][api.service:220]: on_ping_request: PingRequest {}

I was replied with some specific info, I’ll post it here…

As I said:
PCF8574 pin 1+2+3 (A0+A1+A2) connected to gnd (to set the address to 0x20 )

I checked again, this is really the case. A0+A1+A2 are connected to the ground, verified it.

The logs shows:
[12:14:28][I][i2c:033]: Scanning i2c bus for active devices…
[12:14:28][I][i2c:040]: Found i2c device at address at 0x38

However, this 0x38 is unknown to me. (and somethimes the log also shows other addresses) I only have the wemos connected to the I/O extender. No other devices are running (although, Home Assistant is running on the Raspberry Pi, some integrations are made in HA, like my NAS, Tado thermostat, …)

I was also pointed out to the datasheet concerning the address reference… But I’m not sure how to interpret this. The hex address should be 0x40 or 0x41 when A0-A1-A2 are low? But should I use the read or write address (I don’t want to write data to the I/O extender, so I guess read since I only want to read an input - but set (write?) an output)? Tried with 0x40 + 0x41 in my yaml also…

The 0x20 address is the address without the read/write bit (last column):

I deleted my post after realising this, hoping you had not seen it yet.

`0x38 is 0b

111000-`

For some reason A6 is high when it should be low.

This corresponds to P7 on the I/O bus which you have connected to an LED:

Try disconnecting this.

Ok…
I disconnected P7 and checked again A0+A1+A2 are connected to the ground (also changed dupont cables)
→ same issues (address 0x20 used in yaml)

I disconnected P7 and used address 0x38 in yaml
→ seems to work now. I changed the yaml to use P0 as the output → connected this one to the resistor - LED - ground. Works fine, I can turn on/off the LED with a button in HA.

[15:17:26][C][i2c:028]: I2C Bus:
[15:17:26][C][i2c:029]:   SDA Pin: GPIO4
[15:17:26][C][i2c:030]:   SCL Pin: GPIO5
[15:17:26][C][i2c:031]:   Frequency: 50000 Hz
[15:17:26][I][i2c:033]: Scanning i2c bus for active devices...
[15:17:26][I][i2c:040]: Found i2c device at address 0x38
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][pcf8574:021]: PCF8574:
[15:17:26][C][pcf8574:022]:   Address: 0x38
[15:17:26][C][pcf8574:023]:   Is PCF8575: NO
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'pin_0_input_PCF8574'
[15:17:26][C][gpio.binary_sensor:016]:   Pin: GPIO0 (Mode: INPUT)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][switch.gpio:042]: GPIO Switch 'PCF8574 Pin #4'
[15:17:26][C][switch.gpio:043]:   Pin: GPIO4 (Mode: OUTPUT)
[15:17:26][C][switch.gpio:059]:   Restore Mode: Restore (Defaults to OFF)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][logger:189]: Logger:
[15:17:26][C][logger:190]:   Level: VERY_VERBOSE
[15:17:26][C][logger:191]:   Log Baud Rate: 115200
[15:17:26][C][logger:192]:   Hardware UART: UART0
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][captive_portal:169]: Captive Portal:
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][ota:029]: Over-The-Air Updates:
[15:17:26][C][ota:030]:   Address: keuken.local:8266
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][C][api:095]: API Server:
[15:17:26][C][api:096]:   Address: keuken.local:6053
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)
[15:17:26][VV][i2c:083]: Requesting 1 bytes from 0x38:
[15:17:26][VV][i2c:113]:     Received 0b11101110 (0xEE)

So, not really clear to met yet :slight_smile:
0x38 shouldn’t be allowed, since I can only set A0-A1-A2 from 0-0-0 to 1-1-1 (= 0x20 → 0x27)

Maybe a bad connection with my breadboard? I’ll try later with a different one or cables connected directly to the I/O extender.

  • in this case, I cannot use P7 as an I/O ? (maybe same issue with others?)

Yeah the most significant bit of the full address is a 1 rather than a 0.

Try using P7 and see what happens.

Ok, tried with a different breadboard, same results. When using address 0x20, it fails. When using 0x38 it works (and the logs say it found a device at address 0x38)

I also added P7 as a switch to Yaml (still using address 0x38), and I can use this as a switch, so LED on/off works.

Very strange… Especially if I want to add a second I/O extender, I should use a different hex address (for examle A0-A1-A2 = low, low, high)

Edit/Update

  • tried without a breadboard… Address stays at 0x38.

I think I’ll get a second PCF8547 to check it it behaves the same (and if it uses a different address, also good - then I can use both)

Then assuming that the second extender has the same issue, you just have to flip the leading bit to get the new address:

0x21 is 0b0100001-

Flipping the fist bit:

0b1100001- is 0x61

However the easiest way would just be to look at the scan log for the address of the new device.

I think you’ve got 8574A parts, not 8574. The former have a base address of 0x38, explaining what you are seeing.

see: Confused about I2C addressing in PCA8574/74A - Electrical Engineering Stack Exchange

good luck

1 Like