2020-06-27 23:10:05 +02:00
SN74HC595 I/O Expander (shift register)
=======================================
.. seo ::
:description: Instructions for setting up SN74HC595 shift registers as digital port expanders in ESPHome.
The SN74HC595 component allows you to use SN74HC595 shift registers as I/O expanders
(`datasheet <http://www.ti.com/lit/ds/symlink/sn74hc595.pdf> `__ ,
2023-11-07 10:15:17 +01:00
`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.
2020-06-27 23:10:05 +02:00
2023-11-07 10:15:17 +01:00
Once configured, you can use any of the 8 pins for your projects. Up to 256 shift registers can be daisy-chained
2020-06-27 23:10:05 +02:00
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.
.. figure :: images/sn74hc595-full.jpg
:align: center
:width: 80.0%
SN74HC595 I/O Expander (shift register).
.. _SparkFun: https://www.sparkfun.com/products/13699
2023-11-07 10:15:17 +01:00
The component can be configured using :ref: `GPIO pins <config-pin_schema>` or the :ref: `SPI Bus <spi>` .
Over GPIO
---------
2020-06-27 23:10:05 +02:00
.. code-block :: yaml
# Example configuration entry
sn74hc595:
- id: 'sn74hc595_hub'
2024-05-07 07:40:12 +02:00
data_pin: GPIOXX
clock_pin: GPIOXX
latch_pin: GPIOXX
oe_pin: GPIOXX
2020-06-27 23:10:05 +02:00
sr_count: 2
# Individual outputs
switch:
- platform: gpio
name: "SN74HC595 Pin #0"
pin:
sn74hc595: sn74hc595_hub
# Use pin number 0
number: 0
2021-07-28 23:56:11 +02:00
inverted: false
2020-06-27 23:10:05 +02:00
Configuration variables:
2021-03-11 19:31:31 +01:00
***** ***** ***** ***** *** *
2020-06-27 23:10:05 +02:00
- **id** (**Required** , :ref: `config-id` ): The id to use for this SN74HC595 component.
2022-03-11 03:03:38 +01:00
- **data_pin** (**Required** , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 SER (SD) input.
- **clock_pin** (**Required** , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 SRCLK (SH_CP) pin
- **latch_pin** (**Required** , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 RCLK (ST_CP) pin
2020-06-27 23:10:05 +02:00
- **oe_pin** (*Optional* , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 OE pin
2022-12-06 19:23:11 +01:00
- **sr_count** (*Optional* , int): Number of daisy-chained shift registers, up-to 256. Defaults to `` 1 `` .
2020-06-27 23:10:05 +02:00
2023-11-07 10:15:17 +01:00
Over SPI
--------
.. code-block :: yaml
# Example configuration entry
sn74hc595:
- id: 'sn74hc595_hub'
2024-04-23 07:22:17 +02:00
type: spi
2024-05-07 07:40:12 +02:00
latch_pin: GPIOXX
oe_pin: GPIOXX
2023-11-07 10:15:17 +01:00
sr_count: 2
Configuration variables:
***** ***** ***** ***** *** *
- **id** (**Required** , :ref: `config-id` ): The id to use for this SN74HC595 component.
2024-04-23 07:22:17 +02:00
- **spi_id** (**Required** , :ref: `SPI Bus Schema <spi>` ): 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 `` .
2023-11-07 10:15:17 +01:00
- **latch_pin** (**Required** , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 RCLK (ST_CP) pin
- **oe_pin** (*Optional* , :ref: `Pin Schema <config-pin_schema>` ): Pin connected to SN74HC595 OE pin
- **sr_count** (*Optional* , int): Number of daisy-chained shift registers, up to 256. Defaults to `` 1 `` .
2024-04-23 07:22:17 +02:00
Pin configuration
-----------------
.. code-block :: yaml
# Individual outputs
switch:
- platform: gpio
name: "SN74HC595 Pin #0"
pin:
sn74hc595: sn74hc595_hub
# Use pin number 0
number: 0
inverted: false
2021-03-09 02:53:04 +01:00
- **sn74hc595** (**Required** , :ref: `config-id` ): The id of the SN74HC595 component of the pin.
2021-11-28 19:57:01 +01:00
- **number** (**Required** , int): The pin number.
2021-03-09 02:53:04 +01:00
- **inverted** (*Optional* , boolean): If all written values should be treated as inverted.
2021-07-28 23:56:11 +02:00
Defaults to `` false `` .
2021-03-09 02:53:04 +01:00
2020-06-27 23:10:05 +02:00
See Also
--------
- :doc: `switch/gpio`
- :doc: `binary_sensor/gpio`
2021-03-09 02:53:04 +01:00
- `Serial to Parallel Shifting-Out with a 74HC595 <https://www.arduino.cc/en/tutorial/ShiftOut> `__
2020-06-27 23:10:05 +02:00
- :apiref: `sn74hc595/sn74hc595.h`
- :ghedit: `Edit`