ModularSensors > Modules > Supported Sensors > TI INA219

TI INA219 module

Classes for the TI INA219 current and voltage sensor.

Intruduction

The TI INA219 is a bi-directional, high-side, current/power monitor that communicates with the board via I2C. The I2C address of INA219 can be any number between 0x40 and 0x4F, depending on the settings of pins A0 and A1. See the datasheet for the possible configurations. The INA219 requires an input voltage of 3.0-5.5V. The gain of this sensor can be increased to increase sensitivity (at the expense of range) but this library assumes the maximum range.

Commuincation between the INA219 and the mcu is managed by the Adafruit INA219 Library

Sensor Datasheet

Documentation for the sensor can be found at: https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout and http://www.ti.com/product/INA219

Sensor Constructor

TIINA219(int8_t powerPin, uint8_t i2cAddressHex = INA219_ADDRESS_BASE, uint8_t measurementsToAverage = 1) explicit

Construct a new TI INA219 object using the default hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the INA219. Use -1 if it is continuously powered.

  • The INA219 requires input voltage of 3.0-5.5V, which can be turned off between measurements.
i2cAddressHex The I2C address of the BME280; can be any number between 0x40 and 0x4F. The default value is 0x40.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

TIINA219(TwoWire* theI2C, int8_t powerPin, uint8_t i2cAddressHex = INA219_ADDRESS_BASE, uint8_t measurementsToAverage = 1)

Construct a new TI INA219 object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the INA219. Use -1 if it is continuously powered.

  • The INA219 requires input voltage of 3.0-5.5V, which can be turned off between measurements.
i2cAddressHex The I2C address of the BME280; can be any number between 0x40 and 0x4F. The default value is 0x40.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.


Example Code

The TI INA219 is used in the menu a la carte example.

#include <sensors/TIINA219.h>

// NOTE: Use -1 for any pins that don't apply or aren't being used.
const int8_t INA219Power    = sensorPowerPin;  // Power pin
uint8_t      INA219i2c_addr = 0x40;            // 1000000 (Board A0+A1=GND)
// The INA219 can have one of 16 addresses, depending on the connections of A0
// and A1
const uint8_t INA219ReadingsToAvg = 1;

// Create an INA219 sensor object
TIINA219 ina219(INA219Power, INA219i2c_addr, INA219ReadingsToAvg);

// Create current, voltage, and power variable pointers for the INA219
Variable* inaCurrent =
    new TIINA219_Current(&ina219, "12345678-abcd-1234-ef00-1234567890ab");
Variable* inaVolt =
    new TIINA219_Voltage(&ina219, "12345678-abcd-1234-ef00-1234567890ab");
Variable* inaPower = new TIINA219_Power(&ina219,
                                        "12345678-abcd-1234-ef00-1234567890ab");

Classes

class TIINA219
The Sensor sub-class for the TexasInstruments INA219 sensor.
class TIINA219_Current
The Variable sub-class used for the current output from a TI INA219 power and current monitor.
class TIINA219_Voltage
The Variable sub-class used for the bus voltage output from a TI INA219 power and current monitor.
class TIINA219_Power
The Variable sub-class used for the power use output calculated from the voltage and current measured by a TI INA219 power and current monitor.

Typedefs

using TIINA219_Volt = TIINA219_Voltage deprecated in v0.33.0
typedef for backwards compatibility; use the TIINA219_Voltage class in new code

Defines

#define INA219_NUM_VARIABLES = 3
Sensor::_numReturnedValues; the INA219 can report 3 values.
#define INA219_INC_CALC_VARIABLES = 0
Sensor::_incCalcValues; we don't calculate any additional values.
#define INA219_ADDRESS_BASE = 0x40
The default address of the INA219.

Sensor Timing

The sensor timing for a TI INA219

#define INA219_WARM_UP_TIME_MS = 100
Sensor::_warmUpTime_ms; the INA219 warms up in 100ms.
#define INA219_STABILIZATION_TIME_MS = 4000
Sensor::_stabilizationTime_ms; the INA219 is stable after 4000ms.

Stable numbers can be acheived after 500ms, but waiting up to 4s gave more consistent numbers based on tests using INA219timingTest.ino

#define INA219_MEASUREMENT_TIME_MS = 1100
Sensor::_measurementTime_ms; the INA219 takes 1100ms to complete a measurement.

A single ADC conversion takes >532 µs (586 µs typical) at 12 bit resolution, but in tests waiting closer to 1.1s gave data with a slightly better standard deviation.

Current

The current variable from a TI INA219

  • Range is between +/-0.4 Amps and +/-3.2 Amps
  • Absolute accuracy is range dependent, and approx 2LSB (R accuracy unknown)

TIINA219_Current(TIINA219* parentSense, const char* uuid = "", const char* varCode = INA219_CURRENT_MA_DEFAULT_CODE) explicit

Construct a new TIINA219_Current object.

Parameters
parentSense The parent TIINA219 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "TIINA219Amp".

#define INA219_CURRENT_MA_RESOLUTION = 1
Decimals places in string representation; current should have 1.
  • resolution is 12-bit
    • 0.8mA using +/-3.2 Amp range
    • 0.1mA using +/-0.4 Amp range
#define INA219_CURRENT_MA_VAR_NUM = 0
Sensor variable number; current is stored in sensorValues[0].
#define INA219_CURRENT_MA_VAR_NAME = "electricCurrent"
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define INA219_CURRENT_MA_UNIT_NAME = "milliamp"
Variable unit name in ODM2 controlled vocabulary; "milliamp".
#define INA219_CURRENT_MA_DEFAULT_CODE = "TIINA219Amp"
Default variable short code; "TIINA219Amp".

Bus Voltage

The bus voltage variable from a TI INA219

  • Range is 0 to 26V
  • Accuracy is ±4mV (1 LSB step size)

TIINA219_Voltage(TIINA219* parentSense, const char* uuid = "", const char* varCode = INA219_BUS_VOLTAGE_DEFAULT_CODE) explicit

Construct a new TIINA219_Voltage object.

Parameters
parentSense The parent TIINA219 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "TIINA219Volt".

#define INA219_BUS_VOLTAGE_RESOLUTION = 3
Decimals places in string representation; bus voltage should have 4 - resolution is 0.001V.
#define INA219_BUS_VOLTAGE_VAR_NUM = 1
Sensor variable number; bus voltage is stored in sensorValues[1].
#define INA219_BUS_VOLTAGE_VAR_NAME = "voltage"
Variable name in ODM2 controlled vocabulary; "voltage".
#define INA219_BUS_VOLTAGE_UNIT_NAME = "volt"
Variable unit name in ODM2 controlled vocabulary; "volt".
#define INA219_BUS_VOLTAGE_DEFAULT_CODE = "TIINA219Volt"
Default variable short code; "TIINA219Volt".

Power

The power variable from a TI INA219

TIINA219_Power(TIINA219* parentSense, const char* uuid = "", const char* varCode = INA219_POWER_MW_DEFAULT_CODE) explicit

Construct a new TIINA219_Power object.

Parameters
parentSense The parent TIINA219 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "TIINA219Power".

#define INA219_POWER_MW_RESOLUTION = 2
Decimals places in string representation; power draw should have 2 - resolution is 0.01mW.
#define INA219_POWER_MW_VAR_NUM = 2
Sensor variable number; power draw is stored in sensorValues[2].
#define INA219_POWER_MW_VAR_NAME = "electricPower"
Variable name in ODM2 controlled vocabulary; "electricPower".
#define INA219_POWER_MW_UNIT_NAME = "milliwatt"
Variable unit name in ODM2 controlled vocabulary; "milliwatt".
#define INA219_POWER_MW_DEFAULT_CODE = "TIINA219Power"
Default variable short code; "TIINA219Power".