17 #ifndef _LIB_ADAFRUIT_INA219_ 18 #define _LIB_ADAFRUIT_INA219_ 21 #include <Adafruit_BusIO_Register.h> 22 #include <Adafruit_I2CDevice.h> 37 #define INA219_CALC_ADDRESS(INA_ADDR0, INA_ADDR1) \ 38 (0x40 | (INA_ADDR0 != 0 ? 0x01 : 0x00) | (INA_ADDR1 != 0 ? 0x04 : 0x00)) 41 #define INA219_ADDRESS (0x40) // 1000000 (A0+A1=GND) 44 #define INA219_READ (0x01) 51 #define INA219_REG_CONFIG (0x00) 54 #define INA219_CONFIG_RESET (0x8000) // Reset Bit 57 #define INA219_CONFIG_BVOLTAGERANGE_MASK (0x2000) // Bus Voltage Range Mask 61 INA219_CONFIG_BVOLTAGERANGE_16V = (0x0000),
62 INA219_CONFIG_BVOLTAGERANGE_32V = (0x2000),
66 #define INA219_CONFIG_GAIN_MASK (0x1800) // Gain Mask 70 INA219_CONFIG_GAIN_1_40MV = (0x0000),
71 INA219_CONFIG_GAIN_2_80MV = (0x0800),
72 INA219_CONFIG_GAIN_4_160MV = (0x1000),
73 INA219_CONFIG_GAIN_8_320MV = (0x1800),
77 #define INA219_CONFIG_BADCRES_MASK (0x0780) 81 INA219_CONFIG_BADCRES_9BIT = (0x0000),
82 INA219_CONFIG_BADCRES_10BIT = (0x0080),
83 INA219_CONFIG_BADCRES_11BIT = (0x0100),
84 INA219_CONFIG_BADCRES_12BIT = (0x0180),
85 INA219_CONFIG_BADCRES_12BIT_2S_1060US =
87 INA219_CONFIG_BADCRES_12BIT_4S_2130US =
89 INA219_CONFIG_BADCRES_12BIT_8S_4260US =
91 INA219_CONFIG_BADCRES_12BIT_16S_8510US =
93 INA219_CONFIG_BADCRES_12BIT_32S_17MS =
95 INA219_CONFIG_BADCRES_12BIT_64S_34MS =
97 INA219_CONFIG_BADCRES_12BIT_128S_69MS =
103 #define INA219_CONFIG_SADCRES_MASK \ 104 (0x0078) // Shunt ADC Resolution and Averaging Mask 108 INA219_CONFIG_SADCRES_9BIT_1S_84US = (0x0000),
109 INA219_CONFIG_SADCRES_10BIT_1S_148US = (0x0008),
110 INA219_CONFIG_SADCRES_11BIT_1S_276US = (0x0010),
111 INA219_CONFIG_SADCRES_12BIT_1S_532US = (0x0018),
112 INA219_CONFIG_SADCRES_12BIT_2S_1060US =
114 INA219_CONFIG_SADCRES_12BIT_4S_2130US =
116 INA219_CONFIG_SADCRES_12BIT_8S_4260US =
118 INA219_CONFIG_SADCRES_12BIT_16S_8510US =
120 INA219_CONFIG_SADCRES_12BIT_32S_17MS =
122 INA219_CONFIG_SADCRES_12BIT_64S_34MS =
124 INA219_CONFIG_SADCRES_12BIT_128S_69MS =
129 #define INA219_CONFIG_MODE_MASK (0x0007) // Operating Mode Mask 146 #define INA219_REG_SHUNTVOLTAGE (0x01) 149 #define INA219_REG_BUSVOLTAGE (0x02) 152 #define INA219_REG_POWER (0x03) 155 #define INA219_REG_CURRENT (0x04) 158 #define INA219_REG_CALIBRATION (0x05) 168 bool begin(TwoWire *theWire = &Wire);
180 Adafruit_I2CDevice *i2c_dev = NULL;
184 uint8_t ina219_i2caddr = -1;
185 uint32_t ina219_calValue;
188 uint32_t ina219_currentDivider_mA;
189 float ina219_powerMultiplier_mW;
192 int16_t getBusVoltage_raw();
193 int16_t getShuntVoltage_raw();
194 int16_t getCurrent_raw();
195 int16_t getPower_raw();
void powerSave(bool on)
Set power save mode according to parameters.
Definition: Adafruit_INA219.cpp:280
float getCurrent_mA()
Gets the current value in mA, taking into account the config settings and current LSB...
Definition: Adafruit_INA219.cpp:168
float getShuntVoltage_mV()
Gets the shunt voltage in mV (so +-327mV)
Definition: Adafruit_INA219.cpp:148
bool begin(TwoWire *theWire=&Wire)
Sets up the HW (defaults to 32V and 2A for calibration values)
Definition: Adafruit_INA219.cpp:53
Definition: Adafruit_INA219.h:135
bool success()
Provides the the underlying return value from the last operation called on the device.
Definition: Adafruit_INA219.cpp:486
Definition: Adafruit_INA219.h:139
Definition: Adafruit_INA219.h:133
void setCalibration_32V_1A()
Configures to INA219 to be able to measure up to 32V and 1A of current. Each unit of current correspo...
Definition: Adafruit_INA219.cpp:300
float getPower_mW()
Gets the power value in mW, taking into account the config settings and current LSB.
Definition: Adafruit_INA219.cpp:179
Definition: Adafruit_INA219.h:140
float getBusVoltage_V()
Gets the bus voltage in volts.
Definition: Adafruit_INA219.cpp:158
void setCalibration_16V_400mA()
set device to alibration which uses the highest precision for current measurement (0...
Definition: Adafruit_INA219.cpp:391
Class that stores state and functions for interacting with INA219 current/power monitor IC...
Definition: Adafruit_INA219.h:164
Definition: Adafruit_INA219.h:134
~Adafruit_INA219()
INA219 class destructor.
Definition: Adafruit_INA219.cpp:46
Definition: Adafruit_INA219.h:136
Definition: Adafruit_INA219.h:138
Definition: Adafruit_INA219.h:141
Adafruit_INA219(uint8_t addr=INA219_ADDRESS)
Instantiates a new INA219 class.
Definition: Adafruit_INA219.cpp:37
void setCalibration_32V_2A()
Configures to INA219 to be able to measure up to 32V and 2A of current. Each unit of current correspo...
Definition: Adafruit_INA219.cpp:192
#define INA219_ADDRESS
Definition: Adafruit_INA219.h:41