TI INA219 topic
- Intruduction
- Sensor Datasheet
- Sensor Constructor
- Example Code
- Reference
- Detailed Descriptions
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:/
Sensor Constructor
Construct a new TI INA219 object using the default hardware I2C instance. The pin on the mcu controlling power to the INA219. Use -1 if it is continuously powered. Construct a new TI INA219 object using a secondary hardware I2C instance. The pin on the mcu controlling power to the INA219. Use -1 if it is continuously powered.
TIINA219::
Parameters
powerPin
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::
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
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.
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
Sensor Variable Counts
The number of variables that can be returned by the INA219
- #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.
Configuration Defines
Defines to set the address of the INA219.
- #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. - #define INA219_MEASUREMENT_TIME_MS = 1100
- Sensor::
_measurementTime_ms; the INA219 takes 1100ms to complete a measurement.
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)
Construct a new TIINA219_
TIINA219_
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.
- #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)
Construct a new TIINA219_
TIINA219_
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
Construct a new TIINA219_
TIINA219_
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".
Typedef documentation
typedef TIINA219_ Voltage TIINA219_Volt
#include <src/sensors/TIINA219.h>
typedef for backwards compatibility; use the TIINA219_
Define documentation
#define INA219_NUM_VARIABLES = 3
#include <src/sensors/TIINA219.h>
Sensor::
#define INA219_INC_CALC_VARIABLES = 0
#include <src/sensors/TIINA219.h>
Sensor::
#define INA219_ADDRESS_BASE = 0x40
#include <src/sensors/TIINA219.h>
The default address of the INA219.
#define INA219_WARM_UP_TIME_MS = 100
#include <src/sensors/TIINA219.h>
Sensor::
#define INA219_STABILIZATION_TIME_MS = 4000
#include <src/sensors/TIINA219.h>
Sensor::
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
#include <src/sensors/TIINA219.h>
Sensor::
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.
#define INA219_CURRENT_MA_RESOLUTION = 1
#include <src/sensors/TIINA219.h>
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
#include <src/sensors/TIINA219.h>
Sensor variable number; current is stored in sensorValues[0].
#define INA219_CURRENT_MA_VAR_NAME = "electricCurrent"
#include <src/sensors/TIINA219.h>
Variable name in ODM2 controlled vocabulary; "electricCurrent".
#define INA219_CURRENT_MA_UNIT_NAME = "milliamp"
#include <src/sensors/TIINA219.h>
Variable unit name in ODM2 controlled vocabulary; "milliamp".
#define INA219_CURRENT_MA_DEFAULT_CODE = "TIINA219Amp"
#include <src/sensors/TIINA219.h>
Default variable short code; "TIINA219Amp".
#define INA219_BUS_VOLTAGE_RESOLUTION = 3
#include <src/sensors/TIINA219.h>
Decimals places in string representation; bus voltage should have 4 - resolution is 0.001V.
#define INA219_BUS_VOLTAGE_VAR_NUM = 1
#include <src/sensors/TIINA219.h>
Sensor variable number; bus voltage is stored in sensorValues[1].
#define INA219_BUS_VOLTAGE_VAR_NAME = "voltage"
#include <src/sensors/TIINA219.h>
Variable name in ODM2 controlled vocabulary; "voltage".
#define INA219_BUS_VOLTAGE_UNIT_NAME = "volt"
#include <src/sensors/TIINA219.h>
Variable unit name in ODM2 controlled vocabulary; "volt".
#define INA219_BUS_VOLTAGE_DEFAULT_CODE = "TIINA219Volt"
#include <src/sensors/TIINA219.h>
Default variable short code; "TIINA219Volt".
#define INA219_POWER_MW_RESOLUTION = 2
#include <src/sensors/TIINA219.h>
Decimals places in string representation; power draw should have 2 - resolution is 0.01mW.
#define INA219_POWER_MW_VAR_NUM = 2
#include <src/sensors/TIINA219.h>
Sensor variable number; power draw is stored in sensorValues[2].
#define INA219_POWER_MW_VAR_NAME = "electricPower"
#include <src/sensors/TIINA219.h>
Variable name in ODM2 controlled vocabulary; "electricPower".
#define INA219_POWER_MW_UNIT_NAME = "milliwatt"
#include <src/sensors/TIINA219.h>
Variable unit name in ODM2 controlled vocabulary; "milliwatt".
#define INA219_POWER_MW_DEFAULT_CODE = "TIINA219Power"
#include <src/sensors/TIINA219.h>
Default variable short code; "TIINA219Power".