SN74HC165 I/O Expander (shift register)

The SN74HC165 component allows you to use SN74HC165 shift registers as I/O expanders (Input only, use SN74HC595 for outputs) (datasheet) in ESPHome. It uses 3 wires (optionally 4) for communication.

Once configured, you can use any of the 8 pins for your projects. Up-to 256 shift registers can be daisy-chained to provide more pins, without using more GPIO pins on the controller. They are linked by connecting pin Q of the closer shift register to the pin QH of the next shift register.

# Example configuration entry
sn74hc165:
  - id: sn74hc165_hub
    clock_pin: GPIOXX
    data_pin: GPIOXX
    load_pin: GPIOXX
    clock_inhibit_pin: GPIOXX
    sr_count: 2

Configuration variables:

  • id (Required, ID): The id to use for this SN74HC165 component.

  • data_pin (Required, Pin Schema): Pin connected to SN74HC165 Serial Output (QH) input.

  • clock_pin (Required, Pin Schema): Pin connected to SN74HC165 Clock (CLK) pin.

  • load_pin (Required, Pin Schema): Pin connected to SN74HC165 Load input (SH/LD) pin.

  • clock_inhibit_pin (Optional, Pin Schema): Pin connected to SN74HC165 Clock Inhibit (CLK INH) pin. The use of it is optional, as it can be directly connected to ground.

  • sr_count (Optional, int): Number of daisy-chained shift registers, up-to 256. Defaults to 1.

Pin configuration variables:

# Individual inputs
binary_sensor:
  - platform: gpio
    name: "SN74HC165 Pin #0"
    pin:
      sn74hc165: sn74hc165_hub
      # Use pin number 0
      number: 0
      inverted: false
  • sn74hc165 (Required, ID): The id of the SN74HC165 component of the pin.

  • number (Required, int): The pin number.

  • inverted (Optional, boolean): If received value should be treated as inverted. Defaults to false.

Note

Pin number 0 is Pin A on the SN74HC165 that is furthest away from the microcontroller.

See Also