ina219 - Driver for INA219/INA220 bidirectional current/power monitor¶
- group ina219
ESP-IDF driver for INA219/INA220 Zerø-Drift, Bidirectional Current/Power Monitor.
Copyright (c) 2019 Ruslan V. Uss unclerus@gmail.com
BSD Licensed as described in the file LICENSE
Defines
-
INA219_ADDR_GND_GND¶
I2C address, A1 pin - GND, A0 pin - GND.
-
INA219_ADDR_GND_VS¶
I2C address, A1 pin - GND, A0 pin - VS+.
-
INA219_ADDR_GND_SDA¶
I2C address, A1 pin - GND, A0 pin - SDA.
-
INA219_ADDR_GND_SCL¶
I2C address, A1 pin - GND, A0 pin - SCL.
-
INA219_ADDR_VS_GND¶
I2C address, A1 pin - VS+, A0 pin - GND.
-
INA219_ADDR_VS_VS¶
I2C address, A1 pin - VS+, A0 pin - VS+.
-
INA219_ADDR_VS_SDA¶
I2C address, A1 pin - VS+, A0 pin - SDA.
-
INA219_ADDR_VS_SCL¶
I2C address, A1 pin - VS+, A0 pin - SCL.
-
INA219_ADDR_SDA_GND¶
I2C address, A1 pin - SDA, A0 pin - GND.
-
INA219_ADDR_SDA_VS¶
I2C address, A1 pin - SDA, A0 pin - VS+.
-
INA219_ADDR_SDA_SDA¶
I2C address, A1 pin - SDA, A0 pin - SDA.
-
INA219_ADDR_SDA_SCL¶
I2C address, A1 pin - SDA, A0 pin - SCL.
-
INA219_ADDR_SCL_GND¶
I2C address, A1 pin - SCL, A0 pin - GND.
-
INA219_ADDR_SCL_VS¶
I2C address, A1 pin - SCL, A0 pin - VS+.
-
INA219_ADDR_SCL_SDA¶
I2C address, A1 pin - SCL, A0 pin - SDA.
-
INA219_ADDR_SCL_SCL¶
I2C address, A1 pin - SCL, A0 pin - SCL.
Enums
-
enum ina219_bus_voltage_range_t¶
Bus voltage range.
Values:
-
enumerator INA219_BUS_RANGE_16V¶
16V FSR
-
enumerator INA219_BUS_RANGE_32V¶
32V FSR (default)
-
enumerator INA219_BUS_RANGE_16V¶
-
enum ina219_gain_t¶
PGA gain for shunt voltage.
Values:
-
enumerator INA219_GAIN_1¶
Gain: 1, Range: +-40 mV.
-
enumerator INA219_GAIN_0_5¶
Gain: 1/2, Range: +-80 mV.
-
enumerator INA219_GAIN_0_25¶
Gain: 1/4, Range: +-160 mV.
-
enumerator INA219_GAIN_0_125¶
Gain: 1/8, Range: +-320 mV (default)
-
enumerator INA219_GAIN_1¶
-
enum ina219_resolution_t¶
ADC resolution/averaging.
Values:
-
enumerator INA219_RES_9BIT_1S¶
9 bit, 1 sample, conversion time 84 us
-
enumerator INA219_RES_10BIT_1S¶
10 bit, 1 sample, conversion time 148 us
-
enumerator INA219_RES_11BIT_1S¶
11 bit, 1 sample, conversion time 276 us
-
enumerator INA219_RES_12BIT_1S¶
12 bit, 1 sample, conversion time 532 us (default)
-
enumerator INA219_RES_12BIT_2S¶
12 bit, 2 samples, conversion time 1.06 ms
-
enumerator INA219_RES_12BIT_4S¶
12 bit, 4 samples, conversion time 2.13 ms
-
enumerator INA219_RES_12BIT_8S¶
12 bit, 8 samples, conversion time 4.26 ms
-
enumerator INA219_RES_12BIT_16S¶
12 bit, 16 samples, conversion time 8.51 ms
-
enumerator INA219_RES_12BIT_32S¶
12 bit, 32 samples, conversion time 17.02 ms
-
enumerator INA219_RES_12BIT_64S¶
12 bit, 64 samples, conversion time 34.05 ms
-
enumerator INA219_RES_12BIT_128S¶
12 bit, 128 samples, conversion time 68.1 ms
-
enumerator INA219_RES_9BIT_1S¶
-
enum ina219_mode_t¶
Operating mode.
Values:
-
enumerator INA219_MODE_POWER_DOWN¶
Power-done.
-
enumerator INA219_MODE_TRIG_SHUNT¶
Shunt voltage, triggered.
-
enumerator INA219_MODE_TRIG_BUS¶
Bus voltage, triggered.
-
enumerator INA219_MODE_TRIG_SHUNT_BUS¶
Shunt and bus, triggered.
-
enumerator INA219_MODE_DISABLED¶
ADC off (disabled)
-
enumerator INA219_MODE_CONT_SHUNT¶
Shunt voltage, continuous.
-
enumerator INA219_MODE_CONT_BUS¶
Bus voltage, continuous.
-
enumerator INA219_MODE_CONT_SHUNT_BUS¶
Shunt and bus, continuous (default)
-
enumerator INA219_MODE_POWER_DOWN¶
Functions
-
esp_err_t ina219_init_desc(ina219_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)¶
Initialize device descriptor.
- Parameters
dev – Device descriptor
addr – Device I2C address
port – I2C port
sda_gpio – SDA GPIO
scl_gpio – SCL GPIO
- Returns
ESP_OK
on success
-
esp_err_t ina219_free_desc(ina219_t *dev)¶
Free device descriptor.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina219_init(ina219_t *dev)¶
Init device.
Read current device configuration into
dev->config
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina219_reset(ina219_t *dev)¶
Reset device.
Same as power-on reset. Resets all registers to default values. You still need to calibrate device to read current, otherwise only shunt voltage readings will be valid.
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina219_configure(ina219_t *dev, ina219_bus_voltage_range_t u_range, ina219_gain_t gain, ina219_resolution_t u_res, ina219_resolution_t i_res, ina219_mode_t mode)¶
Set device configuration.
- Parameters
dev – Device descriptor
u_range – Bus voltage range
gain – Shunt voltage gain
u_res – Bus voltage resolution and averaging
i_res – Shunt voltage resolution and averaging
mode – Device operational mode
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_bus_voltage_range(ina219_t *dev, ina219_bus_voltage_range_t *range)¶
Get bus voltage range.
- Parameters
dev – Device descriptor
range – [out] Bus voltage range
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_gain(ina219_t *dev, ina219_gain_t *gain)¶
Get shunt voltage gain.
- Parameters
dev – Device descriptor
gain – [out] Shunt voltage gain
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_bus_voltage_resolution(ina219_t *dev, ina219_resolution_t *res)¶
Get bus voltage resolution and averaging.
- Parameters
dev – Device descriptor
res – [out] Bus voltage resolution and averaging
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_shunt_voltage_resolution(ina219_t *dev, ina219_resolution_t *res)¶
Get shunt voltage resolution and averaging.
- Parameters
dev – Device descriptor
res – [out] Shunt voltage resolution and averaging
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_mode(ina219_t *dev, ina219_mode_t *mode)¶
Get operating mode.
- Parameters
dev – Device descriptor
mode – [out] Operating mode
- Returns
ESP_OK
on success
-
esp_err_t ina219_calibrate(ina219_t *dev, float i_expected_max, float r_shunt)¶
Perform calibration.
Current readings will be valid only after calibration
- Parameters
dev – Device descriptor
i_expected_max – Maximum expected current, A
r_shunt – Shunt resistance, Ohm
- Returns
ESP_OK
on success
-
esp_err_t ina219_trigger(ina219_t *dev)¶
Trigger single conversion.
Function will return an error if current operating mode is not
INA219_MODE_TRIG_SHUNT
/INA219_MODE_TRIG_BUS
/INA219_MODE_TRIG_SHUNT_BUS
- Parameters
dev – Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_bus_voltage(ina219_t *dev, float *voltage)¶
Read bus voltage.
- Parameters
dev – Device descriptor
voltage – [out] Bus voltage, V
- Returns
ESP_OK
on success
-
esp_err_t ina219_get_shunt_voltage(ina219_t *dev, float *voltage)¶
Read shunt voltage.
- Parameters
dev – Device descriptor
voltage – [out] Shunt voltage, V
- Returns
ESP_OK
on success
-
struct ina219_t¶
- #include <ina219.h>
Device descriptor.
-
INA219_ADDR_GND_GND¶