ModularSensors > Classes > Sensor > TIINA219
ModularSensors > Modules > TI INA219 > TIINA219


TIINA219 class

The Sensor sub-class for the TexasInstruments INA219 sensor.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

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.
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.
~TIINA219()
Destroy the TI INA219 object.

Public functions

bool wake(void ) override
Wake the sensor up and read the calibration coefficient from it.
bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
String getSensorLocation(void ) override
Get the pin or connection location between the mcu and the sensor.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

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.

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.

boolwake(void ) override

Wake the sensor up and read the calibration coefficient from it.

Returns bool True if the wake function completed successfully.

Verifies that the power is on and updates the _sensorStatus. This also sets the _millisSensorActivated timestamp.


boolsetup(void ) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets the _powerPin mode, begins the Wire library (sets pin levels and modes for I2C). This also sets the calibration range of the INA219, and updates the _sensorStatus. The INA219 must be powered for setup.


StringgetSensorLocation(void ) override

Get the pin or connection location between the mcu and the sensor.

Returns String Text describing how the sensor is attached to the mcu.

booladdSingleMeasurementResult(void ) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.