Skip to content

ZivLow/ina226

Repository files navigation

INA226 component for ESP-IDF

Component Registry Example build

This library is an ESP-IDF component for the INA226 power monitor IC.

Using component

idf.py add-dependency "zivlow/ina226"

Example

idf.py create-project-from-example "zivlow/ina226:ina226-example"
cd ina226-example
idf.py flash monitor

I2C pins

If using ESP32 DevKitC, the default I2C pins has been set to GPIO 21 (SDA) and GPIO 22 (SCL).

// Use default I2C pins GPIO 21 (SDA) and GPIO 22 (SCL)
INA226 CurrentSensor;

If using other ESP32 product variants (e.g. ESP32s3), or if you want to select custom I2C pins, put your desired I2C pins as parameter arguments.

// Custom I2C pins
INA226 CurrentSensor{SDA_GPIO_NUM, SCL_GPIO_NUM};

INA226 address

The default constructor will use default I2C address 0x40.

To set a different I2C address, add the desired address as the third parameter.

// Custom INA226 address
INA226 CurrentSensor{SDA_GPIO_NUM, SCL_GPIO_NUM, INA226_CUSTOM_ADDRESS};

API

Refer to Documentation.

Environment

  • ESP-IDF v5.2
  • ESP32 DevKitC