2019-10-17 16:28:54 +02:00
|
|
|
MCP230xx I/O Expander
|
2019-03-14 16:41:37 +01:00
|
|
|
=====================
|
|
|
|
|
|
|
|
.. seo::
|
2020-04-12 21:07:25 +02:00
|
|
|
:description: Instructions for setting up MCP23008, MCP23016 or MCP23017 digital port expander in ESPHome.
|
2021-11-16 03:19:33 +01:00
|
|
|
:image: mcp230xx.svg
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
The Microchip MCP230xx series of general purpose, parallel I/O expansion for I²C bus applications.
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
**Supported Variants :**
|
2019-03-14 16:41:37 +01:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
- :ref:`mcp23008-label`
|
|
|
|
- :ref:`mcp23016-label`
|
|
|
|
- :ref:`mcp23017-label`
|
2019-03-14 16:41:37 +01:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
.. _mcp23008-label:
|
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
MCP23008 Component
|
|
|
|
------------------
|
2020-04-12 21:07:25 +02:00
|
|
|
|
|
|
|
The MCP23008 component (`datasheet <http://ww1.microchip.com/downloads/en/devicedoc/21919e.pdf>`__,
|
|
|
|
`Adafruit <https://www.adafruit.com/product/593>`__) has 8 GPIOs that can be configured independently.
|
2019-03-14 16:41:37 +01:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
2020-04-12 21:07:25 +02:00
|
|
|
mcp23008:
|
|
|
|
- id: 'mcp23008_hub'
|
2019-03-14 16:41:37 +01:00
|
|
|
address: 0x20
|
|
|
|
|
|
|
|
# Individual outputs
|
|
|
|
switch:
|
|
|
|
- platform: gpio
|
2020-04-12 21:07:25 +02:00
|
|
|
name: "MCP23008 Pin #0"
|
2019-03-14 16:41:37 +01:00
|
|
|
pin:
|
2021-03-07 20:24:08 +01:00
|
|
|
mcp23xxx: mcp23008_hub
|
2019-03-14 16:41:37 +01:00
|
|
|
# Use pin number 0
|
|
|
|
number: 0
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
output: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2020-04-12 21:07:25 +02:00
|
|
|
|
|
|
|
# Individual inputs
|
|
|
|
binary_sensor:
|
|
|
|
- platform: gpio
|
|
|
|
name: "MCP23008 Pin #1"
|
|
|
|
pin:
|
2021-03-07 20:24:08 +01:00
|
|
|
mcp23xxx: mcp23008_hub
|
2020-04-12 21:07:25 +02:00
|
|
|
# Use pin number 1
|
|
|
|
number: 1
|
|
|
|
# One of INPUT or INPUT_PULLUP
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
input: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2019-03-14 16:41:37 +01:00
|
|
|
|
|
|
|
Configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
************************
|
2019-03-14 16:41:37 +01:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
- **id** (**Required**, :ref:`config-id`): The id to use for this MCP23008 component.
|
2019-03-14 16:41:37 +01:00
|
|
|
- **address** (*Optional*, int): The I²C address of the driver.
|
2020-04-12 21:07:25 +02:00
|
|
|
Defaults to ``0x20``.
|
2021-11-28 19:57:01 +01:00
|
|
|
- **open_drain_interrupt** (*Optional*, boolean): Configure the interrupt pin to open-drain mode.
|
2021-02-13 10:07:15 +01:00
|
|
|
Useful when the MCP23008's power supply is greater than 3.3 volts. Note that this pin
|
|
|
|
will require a pull-up resistor (to 3.3 volts) when this mode is enabled.
|
2019-03-14 16:41:37 +01:00
|
|
|
|
2021-03-09 02:53:04 +01:00
|
|
|
Pin configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
****************************
|
2021-03-07 20:24:08 +01:00
|
|
|
|
|
|
|
- **mcp23xxx** (**Required**, :ref:`config-id`): The id of the MCP23008 component.
|
|
|
|
- **interrupt** (*Optional*): Set this pin to trigger the INT pin on the component. Can be one of ``CHANGE``, ``RISING``, ``FALLING``.
|
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 read and written values
|
2021-07-28 23:56:11 +02:00
|
|
|
should be treated as inverted. Defaults to ``false``.
|
2021-03-09 02:53:04 +01:00
|
|
|
- **mode** (*Optional*, string): A pin mode to set for the pin at. One of ``INPUT`` or ``OUTPUT``.
|
2021-03-07 20:24:08 +01:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
.. _mcp23016-label:
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
MCP23016 Component
|
|
|
|
------------------
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
The MCP23016 component (`datasheet <http://ww1.microchip.com/downloads/en/devicedoc/20090c.pdf>`__)
|
|
|
|
has 16 GPIOs and can be configured the same way than the other variants.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
The 'INPUT_PULLUP' mode is not supported on this device.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
mcp23016:
|
|
|
|
- id: 'mcp23016_hub'
|
|
|
|
address: 0x20
|
|
|
|
|
|
|
|
# Individual outputs
|
|
|
|
switch:
|
|
|
|
- platform: gpio
|
|
|
|
name: "MCP23016 Pin #0"
|
|
|
|
pin:
|
|
|
|
mcp23016: mcp23016_hub
|
|
|
|
# Use pin number 0
|
|
|
|
number: 0
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
output: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2020-04-12 21:07:25 +02:00
|
|
|
|
|
|
|
# Individual inputs
|
|
|
|
binary_sensor:
|
|
|
|
- platform: gpio
|
|
|
|
name: "MCP23016 Pin #1"
|
|
|
|
pin:
|
|
|
|
mcp23016: mcp23016_hub
|
|
|
|
# Use pin number 1
|
|
|
|
number: 1
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
input: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2020-04-12 21:07:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
Configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
************************
|
2020-04-12 21:07:25 +02:00
|
|
|
|
|
|
|
- **id** (**Required**, :ref:`config-id`): The id to use for this MCP23016 component.
|
|
|
|
- **address** (*Optional*, int): The I²C address of the driver.
|
|
|
|
Defaults to ``0x20``.
|
|
|
|
|
2021-03-09 02:53:04 +01:00
|
|
|
Pin configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
****************************
|
2021-03-07 20:24:08 +01:00
|
|
|
|
2021-03-09 02:53:04 +01:00
|
|
|
- **mcp23xxx** (**Required**, :ref:`config-id`): The id of the MCP23016 component.
|
2021-03-07 20:24:08 +01:00
|
|
|
- All other options from :ref:`Pin Schema <config-pin_schema>`
|
|
|
|
|
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
.. _mcp23017-label:
|
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
MCP23017 Component
|
|
|
|
------------------
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
The MCP23017 component allows you to use MCP23017 I/O expanders
|
|
|
|
(`datasheet <http://ww1.microchip.com/downloads/en/devicedoc/20001952c.pdf>`__,
|
|
|
|
`Adafruit <https://www.adafruit.com/product/732>`__) in ESPHome.
|
|
|
|
It uses the :ref:`I²C Bus <i2c>` for communication.
|
|
|
|
|
|
|
|
Once configured, you can use any of the 16 pins as
|
|
|
|
pins for your projects. Within ESPHome they emulate a real internal GPIO pin
|
|
|
|
and can therefore be used with many of ESPHome's components such as the GPIO
|
|
|
|
binary sensor or GPIO switch.
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2022-01-26 21:14:17 +01:00
|
|
|
GPIO pins in the datasheet are labelled A0 to A7 and B0 to B7, these are mapped
|
|
|
|
consecutively in this component to numbers from 0 to 15.
|
|
|
|
|
2019-10-17 16:28:54 +02:00
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
2020-04-12 21:07:25 +02:00
|
|
|
mcp23017:
|
|
|
|
- id: 'mcp23017_hub'
|
2019-10-17 16:28:54 +02:00
|
|
|
address: 0x20
|
|
|
|
|
|
|
|
# Individual outputs
|
|
|
|
switch:
|
|
|
|
- platform: gpio
|
2022-01-26 21:14:17 +01:00
|
|
|
name: "MCP23017 Pin A0"
|
2019-10-17 16:28:54 +02:00
|
|
|
pin:
|
2021-03-07 20:24:08 +01:00
|
|
|
mcp23xxx: mcp23017_hub
|
2022-01-26 21:14:17 +01:00
|
|
|
# Use pin A0
|
2019-10-17 16:28:54 +02:00
|
|
|
number: 0
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
output: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
# Individual inputs
|
|
|
|
binary_sensor:
|
|
|
|
- platform: gpio
|
2022-01-26 21:14:17 +01:00
|
|
|
name: "MCP23017 Pin B7"
|
2020-04-12 21:07:25 +02:00
|
|
|
pin:
|
2021-03-07 20:24:08 +01:00
|
|
|
mcp23xxx: mcp23017_hub
|
2022-01-26 21:14:17 +01:00
|
|
|
# Use pin B7
|
|
|
|
number: 15
|
2020-04-12 21:07:25 +02:00
|
|
|
# One of INPUT or INPUT_PULLUP
|
2021-11-03 19:55:26 +01:00
|
|
|
mode:
|
|
|
|
input: true
|
|
|
|
pullup: true
|
2021-07-28 23:56:11 +02:00
|
|
|
inverted: false
|
2019-10-17 16:28:54 +02:00
|
|
|
|
|
|
|
Configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
************************
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2020-04-12 21:07:25 +02:00
|
|
|
- **id** (**Required**, :ref:`config-id`): The id to use for this MCP23017 component.
|
2019-10-17 16:28:54 +02:00
|
|
|
- **address** (*Optional*, int): The I²C address of the driver.
|
2020-04-12 21:07:25 +02:00
|
|
|
Defaults to ``0x20``.
|
2021-11-28 19:57:01 +01:00
|
|
|
- **open_drain_interrupt** (*Optional*, boolean): Configure interrupt pins to open-drain mode.
|
2021-02-13 10:07:15 +01:00
|
|
|
Useful when the MCP23017's power supply is greater than 3.3 volts. Note that these pins
|
|
|
|
will require pull-up resistors (to 3.3 volts) when this mode is enabled.
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2021-03-09 02:53:04 +01:00
|
|
|
Pin configuration variables:
|
2021-03-11 19:31:31 +01:00
|
|
|
****************************
|
2021-03-07 20:24:08 +01:00
|
|
|
|
|
|
|
- **mcp23xxx** (**Required**, :ref:`config-id`): The id of the MCP23017 component.
|
|
|
|
- **interrupt** (*Optional*): Set this pin to trigger the port INT pin on the component. Can be one of ``CHANGE``, ``RISING``, ``FALLING``.
|
|
|
|
- All other options from :ref:`Pin Schema <config-pin_schema>`
|
|
|
|
|
2019-10-17 16:28:54 +02:00
|
|
|
|
2019-03-14 16:41:37 +01:00
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
|
|
|
- :ref:`i2c`
|
|
|
|
- :doc:`switch/gpio`
|
|
|
|
- :doc:`binary_sensor/gpio`
|
2020-04-12 21:07:25 +02:00
|
|
|
- :apiref:`API Reference (MCP23008) <mcp23008/mcp23008.h>`
|
|
|
|
- :apiref:`API Reference (MCP23016) <mcp23016/mcp23016.h>`
|
|
|
|
- :apiref:`API Reference (MCP23017) <mcp23017/mcp23017.h>`
|
2019-03-14 16:41:37 +01:00
|
|
|
- :ghedit:`Edit`
|