Skip to content

esp-arduino-libs/ESP32_IO_Expander

Repository files navigation

Arduino Lint pre-commit Build Test Apps

Latest Arduino Library Version: GitHub Release

Latest Espressif Component Version: Espressif Release

ESP32_IO_Expander

ESP32_IO_Expander is a library designed for driving IO expander chips using ESP32 SoCs.

ESP32_IO_Expander encapsulates various components from the Espressif Components Registry. It is developed based on arduino-esp32 or esp-idf, and can be easily downloaded and integrated into the Arduino IDE.

Features

  • Supports various IO expander chips.
  • Supports controlling individual IO pin (using pinMode(), digitalRead(), and digitalWrite() functions).
  • Supports controlling multiple IO pins simultaneously.
  • Supports building on the Arduino IDE and the ESP-IDF framework.

Supported Drivers

Driver Version
esp_io_expander 1.0.1
TCA95xx (8bit) 1.0.1
TCA95xx (16bit) 1.0.0
HT8574 1.0.0
CH422G x

Dependencies Version

Arduino

Name Version
arduino-esp32 >= v3.0.0

ESP-IDF

Name Version
esp-idf >= v5.1

How to Use

For information on how to use the library in the Arduino IDE, please refer to the documentation for Arduino IDE v1.x.x or Arduino IDE v2.x.x.

Examples

  • Test Functions: Demonstrates how to use ESP32_IO_Expander and test all functions.
  • Test CH422G: Demonstrates how to use ESP32_IO_Expander with the CH422G chip.

Detailed Usage

#include <ESP_IOExpander_Library.h>

// Create and initialize an ESP_IOExpander object according to the chip type
ESP_IOExpander *expander = new ESP_IOExpander_TCA95xx_8bit(EXAMPLE_I2C_NUM_0, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
                                                           EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
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 ESP_IOExpander object
delete expander;