47 _i2cAddress(i2cAddress), _shuntResistor(shuntResistor)
114 uint16_t shuntVoltageReg;
115 uint16_t busVoltageReg;
127 if (_i2cStatus != 0) {
return false; }
131 if (_i2cStatus != 0) {
return false; }
134 if (shuntVoltageReg & 0x8000) {
143 if (busVoltageReg & 0x01) {
193 Wire.beginTransmission(_i2cAddress);
195 _i2cStatus = Wire.endTransmission(
false);
196 (void)Wire.requestFrom(_i2cAddress, (uint8_t)2);
197 return (Wire.read() << 8) | Wire.read();
211 const uint8_t buffer[3] = { reg, (uint8_t)(val >> 8), (uint8_t)(val & 0xff) };
213 Wire.beginTransmission(_i2cAddress);
214 Wire.write(buffer,
sizeof(buffer));
215 _i2cStatus = (Wire.endTransmission() == 0) ?
true :
false;
241 serial->println(F(
"INA219 registers:"));
243 serial->print(F(
" 00 CONFIG: 0x"));
245 serial->print(F(
" 01 SHUNTVOLTAGE: 0x"));
247 serial->print(F(
" 02 BUSVOLTAGE: 0x"));
249 serial->print(F(
" 03 POWER: 0x"));
251 serial->print(F(
" 04 CURRENT: 0x"));
253 serial->print(F(
" 05 CALIBRATION: 0x"));
#define INA219_REG_POWER
Power register.
bool available
Successful conversion.
void registerWrite(uint8_t reg, uint16_t val)
Write to INA219 register.
bool powerUp()
Power-up INA219.
#define REG_CONFIG_VALUE
Default config register value.
bool read()
Read voltage and current from INA219.
float current
Current in mA.
uint8_t getI2CStatus()
Return status of the last I2C write, returned by Wire endTransfer()
INA219 voltage and current sensor library for Arduino.
#define INA219_REG_CALIBRATION
Calibration register.
float busVoltage
Bus voltage in V.
#define INA219_REG_CONFIG
Config register.
#define INA219_REG_CURRENT
Current register.
bool begin()
Initialize INA219.
#define INA219_REG_SHUNTVOLTAGE
Shunt/voltage register.
uint16_t registerRead(uint8_t reg)
Read from INA219 register.
void dumpRegisters(Stream *serial)
Print I2C registers on serial port.
INA219(uint8_t i2cAddress=INA219_I2C_ADDRESS, float shuntResistor=INA219_SHUNT_RESISTOR)
INA219 constructor.
float shuntVoltage
Shunt voltage in mV.
#define INA219_REG_BUSVOLTAGE
Bus voltage register.
bool powerDown()
Set INA219 in power-down mode.