NODE MCU AMICA and multiple PCF8574 esphome

Hi,
I am trying to add two PCF8574 to my NODEMCU AMICA.

I set the two pcf9574 as and changed the jumper accordingly

  - id: 'pcf8574_hub_0'
    address: 0x20

  - id: 'pcf8574_hub_1'
    address: 0x21

My code is as follows.

esphome:
  name: node_mcu_pcf9574
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "xxxxxxx"
  password: "xxxxxxxx"
  power_save_mode: none
  
  manual_ip:  
   static_ip: 192.168.0.29
   gateway: 192.168.0.2
   subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Node Mcu Pcf9574"
    password: "WdS4utI90XHJ"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:


i2c:
   - id: bus_a
     sda: 4
     scl: 5
     scan: True
     
     
# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub_0'
    address: 0x20

  - id: 'pcf8574_hub_1'
    address: 0x21



binary_sensor:
  - platform: gpio
    name: "PCF8574 Pin #0"
    pin:
      pcf8574: pcf8574_hub_0
      number: 0
      mode: INPUT
      inverted: False
      
  - platform: gpio
    name: "PCF8574 Pin #1"
    pin:
      pcf8574: pcf8574_hub_0
      number: 1
      mode: INPUT
      inverted: False
      
      
  - platform: gpio
    name: "PCF8574 Pin #2"
    pin:
      pcf8574: pcf8574_hub_0
      number: 2
      mode: INPUT
      inverted: False   
      
      
  - platform: gpio
    name: "PCF8574 Pin #3"
    pin:
      pcf8574: pcf8574_hub_0
      number: 3
      mode: INPUT
      inverted: False  
      
  - platform: gpio
    name: "PCF8574 Pin #4"
    pin:
      pcf8574: pcf8574_hub_0
      number: 4
      mode: INPUT
      inverted: False  
      

  - platform: gpio
    name: "PCF8574 Pin #5"
    pin:
      pcf8574: pcf8574_hub_0
      number: 5
      mode: INPUT
      inverted: False  
      
      
  - platform: gpio
    name: "PCF8574 Pin #6"
    pin:
      pcf8574: pcf8574_hub_0
      number: 6
      mode: INPUT
      inverted: False 
      
      
  - platform: gpio
    name: "PCF8574 Pin #7"
    pin:
      pcf8574: pcf8574_hub_0
      number: 7
      mode: INPUT
      inverted: False 
      

      
  - platform: gpio
    name: "PCF8574 Pin #0"
    pin:
      pcf8574: pcf8574_hub_1
      number: 0
      mode: INPUT
      inverted: False 
      
      
status_led:
  pin:
    number: D4
    inverted: FALSE

The problem I experiencing is that both PIN 0 give the same output even though both addresses have been correctly identified during scan, see log below.

[11:27:48][C][wifi:415]: WiFi:
[11:27:48][C][wifi:283]:   SSID: 'xxxxxxxxx'
[11:27:48][C][wifi:284]:   IP Address: 192.168.0.29
[11:27:48][C][wifi:286]:   BSSID: xx xx
[11:27:48][C][wifi:287]:   Hostname: 'node_mcu_pcf9574'
[11:27:48][C][wifi:291]:   Signal strength: -72 dB ▂▄▆█
[11:27:48][C][wifi:295]:   Channel: 6
[11:27:48][C][wifi:296]:   Subnet: 255.255.255.0
[11:27:48][C][wifi:297]:   Gateway: 192.168.0.2
[11:27:48][C][wifi:298]:   DNS1: (IP unset)
[11:27:48][C][wifi:299]:   DNS2: (IP unset)
[11:27:48][C][i2c:028]: I2C Bus:
[11:27:48][C][i2c:029]:   SDA Pin: GPIO4
[11:27:48][C][i2c:030]:   SCL Pin: GPIO5
[11:27:48][C][i2c:031]:   Frequency: 50000 Hz
[11:27:48][I][i2c:033]: Scanning i2c bus for active devices...
[11:27:48][I][i2c:040]: Found i2c device at address 0x20
[11:27:48][I][i2c:040]: Found i2c device at address 0x21
[11:27:48][C][pcf8574:021]: PCF8574:
[11:27:48][C][pcf8574:022]:   Address: 0x20
[11:27:48][C][pcf8574:023]:   Is PCF8575: NO
[11:27:48][C][pcf8574:021]: PCF8574:
[11:27:48][C][pcf8574:022]:   Address: 0x21
[11:27:48][C][pcf8574:023]:   Is PCF8575: NO
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #0'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO0 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #1'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO1 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #2'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO2 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #3'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO3 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #4'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO4 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #5'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO5 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #6'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO6 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #7'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO7 (Mode: INPUT)
[11:27:48][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PCF8574 Pin #0'
[11:27:48][C][gpio.binary_sensor:016]:   Pin: GPIO0 (Mode: INPUT)
[11:27:48][C][logger:175]: Logger:
[11:27:48][C][logger:176]:   Level: DEBUG
[11:27:48][C][logger:177]:   Log Baud Rate: 115200
[11:27:48][C][logger:178]:   Hardware UART: UART0
[11:27:48][C][captive_portal:169]: Captive Portal:
[11:27:48][C][ota:029]: Over-The-Air Updates:
[11:27:48][C][ota:030]:   Address: 192.168.0.29:8266
[11:27:48][C][api:095]: API Server:
[11:27:48][C][api:096]:   Address: 192.168.0.29:6053
[11:28:46][D][binary_sensor:036]: 'PCF8574 Pin #0': Sending state OFF
[11:28:46][D][binary_sensor:036]: 'PCF8574 Pin #0': Sending state ON

Any ideas if my code is wrong or is there another issue here?

Regards,

Solved,
Simple mistake…it was in the name:

added 1 / 2 to differentiate between the two PCF8574 :grinning:

I added

binary_sensor:
  - platform: gpio
    name: "PCF8574 1 Pin #0"
    pin:
      pcf8574: pcf8574_hub_1
      number: 0
      mode: INPUT
      inverted: False
  - platform: gpio
    name: "PCF8574 2 Pin #0"
    pin:
      pcf8574: pcf8574_hub_2
      number: 0
      mode: INPUT
      inverted: False 
[09:43:54][D][binary_sensor:036]: 'PCF8574 2 Pin #0': Sending state OFF
[09:43:54][D][binary_sensor:036]: 'PCF8574 2 Pin #0': Sending state ON
[09:43:57][D][binary_sensor:036]: 'PCF8574 1 Pin #0': Sending state OFF
[09:43:58][D][binary_sensor:036]: 'PCF8574 1 Pin #0': Sending state ON

Regards,

1 Like