Latest Arduino Library Version:
Latest Espressif Component Version:
ESP32_IO_Expander
is a library designed for driving IO expander chips using ESP SoCs. It encapsulates various components from the Espressif Components Registry and includes the following features:
- Supports various IO expander chips, such as TCA95xx, HT8574, and CH422G.
- Supports controlling individual IO pin with functions like
pinMode()
,digitalWrite()
, anddigitalRead()
. - Supports controlling multiple IO pins simultaneously with functions like
multiPinMode()
,multiDigitalWrite()
, andmultiDigitalRead()
. - Compatible with the
Arduino
,ESP-IDF
andMicroPython
for compilation.
Driver | Version |
---|---|
esp_io_expander | 1.0.1 |
TCA95XX_8BIT | 1.0.1 |
TCA95XX_16BIT | 1.0.0 |
HT8574 | 1.0.0 |
CH422G | x |
Dependency | Version |
---|---|
esp-idf | >= 5.1 |
esp-lib-utils | >= 0.1.0 && <= 0.2.0 |
ESP32_IO_Expander
has been uploaded to the Espressif Component Registry, and users can add it to their project using the idf.py add-dependency
command, for example:
idf.py add-dependency "espressif/ESP32_IO_Expander"
Alternatively, users can create or modify the idf_component.yml file in the project directory. For more details, please refer to the Espressif Documentation - IDF Component Manager.
Since ESP32_IO_Expander
depends on the esp-lib-utils
library which implements the logging
, checking
, and memory
functions, to configure it when using ESP-IDF, please refer to the instructions.
Dependency | Version |
---|---|
arduino-esp32 | >= v3.0.0 |
esp-lib-utils | >= 0.1.0 && <= 0.2.0 |
For installation of the ESP32_IO_Expander
library, refer to How to Install ESP32_IO_Expander in Arduino IDE.
Since ESP32_IO_Expander
depends on the esp-lib-utils
library which implements the logging
, checking
, and memory
functions, to configure it when using Arduino, please refer to the instructions.
- General: Demonstrates how to use
ESP32_IO_Expander
and test general functions. - CH422G: Demonstrates how to use
ESP32_IO_Expander
specifically with the CH422G chip.
#include <esp_io_expander.hpp>
// Create and initialize the IO expander chip, such as TCA95XX_8BIT
esp_expander::Base *expander = new esp_expander::TCA95XX_8BIT(
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000
);
expander->init();
expander->begin();
// Control a single pin (0-31)
expander->pinMode(0, OUTPUT);
expander->digitalWrite(0, HIGH);
expander->digitalWrite(0, LOW);
expander->pinMode(0, INPUT);
int level = expander->digitalRead(0);
// Control multiple pins (IO_EXPANDER_PIN_NUM_0 - IO_EXPANDER_PIN_NUM_31)
expander->multiPinMode(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, OUTPUT);
expander->multiDigitalWrite(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, HIGH);
expander->multiDigitalWrite(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, LOW);
expander->multiPinMode(IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, INPUT);
uint32_t level = expander->multiDigitalRead(IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3);
// Release the Base object
delete expander;
Users can find and modify the directory path for Arduino libraries by selecting File
> Preferences
> Settings
> Sketchbook location
from the menu bar in the Arduino IDE.
- If users want to install online, navigate to
Sketch
>Include Library
>Manage Libraries...
in the Arduino IDE, then search forESP32_IO_Expander
and click theInstall
button to install it. - If users want to install manually, download the required version of the
.zip
file from ESP32_IO_Expander, then navigate toSketch
>Include Library
>Add .ZIP Library...
in the Arduino IDE, select the downloaded.zip
file, and clickOpen
to install it. - Users can also refer to the guides on library installation in the Arduino IDE v1.x.x or Arduino IDE v2.x.x documentation.