This library is an ESP-IDF component for the INA226 power monitor IC.
idf.py add-dependency "zivlow/ina226"
idf.py create-project-from-example "zivlow/ina226:ina226-example"
cd ina226-example
idf.py flash monitor
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};
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};
Refer to Documentation.
- ESP-IDF v5.2
- ESP32 DevKitC