Compare commits

...

57 commits

Author SHA1 Message Date
Limor "Ladyada" Fried
9bd01a6f80
Update library.properties 2025-05-13 17:08:25 -04:00
Limor "Ladyada" Fried
a670fbd690
Merge pull request #23 from adafruit/remove_INA23x
recfactor to remove INA237/IN238 - they'll get their own library
2025-05-13 16:50:02 -04:00
ladyada
594e075b75 recfactor to remove INA237/IN238 - they'll get their own library 2025-05-13 16:45:02 -04:00
Limor "Ladyada" Fried
73b9c91c78
Merge pull request #22 from adafruit/fix_bus_voltage
Fix bus voltage
2025-05-13 16:35:22 -04:00
ladyada
f93d2170e2 clangf 2025-05-13 16:28:17 -04:00
ladyada
5dbc4d911e fix INA237's current calc 2025-05-13 16:22:57 -04:00
ladyada
2629aa5bc5 Make setShunt() virtual with chip-specific implementations
- Made setShunt() virtual in the base class
- Added INA228-specific implementation using 2^19 divisor
- Added INA237-specific implementation using 2^15 divisor
- Updated documentation to explain the chip-specific differences
- Ensures correct current LSB calculation based on device type
- Fixes current scaling issues for INA237
2025-05-13 16:14:22 -04:00
ladyada
5dde97a877 Update INA237/INA238 examples to display shunt voltage in μV
- Changed shunt voltage display from mV to μV in examples
- Added conversion factor (multiply by 1000) to convert from mV to μV
- Provides higher granularity for smaller shunt voltage readings
- Matches the lower LSB value of the INA237/INA238 (5 μV vs 312.5 μV in INA228)
2025-05-13 15:50:03 -04:00
ladyada
9ac9432fa4 Make read methods virtual in base class
- Made readCurrent(), readShuntVoltage(), and readPower() methods virtual
- Allows proper overriding in derived classes
- Fixes compile errors with override keyword in INA237 implementation
2025-05-13 15:46:19 -04:00
ladyada
cca028c64c Fix INA237 register sizes and conversion factors
- Fixed bus voltage register size (2 bytes instead of 3)
- Fixed register data interpretation for bus voltage
- Added overrides for all measurement functions to use correct register sizes
- Implemented correct conversion factors based on INA237 datasheet
- Changed shunt voltage to use 5/1.25 µV/LSB (vs 312.5/78.125 in INA228)
- Changed current and power calculation to use 16-bit registers (vs 24-bit)
- Added comment explaining differences between INA237 and INA228 registers
2025-05-13 15:45:16 -04:00
ladyada
c81c0aa340 Add manufacturer ID check to begin()
- Added verification that the manufacturer ID is 0x5449 (Texas Instruments)
- Returns false from begin() if the ID doesn't match
- Improves device detection reliability
2025-05-13 15:41:51 -04:00
ladyada
d72faa9ce3 fix 237 detect 2025-05-13 15:40:27 -04:00
ladyada
2f1c6b28b1 clangf 2025-05-13 15:24:27 -04:00
ladyada
549c64d60d Update examples to use _V, _mV, and _mA methods
- Changed readBusVoltage() to getBusVoltage_V()
- Changed readShuntVoltage() to getShuntVoltage_mV()
- Changed readCurrent() to getCurrent_mA()
- Changed readPower() to getPower_mW()
- Fixed unit labels in output (V instead of mV for bus voltage)
2025-05-13 15:22:46 -04:00
ladyada
9137adc0cd Add charge reading to ina228_test example 2025-05-13 15:19:35 -04:00
ladyada
8d2bc9d18b Fix duplicate declaration of readBusVoltage() 2025-05-13 15:16:57 -04:00
ladyada
ccd2a3bf58 Add keywords.txt for Arduino IDE syntax highlighting 2025-05-13 15:16:28 -04:00
ladyada
318e4f58f8 Fix bus voltage conversion factors
- Fix readBusVoltage() in base class to return volts instead of microvolts
- Add chip-specific implementations for INA228 and INA237
- INA228 uses 195.3125 µV/LSB conversion factor (divide by 1e6 for volts)
- INA237 uses 3.125 mV/LSB conversion factor (divide by 1000 for volts)
- Make readBusVoltage() virtual to allow proper overrides
- Update documentation to explain the different factors

Fixes #16
2025-05-13 15:06:16 -04:00
Limor "Ladyada" Fried
c2e95246c1
Merge pull request #21 from adafruit/add_charge_read
Add readCharge() function for INA228
2025-05-13 14:43:33 -04:00
ladyada
bd12ddcad6 clang 2025-05-13 14:36:39 -04:00
ladyada
ff63b4021d Add readCharge() function for INA228
- Add new method to read the 40-bit CHARGE register
- Convert the register value to Coulombs using CURRENT_LSB
- Properly handle sign extension for 40-bit two's complement values
2025-05-13 14:35:38 -04:00
Limor "Ladyada" Fried
0d1719897f
Merge pull request #20 from adafruit/add-ina237-support
Add ina237 support
2025-05-13 14:29:29 -04:00
ladyada
98a70105c0 fix dietemp & accumulators 2025-05-13 14:19:50 -04:00
ladyada
7551706d01 clang 2025-05-13 14:05:03 -04:00
ladyada
b5f2c51bd7 doxy updatex 2025-05-13 13:59:28 -04:00
ladyada
8070e0c3b4 clang'd 2025-05-13 13:51:57 -04:00
ladyada
59901ca236 Fix INA2xx base class files with correct content
- Fixed incorrect content in INA2xx.h and INA2xx.cpp
- Corrected implementations to use proper base class methods and types
- Ensured proper inheritance between classes
2025-05-13 13:45:53 -04:00
ladyada
802915c9eb Refactor library to support INA237 and INA238 chips
This refactoring creates a base class Adafruit_INA2xx that contains all common functionality shared between the INA228, INA237, and INA238 chips. The INA228 class now inherits from this base class, and we've added new classes for INA237 and INA238 support.

- Created Adafruit_INA2xx base class with common functionality
- Updated Adafruit_INA228 to inherit from the base class
- Added Adafruit_INA237 implementation with INA237-specific code
- Added Adafruit_INA238 implementation that inherits from INA237
- Added example sketches for INA237 and INA238
- Updated .gitignore to exclude backup and temporary files
- Added backward compatibility macros and typedefs
2025-05-13 13:40:17 -04:00
Tyeth Gundry
e5a4c36eba
Update library.properties - bump version to 2.0.1 2025-02-25 23:36:34 +00:00
Limor "Ladyada" Fried
1d146a354e
Merge pull request #18 from caternuson/fix_shunt
Fix setshunt values and product URL
2025-02-18 15:49:59 -05:00
caternuson
09ff8d7115 the other url 2025-02-18 12:36:25 -08:00
caternuson
e81e93ba64 fix setshunt and product url 2025-02-18 12:04:06 -08:00
Tyeth Gundry
45b7b40f65
Update library.properties - bump version to 2.0.0 2025-01-07 16:50:21 +00:00
ladyada
7d89e31704 adding 'INA219' compatible functions names 2024-12-20 12:02:08 -05:00
Tyeth Gundry
dfc35f6014
Update library.properties - bump version to 1.1.0 2024-06-25 16:37:35 +01:00
Carter Nelson
741d1f10f7
Merge pull request #11 from Dennis-van-Gils/main
Extended code, bug-fixes and adjusted default values in `setShunt()`
2024-06-20 11:05:14 -07:00
Dennis-van-Gils
5168419123 Moved _updateShuntCalRegister() to private 2024-06-20 18:57:50 +02:00
Dennis van Gils
f01f15dd5c Removed left-over and now redundant code 2024-06-20 11:04:15 +02:00
Dennis-van-Gils
d6f5f959ce Removed parameter adc_range from setShunt()
The ADC range is now set through method `setADCRange(). This required adding method `_updateShuntCalRegister()` and member `_shunt_res`.
2024-06-19 21:51:44 +02:00
Dennis van Gils
55c98df578 Revert "Default parameter values in setShunt() follow spec sheet now"
This reverts commit b7af44834f.
2024-06-19 10:48:11 +02:00
Dennis van Gils
3c27a1cb40 Renamed to resetAccumulators() 2024-06-19 10:47:29 +02:00
Dennis van Gils
ac0c4a75cc Added docstr _mode enums 2024-06-19 10:44:55 +02:00
Dennis van Gils
c5333dd74f Fixed doxygen report by adding missing docstrings 2024-06-07 11:06:20 +02:00
Dennis van Gils
827f7f518c Added method reset_accumulators() 2024-06-07 10:37:18 +02:00
Dennis van Gils
eb46da486d Fixed wrong bits retrieved by getMode() 2024-06-06 15:46:58 +02:00
Dennis-van-Gils
e1533e7bb4 Clang 2024-06-05 19:35:41 +02:00
Dennis-van-Gils
b7af44834f Default parameter values in setShunt() follow spec sheet now 2024-06-05 19:13:55 +02:00
Dennis-van-Gils
20272c927c Added optional adc_range parameter in method setShunt() 2024-06-05 19:11:13 +02:00
Dennis-van-Gils
f755c5d077 Added methods set/getTemperatureConversionTime() 2024-06-05 19:01:30 +02:00
Dennis-van-Gils
4721f762ab Added missing modes in INA228_MeasurementMode
* Added missing modes in enum `INA228_MeasurementMode`
2024-06-05 18:58:46 +02:00
ladyada
492d438bcf https://github.com/adafruit/Adafruit_INA228/issues/7 2024-05-21 15:26:12 -04:00
ladyada
3287142d82 fix for https://github.com/adafruit/Adafruit_INA228/issues/8 2024-05-21 15:24:49 -04:00
ladyada
ab9d7de17e kick 2023-10-29 18:23:03 -04:00
Tyeth Gundry
6dc6f7ba32
Merge pull request #1 from tyeth/update-prodinfo-fix-warning
Fix product info + add two switch cases to example
2023-10-25 14:36:59 +01:00
tyeth
e0a6db24d1 Tweak readme, fix header text for Doxygen links 2023-10-24 14:03:18 +01:00
tyeth
826bf41294 CLang formatting 2023-10-24 12:08:18 +01:00
tyeth
fc8592a3fa Fix product info + add two switch cases to example 2023-10-24 11:53:07 +01:00
11 changed files with 1058 additions and 414 deletions

13
.clang-format Normal file
View file

@ -0,0 +1,13 @@
Language: Cpp
BasedOnStyle: Google
IndentWidth: 2
ColumnLimit: 80
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Attach
DerivePointerAlignment: false
PointerAlignment: Left
SpacesBeforeTrailingComments: 1

View file

@ -19,12 +19,12 @@ jobs:
- name: pre-install
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}

6
.gitignore vendored
View file

@ -1,4 +1,8 @@
html/
Doxyfile
.vscode/
.pio/
.pio/
**/.claude/settings.local.json
*.bak
*.txt
*.pdf

View file

@ -1,40 +1,39 @@
/*!
* @file Adafruit_INA228.cpp
*
* @mainpage Adafruit INA228 I2C Current and Power sensor
*
* @section intro_sec Introduction
* @section ina228_intro Introduction
*
* I2C Driver for the INA228 I2C Current and Power sensor
*
* This is a library for the Adafruit INA228 breakout:
* http://www.adafruit.com/products/4226
* http://www.adafruit.com/products/5832
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
* @section dependencies Dependencies
* @section ina228_dependencies Dependencies
*
* This library depends on the Adafruit BusIO library
*
* @section author Author
* @section ina228_author Author
*
* Bryan Siepert for Adafruit Industries
*
* @section license License
* @section ina228_license License
*
* BSD (see license.txt)
*
* @section HISTORY
* @section ina228_history HISTORY
*
* v1.0 - First release
*/
#include "Arduino.h"
#include "Adafruit_INA228.h"
#include <Wire.h>
#include "Adafruit_INA228.h"
#include "Arduino.h"
/*!
* @brief Instantiates a new INA228 class
@ -47,147 +46,53 @@ Adafruit_INA228::Adafruit_INA228(void) {}
* The I2C address to be used.
* @param theWire
* The Wire object to be used for I2C connections.
* @param skipReset
* When set to true, will omit resetting all INA228 registers to
* their default values. Default: false.
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_INA228::begin(uint8_t i2c_address, TwoWire *theWire) {
i2c_dev = new Adafruit_I2CDevice(i2c_address, theWire);
if (!i2c_dev->begin()) {
bool Adafruit_INA228::begin(uint8_t i2c_address, TwoWire* theWire,
bool skipReset) {
if (!Adafruit_INA2xx::begin(i2c_address, theWire, skipReset)) {
return false;
}
Adafruit_I2CRegister *device_register =
new Adafruit_I2CRegister(i2c_dev, INA228_REG_DVC_UID, 2, MSBFIRST);
Adafruit_I2CRegister *mfg_register =
new Adafruit_I2CRegister(i2c_dev, INA228_REG_MFG_UID, 2, MSBFIRST);
Adafruit_I2CRegisterBits *device_id =
new Adafruit_I2CRegisterBits(device_register, 12, 4);
// make sure we're talking to the right chip
if ((mfg_register->read() != 0x5449) || (device_id->read() != 0x228)) {
if (_device_id != INA228_DEVICE_ID) {
return false;
}
Config = new Adafruit_I2CRegister(i2c_dev, INA228_REG_CONFIG, 2, MSBFIRST);
ADC_Config = new Adafruit_I2CRegister(i2c_dev, INA228_REG_ADCCFG, 2, MSBFIRST);
Diag_Alert = new Adafruit_I2CRegister(i2c_dev, INA228_REG_DIAGALRT, 2, MSBFIRST);
reset();
delay(2); // delay 2ms to give time for first measurement to finish
return true;
}
/**************************************************************************/
/*!
@brief Resets the harware. All registers are set to default values,
the same as a power-on reset.
@brief Resets the hardware specific to INA228
*/
/**************************************************************************/
void Adafruit_INA228::reset(void) {
Adafruit_I2CRegisterBits reset = Adafruit_I2CRegisterBits(Config, 1, 15);
reset.write(1);
Adafruit_I2CRegisterBits alert_conv =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 14);
alert_conv.write(1);
setMode(INA228_MODE_CONTINUOUS);
// Perform base class reset
Adafruit_INA2xx::reset();
// Any additional INA228 specific reset actions would go here
}
/**************************************************************************/
/*!
@brief Sets the shunt calibration by resistor
@param shunt_res Resistance of the shunt in ohms (floating point)
@brief Updates the shunt calibration value to the INA228 register.
*/
/**************************************************************************/
void Adafruit_INA228::setShunt(float shunt_res, float max_current) {
_current_lsb = max_current / (float)(1UL << 19);
//Serial.print("current lsb is (uA) ");
//Serial.println(_current_lsb * 1000000, 8);
bool adcrange = (Config->read() >> 4) & 1;
void Adafruit_INA228::_updateShuntCalRegister() {
float scale = 1;
if (adcrange) {
if (getADCRange()) {
scale = 4;
}
float shunt_cal = 13107.2 * 1000000.0 * shunt_res * _current_lsb * scale;
//Serial.print("shunt cal is ");
//Serial.println(shunt_cal);
float shunt_cal = 13107.2 * 1000000.0 * _shunt_res * _current_lsb * scale;
Adafruit_I2CRegister shunt =
Adafruit_I2CRegister(i2c_dev, INA228_REG_SHUNTCAL, 2, MSBFIRST);
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_SHUNTCAL, 2, MSBFIRST);
shunt.write(shunt_cal);
}
/**************************************************************************/
/*!
@brief Reads the die temperature
@return The current die temp in deg C
*/
/**************************************************************************/
float Adafruit_INA228::readDieTemp(void) {
Adafruit_I2CRegister temp =
Adafruit_I2CRegister(i2c_dev, INA228_REG_DIETEMP, 2, MSBFIRST);
return (float)temp.read() * 7.8125 / 1000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Current register.
@return The current current measurement in mA
*/
/**************************************************************************/
float Adafruit_INA228::readCurrent(void) {
Adafruit_I2CRegister current =
Adafruit_I2CRegister(i2c_dev, INA228_REG_CURRENT, 3, MSBFIRST);
int32_t i = current.read();
if (i & 0x800000) i |= 0xFF000000;
return (float)i / 16.0 * _current_lsb * 1000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Bus Voltage register.
@return The current bus voltage measurement in mV
*/
/**************************************************************************/
float Adafruit_INA228::readBusVoltage(void) {
Adafruit_I2CRegister bus_voltage =
Adafruit_I2CRegister(i2c_dev, INA228_REG_VBUS, 3, MSBFIRST);
return (float)((uint32_t)bus_voltage.read() >> 4) * 195.3125 / 1000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Shunt Voltage register.
@return The current shunt voltage measurement in mV
*/
/**************************************************************************/
float Adafruit_INA228::readShuntVoltage(void) {
bool adcrange = (Config->read() >> 4) & 1;
float scale = 312.5;
if (adcrange) {
scale = 78.125;
}
Adafruit_I2CRegister shunt_voltage =
Adafruit_I2CRegister(i2c_dev, INA228_REG_VSHUNT, 3, MSBFIRST);
int32_t v = shunt_voltage.read();
if (v & 0x800000) v |= 0xFF000000;
return v / 16.0 * scale / 1000000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Power register.
@return The current Power calculation in mW
*/
/**************************************************************************/
float Adafruit_INA228::readPower(void) {
Adafruit_I2CRegister power =
Adafruit_I2CRegister(i2c_dev, INA228_REG_POWER, 3, MSBFIRST);
return (float)power.read() * 3.2 * _current_lsb * 1000;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Energy register.
@ -196,11 +101,11 @@ float Adafruit_INA228::readPower(void) {
/**************************************************************************/
float Adafruit_INA228::readEnergy(void) {
Adafruit_I2CRegister energy =
Adafruit_I2CRegister(i2c_dev, INA228_REG_ENERGY, 5, MSBFIRST);
Adafruit_I2CRegister(i2c_dev, INA228_REG_ENERGY, 5, MSBFIRST);
uint8_t buff[5];
energy.read(buff, 5);
float e = 0;
for (int i=0; i<5; i++) {
for (int i = 0; i < 5; i++) {
e *= 256;
e += buff[i];
}
@ -209,162 +114,104 @@ float Adafruit_INA228::readEnergy(void) {
/**************************************************************************/
/*!
@brief Returns the current measurement mode
@return The current mode
@brief Reads and scales the current value of the Charge register.
@return The current Charge calculation in Coulombs
*/
/**************************************************************************/
INA228_MeasurementMode Adafruit_INA228::getMode(void) {
Adafruit_I2CRegisterBits mode = Adafruit_I2CRegisterBits(Config, 3, 0);
return (INA228_MeasurementMode)mode.read();
}
/**************************************************************************/
/*!
@brief Sets a new measurement mode
@param new_mode
The new mode to be set
*/
/**************************************************************************/
void Adafruit_INA228::setMode(INA228_MeasurementMode new_mode) {
Adafruit_I2CRegisterBits mode = Adafruit_I2CRegisterBits(ADC_Config, 4, 12);
mode.write(new_mode);
}
/**************************************************************************/
/*!
@brief Reads the current number of averaging samples
@return The current number of averaging samples
*/
/**************************************************************************/
INA228_AveragingCount Adafruit_INA228::getAveragingCount(void) {
Adafruit_I2CRegisterBits averaging_count =
Adafruit_I2CRegisterBits(ADC_Config, 3, 0);
return (INA228_AveragingCount)averaging_count.read();
}
/**************************************************************************/
/*!
@brief Sets the number of averaging samples
@param count
The number of samples to be averaged
*/
/**************************************************************************/
void Adafruit_INA228::setAveragingCount(INA228_AveragingCount count) {
Adafruit_I2CRegisterBits averaging_count =
Adafruit_I2CRegisterBits(ADC_Config, 3, 0);
averaging_count.write(count);
}
/**************************************************************************/
/*!
@brief Reads the current current conversion time
@return The current current conversion time
*/
/**************************************************************************/
INA228_ConversionTime Adafruit_INA228::getCurrentConversionTime(void) {
Adafruit_I2CRegisterBits current_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 6);
return (INA228_ConversionTime)current_conversion_time.read();
}
/**************************************************************************/
/*!
@brief Sets the current conversion time
@param time
The new current conversion time
*/
/**************************************************************************/
void Adafruit_INA228::setCurrentConversionTime(INA228_ConversionTime time) {
Adafruit_I2CRegisterBits current_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 6);
current_conversion_time.write(time);
}
/**************************************************************************/
/*!
@brief Reads the current bus voltage conversion time
@return The current bus voltage conversion time
*/
/**************************************************************************/
INA228_ConversionTime Adafruit_INA228::getVoltageConversionTime(void) {
Adafruit_I2CRegisterBits voltage_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 9);
return (INA228_ConversionTime)voltage_conversion_time.read();
}
/**************************************************************************/
/*!
@brief Sets the bus voltage conversion time
@param time
The new bus voltage conversion time
*/
/**************************************************************************/
void Adafruit_INA228::setVoltageConversionTime(INA228_ConversionTime time) {
Adafruit_I2CRegisterBits voltage_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 9);
voltage_conversion_time.write(time);
float Adafruit_INA228::readCharge(void) {
Adafruit_I2CRegister charge =
Adafruit_I2CRegister(i2c_dev, INA228_REG_CHARGE, 5, MSBFIRST);
uint8_t buff[5];
charge.read(buff, 5);
// Convert 40-bit two's complement value
int64_t c = 0;
for (int i = 0; i < 5; i++) {
c = (c << 8) | buff[i];
}
// Handle sign extension for 40-bit two's complement
if (c & ((int64_t)1 << 39)) {
c |= 0xFFFFFF0000000000; // Sign extend to 64 bits
}
return (float)c * _current_lsb;
}
/**************************************************************************/
/*!
@brief Checks if the most recent one shot measurement has completed
@return true if the conversion has completed
@brief Returns the current alert type
@return The current alert type
*/
/**************************************************************************/
bool Adafruit_INA228::conversionReady(void) {
Adafruit_I2CRegisterBits conversion_ready =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 1);
return conversion_ready.read();
INA228_AlertType Adafruit_INA228::getAlertType(void) {
Adafruit_I2CRegisterBits alert_type =
Adafruit_I2CRegisterBits(Diag_Alert, 6, 8);
return (INA228_AlertType)alert_type.read();
}
/**************************************************************************/
/*!
@brief Reads the current alert polarity setting
@return The current bus alert polarity setting
@brief Sets a new alert type
@param alert
The new alert type to be set
*/
/**************************************************************************/
INA228_AlertPolarity Adafruit_INA228::getAlertPolarity(void) {
Adafruit_I2CRegisterBits alert_polarity =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 12);
return (INA228_AlertPolarity)alert_polarity.read();
void Adafruit_INA228::setAlertType(INA228_AlertType alert) {
Adafruit_I2CRegisterBits alert_type =
Adafruit_I2CRegisterBits(Diag_Alert, 6, 8);
alert_type.write(alert);
}
/**************************************************************************/
/*!
@brief Sets Alert Polarity Bit
@param polarity
The polarity of the alert pin
@brief Resets the energy and charge accumulators
*/
/**************************************************************************/
void Adafruit_INA228::setAlertPolarity(INA228_AlertPolarity polarity) {
Adafruit_I2CRegisterBits alert_polarity =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 12);
alert_polarity.write(polarity);
void Adafruit_INA228::resetAccumulators(void) {
Adafruit_I2CRegisterBits reset_accumulators =
Adafruit_I2CRegisterBits(Config, 1, 14);
reset_accumulators.write(1);
}
/**************************************************************************/
/*!
@brief Reads the current alert latch setting
@return The current bus alert latch setting
@brief Reads the die temperature with the INA228-specific conversion factor
@return The current die temp in deg C
*/
/**************************************************************************/
INA228_AlertLatch Adafruit_INA228::getAlertLatch(void) {
Adafruit_I2CRegisterBits alert_latch =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 15);
return (INA228_AlertLatch)alert_latch.read();
float Adafruit_INA228::readDieTemp(void) {
Adafruit_I2CRegister temp =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_DIETEMP, 2, MSBFIRST);
int16_t t = temp.read();
// INA228 uses 16 bits for temperature with 7.8125 m°C/LSB
return (float)t * 7.8125 / 1000.0;
}
/**************************************************************************/
/*!
@brief Sets Alert Latch Bit
@param state
The parameter which asserts the ALERT pin
@brief Reads and scales the current value of the Bus Voltage register
using INA228-specific conversion factor.
@return The current bus voltage measurement in V
*/
/**************************************************************************/
void Adafruit_INA228::setAlertLatch(INA228_AlertLatch state) {
Adafruit_I2CRegisterBits alert_latch =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 15);
alert_latch.write(state);
float Adafruit_INA228::readBusVoltage(void) {
Adafruit_I2CRegister bus_voltage =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_VBUS, 3, MSBFIRST);
// INA228 uses 195.3125 µV/LSB for bus voltage
return (float)((uint32_t)bus_voltage.read() >> 4) * 195.3125 / 1e6;
}
/**************************************************************************/
/*!
@brief Reads the 12 possible alert reason bits from DIAG_ALRT
@return 10 bits that indiccate MEMSTAT (bit 0), CONVRF, POL, BUSUL, BUSOL, SHNTUL, SHNTOL,
TMPOL, reserved, MATHOF, CHARGEOF, ENERGYOF (bit 11)
@brief Sets the shunt calibration by resistor for INA228.
@param shunt_res Resistance of the shunt in ohms (floating point)
@param max_current Maximum expected current in A (floating point)
*/
/**************************************************************************/
uint16_t Adafruit_INA228::alertFunctionFlags(void) {
Adafruit_I2CRegisterBits alert_flags =
Adafruit_I2CRegisterBits(Diag_Alert, 12, 0);
return alert_flags.read();
}
void Adafruit_INA228::setShunt(float shunt_res, float max_current) {
_shunt_res = shunt_res;
// INA228 uses 2^19 as the divisor
_current_lsb = max_current / (float)(1UL << 19);
_updateShuntCalRegister();
}

View file

@ -4,7 +4,7 @@
* I2C Driver for INA228 Current and Power sensor
*
* This is a library for the Adafruit INA228 breakout:
* http://www.adafruit.com/products/xxxx
* http://www.adafruit.com/products/5832
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
@ -17,84 +17,112 @@
#ifndef _ADAFRUIT_INA228_H
#define _ADAFRUIT_INA228_H
#include "Arduino.h"
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Wire.h>
#include "Adafruit_INA2xx.h"
#define INA228_I2CADDR_DEFAULT 0x40 ///< INA228 default i2c address
#define INA228_REG_CONFIG 0x00 ///< Configuration register
#define INA228_REG_ADCCFG 0x01
#define INA228_REG_SHUNTCAL 0x02
#define INA228_REG_SHUNTTEMPCO 0x03
#define INA228_REG_VSHUNT 0x04
#define INA228_REG_VBUS 0x05
#define INA228_REG_DIETEMP 0x06
#define INA228_REG_CURRENT 0x07
#define INA228_REG_POWER 0x08
#define INA228_REG_ENERGY 0x09
#define INA228_REG_CHARGE 0x0A
#define INA228_REG_DIAGALRT 0x0B
#define INA228_REG_SOVL 0x0C
#define INA228_REG_SUVL 0x0D
#define INA228_REG_BOVL 0x0E
#define INA228_REG_BUVL 0x0F
#define INA228_REG_TEMPLIMIT 0x10
#define INA228_REG_PWRLIMIT 0x10
#define INA228_REG_MFG_UID 0x3E ///< Manufacturer ID Register
#define INA228_REG_DVC_UID 0x3F ///< Device ID and Revision Register
#define INA228_DEVICE_ID 0x228 ///< INA228 device ID
// INA228 specific registers
#define INA228_REG_ENERGY 0x09 ///< Energy result register
#define INA228_REG_CHARGE 0x0A ///< Charge result register (40-bit)
#define INA228_REG_SHUNTTEMPCO 0x03 ///< Shunt temperature coefficient register
///@{
/**
* @brief Mode options.
* @name Legacy compatibility macros
*
* Allowed values for setMode.
* These macros provide backward compatibility with earlier versions of the
* library
*/
typedef enum _mode {
INA228_MODE_SHUTDOWN = 0x00, /**< SHUTDOWN: Minimize quiescient current and
turn off current into the device inputs. Set
another mode to exit shutown mode **/
INA228_MODE_TRIGGERED = 0x07, /**< TRIGGERED: Trigger a one-shot measurement
of temp, current and bus voltage. Set the TRIGGERED
mode again to take a new measurement **/
INA228_MODE_CONTINUOUS = 0x0F, /**< CONTINUOUS: (Default) Continuously update
the temp, current, bus voltage and power
registers with new measurements **/
} INA228_MeasurementMode;
#define INA228_MODE_SHUTDOWN \
INA2XX_MODE_SHUTDOWN ///< Alias for INA2XX_MODE_SHUTDOWN
#define INA228_MODE_TRIG_BUS \
INA2XX_MODE_TRIG_BUS ///< Alias for INA2XX_MODE_TRIG_BUS
#define INA228_MODE_TRIG_SHUNT \
INA2XX_MODE_TRIG_SHUNT ///< Alias for INA2XX_MODE_TRIG_SHUNT
#define INA228_MODE_TRIG_BUS_SHUNT \
INA2XX_MODE_TRIG_BUS_SHUNT ///< Alias for INA2XX_MODE_TRIG_BUS_SHUNT
#define INA228_MODE_TRIG_TEMP \
INA2XX_MODE_TRIG_TEMP ///< Alias for INA2XX_MODE_TRIG_TEMP
#define INA228_MODE_TRIG_TEMP_BUS \
INA2XX_MODE_TRIG_TEMP_BUS ///< Alias for INA2XX_MODE_TRIG_TEMP_BUS
#define INA228_MODE_TRIG_TEMP_SHUNT \
INA2XX_MODE_TRIG_TEMP_SHUNT ///< Alias for INA2XX_MODE_TRIG_TEMP_SHUNT
#define INA228_MODE_TRIG_TEMP_BUS_SHUNT \
INA2XX_MODE_TRIG_TEMP_BUS_SHUNT ///< Alias for INA2XX_MODE_TRIG_TEMP_BUS_SHUNT
#define INA228_MODE_SHUTDOWN2 \
INA2XX_MODE_SHUTDOWN2 ///< Alias for INA2XX_MODE_SHUTDOWN2
#define INA228_MODE_CONT_BUS \
INA2XX_MODE_CONT_BUS ///< Alias for INA2XX_MODE_CONT_BUS
#define INA228_MODE_CONT_SHUNT \
INA2XX_MODE_CONT_SHUNT ///< Alias for INA2XX_MODE_CONT_SHUNT
#define INA228_MODE_CONT_BUS_SHUNT \
INA2XX_MODE_CONT_BUS_SHUNT ///< Alias for INA2XX_MODE_CONT_BUS_SHUNT
#define INA228_MODE_CONT_TEMP \
INA2XX_MODE_CONT_TEMP ///< Alias for INA2XX_MODE_CONT_TEMP
#define INA228_MODE_CONT_TEMP_BUS \
INA2XX_MODE_CONT_TEMP_BUS ///< Alias for INA2XX_MODE_CONT_TEMP_BUS
#define INA228_MODE_CONT_TEMP_SHUNT \
INA2XX_MODE_CONT_TEMP_SHUNT ///< Alias for INA2XX_MODE_CONT_TEMP_SHUNT
#define INA228_MODE_CONT_TEMP_BUS_SHUNT \
INA2XX_MODE_CONT_TEMP_BUS_SHUNT ///< Alias for INA2XX_MODE_CONT_TEMP_BUS_SHUNT
#define INA228_MODE_TRIGGERED \
INA2XX_MODE_TRIGGERED ///< Alias for INA2XX_MODE_TRIGGERED
#define INA228_MODE_CONTINUOUS \
INA2XX_MODE_CONTINUOUS ///< Alias for INA2XX_MODE_CONTINUOUS
#define INA228_TIME_50_us INA2XX_TIME_50_us ///< Alias for INA2XX_TIME_50_us
#define INA228_TIME_84_us INA2XX_TIME_84_us ///< Alias for INA2XX_TIME_84_us
#define INA228_TIME_150_us INA2XX_TIME_150_us ///< Alias for INA2XX_TIME_150_us
#define INA228_TIME_280_us INA2XX_TIME_280_us ///< Alias for INA2XX_TIME_280_us
#define INA228_TIME_540_us INA2XX_TIME_540_us ///< Alias for INA2XX_TIME_540_us
#define INA228_TIME_1052_us \
INA2XX_TIME_1052_us ///< Alias for INA2XX_TIME_1052_us
#define INA228_TIME_2074_us \
INA2XX_TIME_2074_us ///< Alias for INA2XX_TIME_2074_us
#define INA228_TIME_4120_us \
INA2XX_TIME_4120_us ///< Alias for INA2XX_TIME_4120_us
#define INA228_COUNT_1 INA2XX_COUNT_1 ///< Alias for INA2XX_COUNT_1
#define INA228_COUNT_4 INA2XX_COUNT_4 ///< Alias for INA2XX_COUNT_4
#define INA228_COUNT_16 INA2XX_COUNT_16 ///< Alias for INA2XX_COUNT_16
#define INA228_COUNT_64 INA2XX_COUNT_64 ///< Alias for INA2XX_COUNT_64
#define INA228_COUNT_128 INA2XX_COUNT_128 ///< Alias for INA2XX_COUNT_128
#define INA228_COUNT_256 INA2XX_COUNT_256 ///< Alias for INA2XX_COUNT_256
#define INA228_COUNT_512 INA2XX_COUNT_512 ///< Alias for INA2XX_COUNT_512
#define INA228_COUNT_1024 INA2XX_COUNT_1024 ///< Alias for INA2XX_COUNT_1024
#define INA228_ALERT_POLARITY_NORMAL \
INA2XX_ALERT_POLARITY_NORMAL ///< Alias for INA2XX_ALERT_POLARITY_NORMAL
#define INA228_ALERT_POLARITY_INVERTED \
INA2XX_ALERT_POLARITY_INVERTED ///< Alias for INA2XX_ALERT_POLARITY_INVERTED
#define INA228_ALERT_LATCH_ENABLED \
INA2XX_ALERT_LATCH_ENABLED ///< Alias for INA2XX_ALERT_LATCH_ENABLED
#define INA228_ALERT_LATCH_TRANSPARENT \
INA2XX_ALERT_LATCH_TRANSPARENT ///< Alias for INA2XX_ALERT_LATCH_TRANSPARENT
///@}
///@{
/**
* @brief Conversion Time options.
* @name Legacy type aliases
*
* Allowed values for setCurrentConversionTime and setVoltageConversionTime.
* These typedefs provide backward compatibility with earlier versions of the
* library
*/
typedef enum _conversion_time {
INA228_TIME_50_us, ///< Measurement time: 50us
INA228_TIME_84_us, ///< Measurement time: 84us
INA228_TIME_150_us, ///< Measurement time: 150us
INA228_TIME_280_us, ///< Measurement time: 280us
INA228_TIME_540_us, ///< Measurement time: 540us
INA228_TIME_1052_us, ///< Measurement time: 1052us
INA228_TIME_2074_us, ///< Measurement time: 2074us
INA228_TIME_4120_us, ///< Measurement time: 4120us
} INA228_ConversionTime;
typedef INA2XX_MeasurementMode
INA228_MeasurementMode; ///< Alias for INA2XX_MeasurementMode
typedef INA2XX_ConversionTime
INA228_ConversionTime; ///< Alias for INA2XX_ConversionTime
typedef INA2XX_AveragingCount
INA228_AveragingCount; ///< Alias for INA2XX_AveragingCount
typedef INA2XX_AlertPolarity
INA228_AlertPolarity; ///< Alias for INA2XX_AlertPolarity
typedef INA2XX_AlertLatch INA228_AlertLatch; ///< Alias for INA2XX_AlertLatch
///@}
/**
* @brief Averaging Count options.
*
* Allowed values forsetAveragingCount.
*/
typedef enum _count {
INA228_COUNT_1, ///< Window size: 1 sample (Default)
INA228_COUNT_4, ///< Window size: 4 samples
INA228_COUNT_16, ///< Window size: 16 samples
INA228_COUNT_64, ///< Window size: 64 samples
INA228_COUNT_128, ///< Window size: 128 samples
INA228_COUNT_256, ///< Window size: 256 samples
INA228_COUNT_512, ///< Window size: 512 samples
INA228_COUNT_1024, ///< Window size: 1024 samples
} INA228_AveragingCount;
/**
* @brief Alert trigger options.
* @brief Alert trigger options specific to INA228.
*
* Allowed values for setAlertType.
*/
@ -108,78 +136,32 @@ typedef enum _alert_type {
INA228_ALERT_NONE = 0x0, ///< Do not trigger alert pin (Default)
} INA228_AlertType;
/**
* @brief Alert pin polarity options.
*
* Allowed values for setAlertPolarity.
*/
typedef enum _alert_polarity {
INA228_ALERT_POLARITY_NORMAL = 0x0, ///< Active high open-collector (Default)
INA228_ALERT_POLARITY_INVERTED = 0x1, ///< Active low open-collector
} INA228_AlertPolarity;
/**
* @brief Alert pin latch options.
*
* Allowed values for setAlertLatch.
*/
typedef enum _alert_latch {
INA228_ALERT_LATCH_ENABLED = 0x1, /**< Alert will latch until Mask/Enable
register is read **/
INA228_ALERT_LATCH_TRANSPARENT = 0x0, /**< Alert will reset when fault is
cleared **/
} INA228_AlertLatch;
/*!
* @brief Class that stores state and functions for interacting with
* INA228 Current and Power Sensor
*/
class Adafruit_INA228 {
public:
class Adafruit_INA228 : public Adafruit_INA2xx {
public:
Adafruit_INA228();
bool begin(uint8_t i2c_addr = INA228_I2CADDR_DEFAULT,
TwoWire *theWire = &Wire);
void reset(void);
TwoWire* theWire = &Wire, bool skipReset = false);
void reset(void) override;
void setShunt(float shunt_res = 0.1, float max_current = 3.2);
float readDieTemp(void);
float readCurrent(void);
float readBusVoltage(void);
float readShuntVoltage(void);
float readPower(void);
// INA228 specific functions
float readEnergy(void);
void setMode(INA228_MeasurementMode mode);
INA228_MeasurementMode getMode(void);
bool conversionReady(void);
uint16_t alertFunctionFlags(void);
float getAlertLimit(void);
void setAlertLimit(float limit);
INA228_AlertLatch getAlertLatch(void);
void setAlertLatch(INA228_AlertLatch state);
INA228_AlertPolarity getAlertPolarity(void);
void setAlertPolarity(INA228_AlertPolarity polarity);
float readCharge(void);
INA228_AlertType getAlertType(void);
void setAlertType(INA228_AlertType alert);
void resetAccumulators(void);
float readDieTemp(void) override;
float readBusVoltage(void) override;
void setShunt(float shunt_res = 0.1, float max_current = 3.2) override;
INA228_ConversionTime getCurrentConversionTime(void);
void setCurrentConversionTime(INA228_ConversionTime time);
INA228_ConversionTime getVoltageConversionTime(void);
void setVoltageConversionTime(INA228_ConversionTime time);
INA228_AveragingCount getAveragingCount(void);
void setAveragingCount(INA228_AveragingCount count);
// INA228 specific register pointer
Adafruit_I2CRegister* AlertLimit; ///< BusIO Register for AlertLimit
Adafruit_I2CRegister *Config, ///< BusIO Register for Config
*ADC_Config, ///< BusIO Register for Config
*Diag_Alert, ///< BusIO Register for MaskEnable
*AlertLimit; ///< BusIO Register for AlertLimit
private:
float _current_lsb;
Adafruit_I2CDevice *i2c_dev;
protected:
void _updateShuntCalRegister(void) override;
};
#endif
#endif

459
Adafruit_INA2xx.cpp Normal file
View file

@ -0,0 +1,459 @@
/*!
* @file Adafruit_INA2xx.cpp
*
* @section ina2xx_intro Introduction
*
* I2C Driver base class for the INA2xx I2C Current and Power sensors
*
* This is a library for the Adafruit INA228 breakout:
* http://www.adafruit.com/products/5832
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
* @section ina2xx_dependencies Dependencies
*
* This library depends on the Adafruit BusIO library
*
* @section ina2xx_author Author
*
* Bryan Siepert for Adafruit Industries
*
* @section ina2xx_license License
*
* BSD (see license.txt)
*
* @section ina2xx_history HISTORY
*
* v1.0 - First release
*/
#include "Adafruit_INA2xx.h"
#include <Wire.h>
#include "Arduino.h"
/*!
* @brief Instantiates a new INA2xx class
*/
Adafruit_INA2xx::Adafruit_INA2xx(void) {}
/*!
* @brief Sets up the HW
* @param i2c_address
* The I2C address to be used.
* @param theWire
* The Wire object to be used for I2C connections.
* @param skipReset
* When set to true, will omit resetting all registers to
* their default values. Default: false.
* @return True if initialization was successful (including verifying
* the manufacturer ID is Texas Instruments: 0x5449), otherwise
* false.
*/
bool Adafruit_INA2xx::begin(uint8_t i2c_address, TwoWire* theWire,
bool skipReset) {
i2c_dev = new Adafruit_I2CDevice(i2c_address, theWire);
if (!i2c_dev->begin()) {
return false;
}
Adafruit_I2CRegister* device_register =
new Adafruit_I2CRegister(i2c_dev, INA2XX_REG_DVC_UID, 2, MSBFIRST);
Adafruit_I2CRegister* mfg_register =
new Adafruit_I2CRegister(i2c_dev, INA2XX_REG_MFG_UID, 2, MSBFIRST);
Adafruit_I2CRegisterBits* device_id =
new Adafruit_I2CRegisterBits(device_register, 12, 4);
// Check manufacturer ID (should be 0x5449 for Texas Instruments)
uint16_t mfg_id = mfg_register->read();
if (mfg_id != 0x5449) {
return false;
}
// Store device ID for validation in derived classes
_device_id = device_id->read();
Config = new Adafruit_I2CRegister(i2c_dev, INA2XX_REG_CONFIG, 2, MSBFIRST);
ADC_Config =
new Adafruit_I2CRegister(i2c_dev, INA2XX_REG_ADCCFG, 2, MSBFIRST);
Diag_Alert =
new Adafruit_I2CRegister(i2c_dev, INA2XX_REG_DIAGALRT, 2, MSBFIRST);
if (!skipReset) {
reset();
delay(2); // delay 2ms to give time for first measurement to finish
}
return true;
}
/**************************************************************************/
/*!
@brief Resets the hardware. All registers are set to default values,
the same as a power-on reset.
*/
/**************************************************************************/
void Adafruit_INA2xx::reset(void) {
Adafruit_I2CRegisterBits reset = Adafruit_I2CRegisterBits(Config, 1, 15);
reset.write(1);
Adafruit_I2CRegisterBits alert_conv =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 14);
alert_conv.write(1);
setMode(INA2XX_MODE_CONTINUOUS);
}
/**************************************************************************/
/*!
@brief Updates the shunt calibration value to the register.
This is implemented in the derived classes due to different calculations
*/
/**************************************************************************/
void Adafruit_INA2xx::_updateShuntCalRegister() {
// Implemented in derived classes
}
/**************************************************************************/
/*!
@brief Sets the shunt calibration by resistor.
@note This base implementation uses INA228 settings.
Derived classes override this method for their specific settings.
@param shunt_res Resistance of the shunt in ohms (floating point)
@param max_current Maximum expected current in A (floating point)
*/
/**************************************************************************/
void Adafruit_INA2xx::setShunt(float shunt_res, float max_current) {
_shunt_res = shunt_res;
// Default to INA228 behavior (2^19 divisor)
_current_lsb = max_current / (float)(1UL << 19);
_updateShuntCalRegister();
}
/**************************************************************************/
/*!
@brief Sets the shunt full scale ADC range across IN+ and IN-.
@param adc_range
Shunt full scale ADC range (0: +/-163.84 mV or 1: +/-40.96 mV)
*/
/**************************************************************************/
void Adafruit_INA2xx::setADCRange(uint8_t adc_range) {
Adafruit_I2CRegisterBits adc_range_bit =
Adafruit_I2CRegisterBits(Config, 1, 4);
adc_range_bit.write(adc_range);
_updateShuntCalRegister();
}
/**************************************************************************/
/*!
@brief Reads the shunt full scale ADC range across IN+ and IN-.
@return Shunt full scale ADC range (0: +/-163.84 mV or 1: +/-40.96 mV)
*/
/**************************************************************************/
uint8_t Adafruit_INA2xx::getADCRange() {
return (Config->read() >> 4) & 1;
}
/**************************************************************************/
/*!
@brief Reads the die temperature (using INA228 scale factor by default)
@note This base implementation uses the INA228 conversion factor of 7.8125
m°C/LSB. Derived classes override this method as needed (e.g., INA237).
@return The current die temp in deg C
*/
/**************************************************************************/
float Adafruit_INA2xx::readDieTemp(void) {
Adafruit_I2CRegister temp =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_DIETEMP, 2, MSBFIRST);
int16_t t = temp.read();
// INA228 uses 16 bits for temperature with 7.8125 m°C/LSB
return (float)t * 7.8125 / 1000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Current register.
@return The current current measurement in mA
*/
/**************************************************************************/
float Adafruit_INA2xx::readCurrent(void) {
Adafruit_I2CRegister current =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_CURRENT, 3, MSBFIRST);
int32_t i = current.read();
if (i & 0x800000)
i |= 0xFF000000;
return (float)i / 16.0 * _current_lsb * 1000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Current register.
@return The current current measurement in mA
*/
/**************************************************************************/
float Adafruit_INA2xx::getCurrent_mA(void) {
return readCurrent();
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Bus Voltage register.
@note This base implementation uses the INA228 conversion factor.
Derived classes override this method for their specific conversion
factors.
@return The current bus voltage measurement in V
*/
/**************************************************************************/
float Adafruit_INA2xx::readBusVoltage(void) {
Adafruit_I2CRegister bus_voltage =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_VBUS, 3, MSBFIRST);
// INA228 uses 195.3125 µV/LSB (microvolts) for bus voltage,
// so we need to divide by 1e6 to get Volts
return (float)((uint32_t)bus_voltage.read() >> 4) * 195.3125 / 1e6;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Bus Voltage register.
@return The current bus voltage measurement in V
*/
/**************************************************************************/
float Adafruit_INA2xx::getBusVoltage_V(void) {
return readBusVoltage();
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Shunt Voltage register.
@return The current shunt voltage measurement in mV
*/
/**************************************************************************/
float Adafruit_INA2xx::readShuntVoltage(void) {
float scale = 312.5;
if (getADCRange()) {
scale = 78.125;
}
Adafruit_I2CRegister shunt_voltage =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_VSHUNT, 3, MSBFIRST);
int32_t v = shunt_voltage.read();
if (v & 0x800000)
v |= 0xFF000000;
return (float)v / 16.0 * scale / 1000000.0;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Shunt Voltage register.
@return The current shunt voltage measurement in mV
*/
/**************************************************************************/
float Adafruit_INA2xx::getShuntVoltage_mV(void) {
return readShuntVoltage();
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Power register.
@return The current Power calculation in mW
*/
/**************************************************************************/
float Adafruit_INA2xx::readPower(void) {
Adafruit_I2CRegister power =
Adafruit_I2CRegister(i2c_dev, INA2XX_REG_POWER, 3, MSBFIRST);
return (float)power.read() * 3.2 * _current_lsb * 1000;
}
/**************************************************************************/
/*!
@brief Reads and scales the current value of the Power register.
@return The current Power calculation in mW
*/
/**************************************************************************/
float Adafruit_INA2xx::getPower_mW(void) {
return readPower();
}
/**************************************************************************/
/*!
@brief Returns the current measurement mode
@return The current mode
*/
/**************************************************************************/
INA2XX_MeasurementMode Adafruit_INA2xx::getMode(void) {
Adafruit_I2CRegisterBits mode = Adafruit_I2CRegisterBits(ADC_Config, 4, 12);
return (INA2XX_MeasurementMode)mode.read();
}
/**************************************************************************/
/*!
@brief Sets a new measurement mode
@param new_mode
The new mode to be set
*/
/**************************************************************************/
void Adafruit_INA2xx::setMode(INA2XX_MeasurementMode new_mode) {
Adafruit_I2CRegisterBits mode = Adafruit_I2CRegisterBits(ADC_Config, 4, 12);
mode.write(new_mode);
}
/**************************************************************************/
/*!
@brief Reads the current number of averaging samples
@return The current number of averaging samples
*/
/**************************************************************************/
INA2XX_AveragingCount Adafruit_INA2xx::getAveragingCount(void) {
Adafruit_I2CRegisterBits averaging_count =
Adafruit_I2CRegisterBits(ADC_Config, 3, 0);
return (INA2XX_AveragingCount)averaging_count.read();
}
/**************************************************************************/
/*!
@brief Sets the number of averaging samples
@param count
The number of samples to be averaged
*/
/**************************************************************************/
void Adafruit_INA2xx::setAveragingCount(INA2XX_AveragingCount count) {
Adafruit_I2CRegisterBits averaging_count =
Adafruit_I2CRegisterBits(ADC_Config, 3, 0);
averaging_count.write(count);
}
/**************************************************************************/
/*!
@brief Reads the current current conversion time
@return The current current conversion time
*/
/**************************************************************************/
INA2XX_ConversionTime Adafruit_INA2xx::getCurrentConversionTime(void) {
Adafruit_I2CRegisterBits current_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 6);
return (INA2XX_ConversionTime)current_conversion_time.read();
}
/**************************************************************************/
/*!
@brief Sets the current conversion time
@param time
The new current conversion time
*/
/**************************************************************************/
void Adafruit_INA2xx::setCurrentConversionTime(INA2XX_ConversionTime time) {
Adafruit_I2CRegisterBits current_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 6);
current_conversion_time.write(time);
}
/**************************************************************************/
/*!
@brief Reads the current bus voltage conversion time
@return The current bus voltage conversion time
*/
/**************************************************************************/
INA2XX_ConversionTime Adafruit_INA2xx::getVoltageConversionTime(void) {
Adafruit_I2CRegisterBits voltage_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 9);
return (INA2XX_ConversionTime)voltage_conversion_time.read();
}
/**************************************************************************/
/*!
@brief Sets the bus voltage conversion time
@param time
The new bus voltage conversion time
*/
/**************************************************************************/
void Adafruit_INA2xx::setVoltageConversionTime(INA2XX_ConversionTime time) {
Adafruit_I2CRegisterBits voltage_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 9);
voltage_conversion_time.write(time);
}
/**************************************************************************/
/*!
@brief Reads the temperature conversion time
@return The temperature conversion time
*/
/**************************************************************************/
INA2XX_ConversionTime Adafruit_INA2xx::getTemperatureConversionTime(void) {
Adafruit_I2CRegisterBits temperature_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 3);
return (INA2XX_ConversionTime)temperature_conversion_time.read();
}
/**************************************************************************/
/*!
@brief Sets the temperature conversion time
@param time
The new temperature conversion time
*/
/**************************************************************************/
void Adafruit_INA2xx::setTemperatureConversionTime(INA2XX_ConversionTime time) {
Adafruit_I2CRegisterBits temperature_conversion_time =
Adafruit_I2CRegisterBits(ADC_Config, 3, 3);
temperature_conversion_time.write(time);
}
/**************************************************************************/
/*!
@brief Checks if the most recent one shot measurement has completed
@return true if the conversion has completed
*/
/**************************************************************************/
bool Adafruit_INA2xx::conversionReady(void) {
Adafruit_I2CRegisterBits conversion_ready =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 1);
return conversion_ready.read();
}
/**************************************************************************/
/*!
@brief Reads the current alert polarity setting
@return The current bus alert polarity setting
*/
/**************************************************************************/
INA2XX_AlertPolarity Adafruit_INA2xx::getAlertPolarity(void) {
Adafruit_I2CRegisterBits alert_polarity =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 12);
return (INA2XX_AlertPolarity)alert_polarity.read();
}
/**************************************************************************/
/*!
@brief Sets Alert Polarity Bit
@param polarity
The polarity of the alert pin
*/
/**************************************************************************/
void Adafruit_INA2xx::setAlertPolarity(INA2XX_AlertPolarity polarity) {
Adafruit_I2CRegisterBits alert_polarity =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 12);
alert_polarity.write(polarity);
}
/**************************************************************************/
/*!
@brief Reads the current alert latch setting
@return The current bus alert latch setting
*/
/**************************************************************************/
INA2XX_AlertLatch Adafruit_INA2xx::getAlertLatch(void) {
Adafruit_I2CRegisterBits alert_latch =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 15);
return (INA2XX_AlertLatch)alert_latch.read();
}
/**************************************************************************/
/*!
@brief Sets Alert Latch Bit
@param state
The parameter which asserts the ALERT pin
*/
/**************************************************************************/
void Adafruit_INA2xx::setAlertLatch(INA2XX_AlertLatch state) {
Adafruit_I2CRegisterBits alert_latch =
Adafruit_I2CRegisterBits(Diag_Alert, 1, 15);
alert_latch.write(state);
}
/**************************************************************************/
/*!
@brief Reads the alert function flags from DIAG_ALRT
@return Bits that indicate alert flags
*/
/**************************************************************************/
uint16_t Adafruit_INA2xx::alertFunctionFlags(void) {
Adafruit_I2CRegisterBits alert_flags =
Adafruit_I2CRegisterBits(Diag_Alert, 12, 0);
return alert_flags.read();
}

213
Adafruit_INA2xx.h Normal file
View file

@ -0,0 +1,213 @@
/*!
* @file Adafruit_INA2xx.h
*
* I2C Driver base class for INA2xx Current and Power sensors
*
* This is a library for the Adafruit INA228 breakout:
* http://www.adafruit.com/products/5832
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
*
* BSD license (see license.txt)
*/
#ifndef _ADAFRUIT_INA2XX_H
#define _ADAFRUIT_INA2XX_H
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Wire.h>
#include "Arduino.h"
// Common registers for INA2xx family
#define INA2XX_REG_CONFIG 0x00 ///< Configuration register
#define INA2XX_REG_ADCCFG 0x01 ///< ADC configuration register
#define INA2XX_REG_SHUNTCAL 0x02 ///< Shunt calibration register
#define INA2XX_REG_VSHUNT 0x04 ///< Shunt voltage measurement register
#define INA2XX_REG_VBUS 0x05 ///< Bus voltage measurement register
#define INA2XX_REG_DIETEMP 0x06 ///< Temperature measurement register
#define INA2XX_REG_CURRENT 0x07 ///< Current result register
#define INA2XX_REG_POWER 0x08 ///< Power result register
#define INA2XX_REG_DIAGALRT 0x0B ///< Diagnostic flags and alert register
#define INA2XX_REG_SOVL 0x0C ///< Shunt overvoltage threshold register
#define INA2XX_REG_SUVL 0x0D ///< Shunt undervoltage threshold register
#define INA2XX_REG_BOVL 0x0E ///< Bus overvoltage threshold register
#define INA2XX_REG_BUVL 0x0F ///< Bus undervoltage threshold register
#define INA2XX_REG_TEMPLIMIT 0x10 ///< Temperature over-limit threshold register
#define INA2XX_REG_PWRLIMIT 0x11 ///< Power over-limit threshold register
#define INA2XX_REG_MFG_UID 0x3E ///< Manufacturer ID register
#define INA2XX_REG_DVC_UID 0x3F ///< Device ID and revision register
#define INA2XX_I2CADDR_DEFAULT 0x40 ///< INA2xx default i2c address
/**
* @brief Mode options.
*
* Allowed values for setMode.
*/
typedef enum _mode {
/**< SHUTDOWN: Minimize quiescient current and turn off current into the
device inputs. Set another mode to exit shutown mode **/
INA2XX_MODE_SHUTDOWN = 0x00,
/**< Triggered bus voltage, single shot **/
INA2XX_MODE_TRIG_BUS = 0x01,
/**< Triggered shunt voltage, single shot **/
INA2XX_MODE_TRIG_SHUNT = 0x02,
/**< Triggered shunt voltage and bus voltage, single shot **/
INA2XX_MODE_TRIG_BUS_SHUNT = 0x03,
/**< Triggered temperature, single shot **/
INA2XX_MODE_TRIG_TEMP = 0x04,
/**< Triggered temperature and bus voltage, single shot **/
INA2XX_MODE_TRIG_TEMP_BUS = 0x05,
/**< Triggered temperature and shunt voltage, single shot **/
INA2XX_MODE_TRIG_TEMP_SHUNT = 0x06,
/**< Triggered bus voltage, shunt voltage and temperature, single shot **/
INA2XX_MODE_TRIG_TEMP_BUS_SHUNT = 0x07,
/**< Shutdown **/
INA2XX_MODE_SHUTDOWN2 = 0x08,
/**< Continuous bus voltage only **/
INA2XX_MODE_CONT_BUS = 0x09,
/**< Continuous shunt voltage only **/
INA2XX_MODE_CONT_SHUNT = 0x0A,
/**< Continuous shunt and bus voltage **/
INA2XX_MODE_CONT_BUS_SHUNT = 0x0B,
/**< Continuous temperature only **/
INA2XX_MODE_CONT_TEMP = 0x0C,
/**< Continuous bus voltage and temperature **/
INA2XX_MODE_CONT_TEMP_BUS = 0x0D,
/**< Continuous temperature and shunt voltage **/
INA2XX_MODE_CONT_TEMP_SHUNT = 0x0E,
/**< Continuous bus voltage, shunt voltage and temperature **/
INA2XX_MODE_CONT_TEMP_BUS_SHUNT = 0x0F,
/**< TRIGGERED: Trigger a one-shot measurement of temp, current and bus
voltage. Set the TRIGGERED mode again to take a new measurement **/
INA2XX_MODE_TRIGGERED = INA2XX_MODE_TRIG_TEMP_BUS_SHUNT,
/**< CONTINUOUS: (Default) Continuously update the temp, current, bus
voltage and power registers with new measurements **/
INA2XX_MODE_CONTINUOUS = INA2XX_MODE_CONT_TEMP_BUS_SHUNT
} INA2XX_MeasurementMode;
/**
* @brief Conversion Time options.
*
* Allowed values for setCurrentConversionTime and setVoltageConversionTime.
*/
typedef enum _conversion_time {
INA2XX_TIME_50_us, ///< Measurement time: 50us
INA2XX_TIME_84_us, ///< Measurement time: 84us
INA2XX_TIME_150_us, ///< Measurement time: 150us
INA2XX_TIME_280_us, ///< Measurement time: 280us
INA2XX_TIME_540_us, ///< Measurement time: 540us
INA2XX_TIME_1052_us, ///< Measurement time: 1052us
INA2XX_TIME_2074_us, ///< Measurement time: 2074us
INA2XX_TIME_4120_us, ///< Measurement time: 4120us
} INA2XX_ConversionTime;
/**
* @brief Averaging Count options.
*
* Allowed values forsetAveragingCount.
*/
typedef enum _count {
INA2XX_COUNT_1, ///< Window size: 1 sample (Default)
INA2XX_COUNT_4, ///< Window size: 4 samples
INA2XX_COUNT_16, ///< Window size: 16 samples
INA2XX_COUNT_64, ///< Window size: 64 samples
INA2XX_COUNT_128, ///< Window size: 128 samples
INA2XX_COUNT_256, ///< Window size: 256 samples
INA2XX_COUNT_512, ///< Window size: 512 samples
INA2XX_COUNT_1024, ///< Window size: 1024 samples
} INA2XX_AveragingCount;
/**
* @brief Alert pin polarity options.
*
* Allowed values for setAlertPolarity.
*/
typedef enum _alert_polarity {
INA2XX_ALERT_POLARITY_NORMAL = 0x0, ///< Active high open-collector (Default)
INA2XX_ALERT_POLARITY_INVERTED = 0x1, ///< Active low open-collector
} INA2XX_AlertPolarity;
/**
* @brief Alert pin latch options.
*
* Allowed values for setAlertLatch.
*/
typedef enum _alert_latch {
INA2XX_ALERT_LATCH_ENABLED = 0x1, /**< Alert will latch until Mask/Enable
register is read **/
INA2XX_ALERT_LATCH_TRANSPARENT = 0x0, /**< Alert will reset when fault is
cleared **/
} INA2XX_AlertLatch;
/*!
* @brief Class that stores state and functions for interacting with
* INA2xx Current and Power Sensor
*/
class Adafruit_INA2xx {
public:
Adafruit_INA2xx();
virtual bool begin(uint8_t i2c_addr = INA2XX_I2CADDR_DEFAULT,
TwoWire* theWire = &Wire, bool skipReset = false);
virtual void reset(void);
virtual void setShunt(float shunt_res = 0.1, float max_current = 3.2);
void setADCRange(uint8_t);
uint8_t getADCRange(void);
virtual float readDieTemp(void);
virtual float readBusVoltage(void);
// Common INA interface:
float getBusVoltage_V(void);
float getShuntVoltage_mV(void);
float getCurrent_mA(void);
float getPower_mW(void);
//
virtual float readCurrent(void);
virtual float readShuntVoltage(void);
virtual float readPower(void);
void setMode(INA2XX_MeasurementMode mode);
INA2XX_MeasurementMode getMode(void);
bool conversionReady(void);
uint16_t alertFunctionFlags(void);
INA2XX_AlertLatch getAlertLatch(void);
void setAlertLatch(INA2XX_AlertLatch state);
INA2XX_AlertPolarity getAlertPolarity(void);
void setAlertPolarity(INA2XX_AlertPolarity polarity);
INA2XX_ConversionTime getCurrentConversionTime(void);
void setCurrentConversionTime(INA2XX_ConversionTime time);
INA2XX_ConversionTime getVoltageConversionTime(void);
void setVoltageConversionTime(INA2XX_ConversionTime time);
INA2XX_ConversionTime getTemperatureConversionTime(void);
void setTemperatureConversionTime(INA2XX_ConversionTime time);
INA2XX_AveragingCount getAveragingCount(void);
void setAveragingCount(INA2XX_AveragingCount count);
Adafruit_I2CRegister *Config, ///< BusIO Register for Config
*ADC_Config, ///< BusIO Register for ADC Config
*Diag_Alert; ///< BusIO Register for Diagnostic Alerts
protected:
virtual void _updateShuntCalRegister(
void); ///< Updates the shunt calibration register based on
///< device-specific calculations
float _shunt_res; ///< Shunt resistance value in ohms
float _current_lsb; ///< Current LSB value used for calculations
Adafruit_I2CDevice* i2c_dev; ///< I2C device interface
uint16_t _device_id; ///< Device ID for chip verification
};
#endif

View file

@ -1,9 +1,11 @@
Adafruit_INA228 [![Build Status](https://github.com/adafruit/Adafruit_INA228/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_INA228/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_INA228/html/index.html)
================
Adafruit_INA228
===============
[![Build Status](https://github.com/adafruit/Adafruit_INA228/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_INA228/actions)
[![Documentation](https://raw.githubusercontent.com/adafruit/ci-arduino/master/assets/doxygen_badge.svg)](https://adafruit.github.io/Adafruit_INA228/html/index.html)
This is the Adafruit INA228 Current and Power sensor library
Tested and works great with the [Adafruit INA228 Breakout Board](http://www.adafruit.com/products)
Tested and works great with the [Adafruit INA228 Breakout Board](https://www.adafruit.com/product/5832)
This chip uses I2C to communicate, 2 pins are required to interface
@ -16,3 +18,6 @@ BSD license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for "Adafruit INA228" and install the library.
Note: For INA237 and INA238 support, please use the separate [Adafruit INA237 and INA238 Library](https://github.com/adafruit/Adafruit_INA237_INA238)

View file

@ -5,20 +5,23 @@ Adafruit_INA228 ina228 = Adafruit_INA228();
void setup() {
Serial.begin(115200);
// Wait until serial port is opened
while (!Serial) { delay(10); }
while (!Serial) {
delay(10);
}
Serial.println("Adafruit INA228 Test");
if (!ina228.begin()) {
Serial.println("Couldn't find INA228 chip");
while (1);
while (1)
;
}
Serial.println("Found INA228 chip");
// we need to set the resistance (default 0.1 ohm) and our max expected current (no greater than 3.2A)
ina228.setShunt(0.1, 1.0);
// set shunt resistance and max current
ina228.setShunt(0.015, 10.0);
ina228.setAveragingCount(INA228_COUNT_16);
uint16_t counts[] = {1, 4, 16, 64, 128, 256, 512, 1024};
uint16_t counts[] = {1, 4, 16, 64, 128, 256, 512, 1024};
Serial.print("Averaging counts: ");
Serial.println(counts[ina228.getAveragingCount()]);
@ -26,63 +29,101 @@ void setup() {
ina228.setVoltageConversionTime(INA228_TIME_150_us);
Serial.print("Voltage conversion time: ");
switch (ina228.getVoltageConversionTime()) {
case INA228_TIME_50_us: Serial.print("50"); break;
case INA228_TIME_84_us: Serial.print("84"); break;
case INA228_TIME_150_us: Serial.print("150"); break;
case INA228_TIME_280_us: Serial.print("280"); break;
case INA228_TIME_1052_us: Serial.print("1052"); break;
case INA228_TIME_2074_us: Serial.print("2074"); break;
case INA228_TIME_4120_us: Serial.print("4120"); break;
case INA228_TIME_50_us:
Serial.print("50");
break;
case INA228_TIME_84_us:
Serial.print("84");
break;
case INA228_TIME_150_us:
Serial.print("150");
break;
case INA228_TIME_280_us:
Serial.print("280");
break;
case INA228_TIME_540_us:
Serial.print("540");
break;
case INA228_TIME_1052_us:
Serial.print("1052");
break;
case INA228_TIME_2074_us:
Serial.print("2074");
break;
case INA228_TIME_4120_us:
Serial.print("4120");
break;
}
Serial.println(" uS");
ina228.setCurrentConversionTime(INA228_TIME_280_us);
Serial.print("Current conversion time: ");
switch (ina228.getCurrentConversionTime()) {
case INA228_TIME_50_us: Serial.print("50"); break;
case INA228_TIME_84_us: Serial.print("84"); break;
case INA228_TIME_150_us: Serial.print("150"); break;
case INA228_TIME_280_us: Serial.print("280"); break;
case INA228_TIME_1052_us: Serial.print("1052"); break;
case INA228_TIME_2074_us: Serial.print("2074"); break;
case INA228_TIME_4120_us: Serial.print("4120"); break;
case INA228_TIME_50_us:
Serial.print("50");
break;
case INA228_TIME_84_us:
Serial.print("84");
break;
case INA228_TIME_150_us:
Serial.print("150");
break;
case INA228_TIME_280_us:
Serial.print("280");
break;
case INA228_TIME_540_us:
Serial.print("540");
break;
case INA228_TIME_1052_us:
Serial.print("1052");
break;
case INA228_TIME_2074_us:
Serial.print("2074");
break;
case INA228_TIME_4120_us:
Serial.print("4120");
break;
}
Serial.println(" uS");
// default polarity for the alert is low on ready, but
// it can be inverted!
//ina228.setAlertPolarity(1);
// ina228.setAlertPolarity(1);
}
void loop() {
// by default the sensor does continuous reading, but
// we can set to triggered mode. to do that, we have to set
// we can set to triggered mode. to do that, we have to set
// the mode to trigger a new reading, then wait for a conversion
// either by checking the ALERT pin or reading the ready register
//ina228.setMode(INA228_MODE_TRIGGERED);
//while (!ina228.conversionReady())
// ina228.setMode(INA228_MODE_TRIGGERED);
// while (!ina228.conversionReady())
// delay(1);
Serial.print("Current: ");
Serial.print(ina228.readCurrent());
Serial.print(ina228.getCurrent_mA());
Serial.println(" mA");
Serial.print("Bus Voltage: ");
Serial.print(ina228.readBusVoltage());
Serial.println(" mV");
Serial.print(ina228.getBusVoltage_V());
Serial.println(" V");
Serial.print("Shunt Voltage: ");
Serial.print(ina228.readShuntVoltage());
Serial.print(ina228.getShuntVoltage_mV());
Serial.println(" mV");
Serial.print("Power: ");
Serial.print(ina228.readPower());
Serial.print(ina228.getPower_mW());
Serial.println(" mW");
Serial.print("Energy: ");
Serial.print(ina228.readEnergy());
Serial.println(" J");
Serial.print("Charge: ");
Serial.print(ina228.readCharge());
Serial.println(" C");
Serial.print("Temperature: ");
Serial.print(ina228.readDieTemp());

80
keywords.txt Normal file
View file

@ -0,0 +1,80 @@
#######################################
# Syntax Coloring Map for Adafruit_INA228 Library
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
Adafruit_INA2xx KEYWORD1
Adafruit_INA228 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
reset KEYWORD2
setShunt KEYWORD2
setADCRange KEYWORD2
getADCRange KEYWORD2
readDieTemp KEYWORD2
readCurrent KEYWORD2
readBusVoltage KEYWORD2
readShuntVoltage KEYWORD2
readPower KEYWORD2
readEnergy KEYWORD2
readCharge KEYWORD2
setMode KEYWORD2
getMode KEYWORD2
conversionReady KEYWORD2
resetAccumulators KEYWORD2
getAlertType KEYWORD2
setAlertType KEYWORD2
getBusVoltage_V KEYWORD2
getShuntVoltage_mV KEYWORD2
getCurrent_mA KEYWORD2
getPower_mW KEYWORD2
getCurrentConversionTime KEYWORD2
setCurrentConversionTime KEYWORD2
getVoltageConversionTime KEYWORD2
setVoltageConversionTime KEYWORD2
getTemperatureConversionTime KEYWORD2
setTemperatureConversionTime KEYWORD2
getAveragingCount KEYWORD2
setAveragingCount KEYWORD2
getAlertLatch KEYWORD2
setAlertLatch KEYWORD2
getAlertPolarity KEYWORD2
setAlertPolarity KEYWORD2
alertFunctionFlags KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
INA228_I2CADDR_DEFAULT LITERAL1
INA228_DEVICE_ID LITERAL1
INA2XX_MODE_SHUTDOWN LITERAL1
INA2XX_MODE_TRIGGERED LITERAL1
INA2XX_MODE_CONTINUOUS LITERAL1
INA2XX_TIME_50_us LITERAL1
INA2XX_TIME_84_us LITERAL1
INA2XX_TIME_150_us LITERAL1
INA2XX_TIME_280_us LITERAL1
INA2XX_TIME_540_us LITERAL1
INA2XX_TIME_1052_us LITERAL1
INA2XX_TIME_2074_us LITERAL1
INA2XX_TIME_4120_us LITERAL1
INA2XX_COUNT_1 LITERAL1
INA2XX_COUNT_4 LITERAL1
INA2XX_COUNT_16 LITERAL1
INA2XX_COUNT_64 LITERAL1
INA2XX_COUNT_128 LITERAL1
INA2XX_COUNT_256 LITERAL1
INA2XX_COUNT_512 LITERAL1
INA2XX_COUNT_1024 LITERAL1
INA2XX_ALERT_POLARITY_NORMAL LITERAL1
INA2XX_ALERT_POLARITY_INVERTED LITERAL1
INA2XX_ALERT_LATCH_ENABLED LITERAL1
INA2XX_ALERT_LATCH_TRANSPARENT LITERAL1

View file

@ -1,5 +1,5 @@
name=Adafruit INA228 Library
version=1.0.0
version=3.0.0
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the INA228 sensors in the Adafruit shop