INA2xx  v1.1.0
Arduino Library to read current, voltage and power data from one or more INA2xx device(s)
INA_Class Class Reference

Forward definitions for the INA_Class. More...

Public Member Functions

 INA_Class (uint8_t expectedDevices=0)
 
 ~INA_Class ()
 
uint8_t begin (const uint16_t maxBusAmps, const uint32_t microOhmR, const uint8_t deviceNumber=UINT8_MAX)
 
void setI2CSpeed (const uint32_t i2cSpeed=INA_I2C_STANDARD_MODE) const
 
void setMode (const uint8_t mode, const uint8_t deviceNumber=UINT8_MAX)
 
void setAveraging (const uint16_t averages, const uint8_t deviceNumber=UINT8_MAX)
 
void setBusConversion (const uint32_t convTime, const uint8_t deviceNumber=UINT8_MAX)
 
void setShuntConversion (const uint32_t convTime, const uint8_t deviceNumber=UINT8_MAX)
 
uint16_t getBusMilliVolts (const uint8_t deviceNumber=0)
 
uint32_t getBusRaw (const uint8_t deviceNumber=0)
 
int32_t getShuntMicroVolts (const uint8_t deviceNumber=0)
 
int32_t getShuntRaw (const uint8_t deviceNumber=0)
 
int32_t getBusMicroAmps (const uint8_t deviceNumber=0)
 
int64_t getBusMicroWatts (const uint8_t deviceNumber=0)
 
const char * getDeviceName (const uint8_t deviceNumber=0)
 
uint8_t getDeviceAddress (const uint8_t deviceNumber=0)
 
void reset (const uint8_t deviceNumber=0)
 
bool conversionFinished (const uint8_t deviceNumber=0)
 
void waitForConversion (const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnConversion (const bool alertState, const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnShuntOverVoltage (const bool alertState, const int32_t milliVolts, const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnShuntUnderVoltage (const bool alertState, const int32_t milliVolts, const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnBusOverVoltage (const bool alertState, const int32_t milliVolts, const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnBusUnderVoltage (const bool alertState, const int32_t milliVolts, const uint8_t deviceNumber=UINT8_MAX)
 
bool alertOnPowerOverLimit (const bool alertState, const int32_t milliAmps, const uint8_t deviceNumber=UINT8_MAX)
 

Public Attributes

uint16_t _EEPROM_offset = 0
 Offset to all EEPROM addresses, GitHub issue #41.
 

Detailed Description

Forward definitions for the INA_Class.

Constructor & Destructor Documentation

◆ INA_Class()

INA_Class::INA_Class ( uint8_t  expectedDevices = 0)

Class constructor

If called without a parameter or with a 0 value, then the constructor does nothing, but if a value is passed then using EEPROM is disabled and each INA-Device found has its data (inaEEPROM structure size) stored in a array dynamically allocated during library instatiation here. If there is not enough space then the pointer isn't init- ialized and the program will abort later on. No error checking can be done here

Parameters
[in]expectedDevicesNumber of elements to initialize array to if non-zero

◆ ~INA_Class()

INA_Class::~INA_Class ( )

Class destructor

If dynamic memory has been allocated for device storage rather than the default EEPROM, then that memory is freed here; otherwise the destructor does nothing

Member Function Documentation

◆ alertOnBusOverVoltage()

bool INA_Class::alertOnBusOverVoltage ( const bool  alertState,
const int32_t  milliVolts,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when the bus voltage goes above the value given in the parameter in millivolts

This call is ignored and returns false when called for an invalid device

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]milliVoltsalert level at which to trigger the alarm
[in]deviceNumberto reset (Optional, when not set all devices have their alert changed)
Returns
Returns "true" on success, otherwise false

◆ alertOnBusUnderVoltage()

bool INA_Class::alertOnBusUnderVoltage ( const bool  alertState,
const int32_t  milliVolts,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when the bus current goes above the value given in the parameter in millivolts.

This call is ignored and returns false when called for an invalid device

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]milliVoltsalert level at which to trigger the alarm
[in]deviceNumberto reset (Optional, when not set then all devices have their alert changed)
Returns
Returns "true" on success, otherwise false

◆ alertOnConversion()

bool INA_Class::alertOnConversion ( const bool  alertState,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when a conversion is complete

This call is ignored and returns false when called for an invalid device as the INA219 doesn't have this pin it won't work for that device.

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]deviceNumberto reset (Optional, when not set all devices have their mode changed)
Returns
Returns "true" on success, otherwise false

◆ alertOnPowerOverLimit()

bool INA_Class::alertOnPowerOverLimit ( const bool  alertState,
const int32_t  milliAmps,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when the power exceeds the value set in the parameter in milliamps

This call is ignored and returns false when called for an invalid device

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]milliAmpsalert level at which to trigger the alarm
[in]deviceNumberto reset (Optional, when not set all devices have their alert changed)
Returns
Returns "true" on success, otherwise false

◆ alertOnShuntOverVoltage()

bool INA_Class::alertOnShuntOverVoltage ( const bool  alertState,
const int32_t  milliVolts,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when the shunt current exceeds the value given in the parameter in millivolts

This call is ignored and returns false when called for an invalid device

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]milliVoltsalert level at which to trigger the alarm
[in]deviceNumberto reset (Optional, when not set all devices have their mode changed)
Returns
Returns "true" on success, otherwise false

◆ alertOnShuntUnderVoltage()

bool INA_Class::alertOnShuntUnderVoltage ( const bool  alertState,
const int32_t  milliVolts,
const uint8_t  deviceNumber = UINT8_MAX 
)

configures the INA devices which support this functionality to pull the ALERT pin low when the shunt current goes below the value given in the parameter in millivolts

This call is ignored and returns false when called for an invalid device

Parameters
[in]alertStateBoolean true or false to denote the requested setting
[in]milliVoltsalert level at which to trigger the alarm
[in]deviceNumberto reset (Optional, when not set all devices have their alert changed)
Returns
Returns "true" on success, otherwise false

◆ begin()

uint8_t INA_Class::begin ( const uint16_t  maxBusAmps,
const uint32_t  microOhmR,
const uint8_t  deviceNumber = UINT8_MAX 
)

Initializes the contents of the class

Searches for possible devices and sets the INA Configuration details, without which meaningful readings cannot be made. If it is called without the optional deviceNumber parameter then the settings are applied to all devices, otherwise just that specific device is targeted. If the optional third parameter, devNo, is specified that specific device gets the two specified values set for it. Can be called multiple times, but the 3 parameter version will only function after the 2 parameter version finds all devices.

Parameters
[in]maxBusAmpsInteger value holding the maximum expected bus amperage, this value is used to compute a device's internal power register
[in]microOhmRShunt resistance in micro-ohms, this value is used to compute a device's internal power register
[in]deviceNumberDevice number to explicitly set the maxBusAmps and microOhmR values, by default all devices found get set to the same initial values for these 2 params
Returns
The integer number of INAxxxx devices found on the I2C bus

◆ conversionFinished()

bool INA_Class::conversionFinished ( const uint8_t  deviceNumber = 0)

Returns whether or not the conversion has completed

The device's conversion ready bit is read and returned. "true" denotes finished conversion.

Parameters
[in]deviceNumberto check

◆ getBusMicroAmps()

int32_t INA_Class::getBusMicroAmps ( const uint8_t  deviceNumber = 0)

Returns the computed microamps measured on the bus for the specified device

The computed reading is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the value for
Returns
int32_t signed integer for computed microamps on the bus

◆ getBusMicroWatts()

int64_t INA_Class::getBusMicroWatts ( const uint8_t  deviceNumber = 0)

returns the computed microwatts measured on the bus for the specified device

The computed reading is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the value for
Returns
int64_t signed integer for computed microwatts on the bus

◆ getBusMilliVolts()

uint16_t INA_Class::getBusMilliVolts ( const uint8_t  deviceNumber = 0)

returns the bus voltage in millivolts

The converted millivolt value is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the device bus millivolts for
Returns
uint16_t unsigned integer for the bus millivoltage

◆ getBusRaw()

uint32_t INA_Class::getBusRaw ( const uint8_t  deviceNumber = 0)

returns the raw unconverted bus voltage reading from the device

The raw measured value is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the raw device bus voltage reading
Returns
Raw bus measurement

◆ getDeviceAddress()

uint8_t INA_Class::getDeviceAddress ( const uint8_t  deviceNumber = 0)

returns a I2C address of the device specified in the input parameter

Return the I2C address of the specified device, if number is out of range return 0

Parameters
[in]deviceNumberto return the device name of
Returns
I2C address of the device. Returns 0 if value is out-of-range

◆ getDeviceName()

const char * INA_Class::getDeviceName ( const uint8_t  deviceNumber = 0)

returns character buffer with the name of the device specified in the input param

See function definition for list of possible return values

Parameters
[in]deviceNumberto return the device name of
Returns
device name

◆ getShuntMicroVolts()

int32_t INA_Class::getShuntMicroVolts ( const uint8_t  deviceNumber = 0)

returns the shunt reading converted to microvolts

The computed microvolts value is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the value for
Returns
int32_t signed integer for the shunt microvolts

◆ getShuntRaw()

int32_t INA_Class::getShuntRaw ( const uint8_t  deviceNumber = 0)

Returns the raw shunt reading

The raw reading is returned and if the device is in triggered mode the next conversion is started

Parameters
[in]deviceNumberto return the value for
Returns
Raw shunt reading

◆ reset()

void INA_Class::reset ( const uint8_t  deviceNumber = 0)

performs a software reset for the specified device

If no device is specified, then all devices are reset

Parameters
[in]deviceNumberto reset

◆ setAveraging()

void INA_Class::setAveraging ( const uint16_t  averages,
const uint8_t  deviceNumber = UINT8_MAX 
)

sets the hardware averaging for one or all devices

Out-of-Range averaging is brought down to the highest allowed value

Parameters
[in]averagesNumber of averages to set (0-128)
[in]deviceNumberto reset (Optional, when not set all devices have their averaging changed)

◆ setBusConversion()

void INA_Class::setBusConversion ( const uint32_t  convTime,
const uint8_t  deviceNumber = UINT8_MAX 
)

specifies the conversion rate in microseconds, rounded to the nearest valid value

INA devices can have a conversion rate of up to 68100 microseconds

Parameters
[in]convTimeThe conversion time in microseconds, invalid values are rounded to the nearest valid value
[in]deviceNumber[optional] When specified, only that specified device number gets changed, otherwise all devices are set to the same averaging rate

◆ setI2CSpeed()

void INA_Class::setI2CSpeed ( const uint32_t  i2cSpeed = INA_I2C_STANDARD_MODE) const

Set a new I2C speed

I2C allows various bus speeds, see the enumerated type I2C_MODES for the standard speeds. The valid speeds are 100KHz, 400KHz, 1MHz and 3.4MHz. Default to 100KHz when not specified. No range checking is done.

Parameters
[in]i2cSpeed[optional] changes the I2C speed to the rate specified in Herz

◆ setMode()

void INA_Class::setMode ( const uint8_t  mode,
const uint8_t  deviceNumber = UINT8_MAX 
)

sets the operating mode from the list given in enum type "ina_Mode" for a device

If no device is specified, then all devices are set to the given mode

Parameters
[in]modeMode (see "ina_Mode" enumerated type for list of valid values
[in]deviceNumberto reset (Optional, when not set then all devices are mode changed)

◆ setShuntConversion()

void INA_Class::setShuntConversion ( const uint32_t  convTime,
const uint8_t  deviceNumber = UINT8_MAX 
)

specifies the conversion rate in microseconds, rounded to the nearest valid value

INA devices can have a conversion rate of up to 68100 microseconds

Parameters
[in]convTimeConversion time in microseconds. Out-of-Range values are set to the closest valid value
[in]deviceNumberto return the device name for[optional] When specified, only that specified device number gets changed, otherwise all devices are set to the same averaging rate

◆ waitForConversion()

void INA_Class::waitForConversion ( const uint8_t  deviceNumber = UINT8_MAX)

will not return until the conversion for the specified device is finished

if no device number is specified it will wait until all devices have finished their current conversion. If the conversion has completed already then the flag (and interrupt pin, if activated) is also reset.

Parameters
[in]deviceNumberto reset (Optional, when not set all devices have their mode changed)

The documentation for this class was generated from the following files: