INA2xx
v1.1.0
Arduino Library to read current, voltage and power data from one or more INA2xx device(s)
|
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. | |
Forward definitions for the 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
[in] | expectedDevices | Number of elements to initialize array to if non-zero |
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
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
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | milliVolts | alert level at which to trigger the alarm |
[in] | deviceNumber | to reset (Optional, when not set all devices have their alert changed) |
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
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | milliVolts | alert level at which to trigger the alarm |
[in] | deviceNumber | to reset (Optional, when not set then all devices have their alert changed) |
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.
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | deviceNumber | to reset (Optional, when not set all devices have their mode changed) |
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
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | milliAmps | alert level at which to trigger the alarm |
[in] | deviceNumber | to reset (Optional, when not set all devices have their alert changed) |
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
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | milliVolts | alert level at which to trigger the alarm |
[in] | deviceNumber | to reset (Optional, when not set all devices have their mode changed) |
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
[in] | alertState | Boolean true or false to denote the requested setting |
[in] | milliVolts | alert level at which to trigger the alarm |
[in] | deviceNumber | to reset (Optional, when not set all devices have their alert changed) |
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.
[in] | maxBusAmps | Integer value holding the maximum expected bus amperage, this value is used to compute a device's internal power register |
[in] | microOhmR | Shunt resistance in micro-ohms, this value is used to compute a device's internal power register |
[in] | deviceNumber | Device 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 |
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.
[in] | deviceNumber | to check |
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
[in] | deviceNumber | to return the value for |
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
[in] | deviceNumber | to return the value for |
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
[in] | deviceNumber | to return the device bus millivolts for |
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
[in] | deviceNumber | to return the raw device bus voltage reading |
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
[in] | deviceNumber | to return the device name of |
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
[in] | deviceNumber | to return the device name of |
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
[in] | deviceNumber | to return the value for |
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
[in] | deviceNumber | to return the value for |
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
[in] | deviceNumber | to reset |
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
[in] | averages | Number of averages to set (0-128) |
[in] | deviceNumber | to reset (Optional, when not set all devices have their averaging changed) |
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
[in] | convTime | The 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 |
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.
[in] | i2cSpeed | [optional] changes the I2C speed to the rate specified in Herz |
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
[in] | mode | Mode (see "ina_Mode" enumerated type for list of valid values |
[in] | deviceNumber | to reset (Optional, when not set then all devices are mode changed) |
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
[in] | convTime | Conversion time in microseconds. Out-of-Range values are set to the closest valid value |
[in] | deviceNumber | to 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 |
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.
[in] | deviceNumber | to reset (Optional, when not set all devices have their mode changed) |