SN74HC595 I/O Expander (shift register)

The SN74HC595 component allows you to use SN74HC595 shift registers as I/O expanders (datasheetExternal link, SparkFun_) in ESPHome. It uses 3 wires (optionally 4) for communication. Optionally, it can be added to a SPI bus to allow sharing pins with other components.

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.

Use of the OE pin is optional. If used, the pin should be pulled up externally.

SparkFunExternal link

The component can be configured using GPIO pins or the SPI Bus.

Over GPIO Copy link to header

# Example configuration entry
sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: GPIOXX
    clock_pin: GPIOXX
    latch_pin: GPIOXX
    oe_pin: GPIOXX
    sr_count: 2

# Individual outputs
switch:
  - platform: gpio
    name: "SN74HC595 Pin #0"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: false

Configuration variables: Copy link to header

  • id (Required, ID): The id to use for this SN74HC595 component.
  • data_pin (Required, Pin Schema): Pin connected to SN74HC595 SER (SD) input.
  • clock_pin (Required, Pin Schema): Pin connected to SN74HC595 SRCLK (SH_CP) pin
  • latch_pin (Required, Pin Schema): Pin connected to SN74HC595 RCLK (ST_CP) pin
  • oe_pin (Optional, Pin Schema): Pin connected to SN74HC595 OE pin
  • sr_count (Optional, int): Number of daisy-chained shift registers, up-to 256. Defaults to 1.

Over SPI Copy link to header

# Example configuration entry
sn74hc595:
  - id: 'sn74hc595_hub'
    type: spi
    latch_pin: GPIOXX
    oe_pin: GPIOXX
    sr_count: 2

Configuration variables: Copy link to header

  • id (Required, ID): The id to use for this SN74HC595 component.
  • spi_id (Required, SPI Bus Schema): The SPI bus to use. This will automatically be set to the ID of the SPI bus if there is only one.
  • type (Required, string): Must be spi.
  • latch_pin (Required, Pin Schema): Pin connected to SN74HC595 RCLK (ST_CP) pin
  • oe_pin (Optional, Pin Schema): Pin connected to SN74HC595 OE pin
  • sr_count (Optional, int): Number of daisy-chained shift registers, up to 256. Defaults to 1.

Pin configuration Copy link to header

# Individual outputs
switch:
  - platform: gpio
    name: "SN74HC595 Pin #0"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: false
  • sn74hc595 (Required, ID): The id of the SN74HC595 component of the pin.
  • number (Required, int): The pin number.
  • inverted (Optional, boolean): If all written values should be treated as inverted. Defaults to false.

See Also Copy link to header

CURRENT