:description:Instructions on using an Arduino board, like the Pro Mini for expanding ports of a ESPHome node
:image:arduino_pro_mini.jpg
:keywords:Arduino port expander extender ESPHome
With this sketch you can control pins of a remote Arduino board through ESPHome. The Arduino acts as a port
expander, allowing you to use more pins than a standard ESP8266/ESP32 has.
..figure:: images/arduino_pro_mini.jpg
:align:center
:width:75.0%
The Arduino is connected to the ESP via I²C. Most Arduinos use the ``A4`` and ``A5`` pins for the I²C bus
so those pins are not available to read from ESPHome.
It is recommended to use a 3.3V I/O level Arduino, however using 5V Arduinos seems to work too. In the latter
case you should power your 5V Arduino with 3.3V otherwise you will need a level converter for the
I²C bus.
Currently it is supported:
- reading digital inputs
- reading analog inputs
- writing digital outputs
The Arduino sketch can be retrieved from `here <https://github.com/glmnet/esphome_devices/tree/master/ArduinoPortExpander/src>`__
you can rename it to ``.ino`` and use the Arduino IDE to program it.
You need to download `arduino_port_expander.h <https://github.com/glmnet/esphome_devices/blob/master/arduino_port_expander.h>`__ and include the ape.h in the ESPHome configuration.
..code-block:: yaml
esphome:
# ...
includes:
- arduino_port_expander.h
Setup your :ref:`I²C Bus <i2c>` and assign it an ``id``:
..code-block:: yaml
i2c:
id: i2c_component
By default ESP8266 uses ``SDA`` pin ``GPIO4`` which you need to connect to Arduino's ``A4`` and the ``SCL``
is ``GPIO5`` which goes to Arduino's ``A5``.
Then create a ``custom_component``, this will be the main component we will be referencing later when creating
individual IOs.
..code-block:: yaml
custom_component:
- id: ape
lambda: |-
auto ape_component = new ArduinoPortExpander(i2c_component, 0x08);
return {ape_component};
By default the I²C address is ``0x08`` but you can change it on the arduino sketch so you can have more slaves
on the same bus.
Now it is time to add the ports.
Binary_Sensor
-------------
When adding binary sensors the pins are configured as INPUT_PULLUP, you can use any PIN from 0 to 13 or
``A0`` to ``A3`` (``A4`` and ``A5`` are used for I²C and ``A6`` and ``A7`` do not support internal pull up)