33 #ifndef ERRIEZ_INA219_H_ 34 #define ERRIEZ_INA219_H_ 39 #define INA219_I2C_ADDRESS 0x40 40 #define INA219_SHUNT_RESISTOR 0.1 43 #define INA219_REG_CONFIG 0x00 44 #define INA219_REG_SHUNTVOLTAGE 0x01 45 #define INA219_REG_BUSVOLTAGE 0x02 46 #define INA219_REG_POWER 0x03 47 #define INA219_REG_CURRENT 0x04 48 #define INA219_REG_CALIBRATION 0x05 51 #define INA219_CONFIG_RST 15 53 #define INA219_CONFIG_BRNG 13 54 #define INA219_CONFIG_BRNG_16V (0 << 13) 55 #define INA219_CONFIG_BRNG_32V (1 << 13) 57 #define INA219_CONFIG_GAIN_MASK (3 << 12) 58 #define INA219_CONFIG_GAIN_1 (0 << 12) 59 #define INA219_CONFIG_GAIN_2 (1 << 12) 60 #define INA219_CONFIG_GAIN_4 (2 << 12) 61 #define INA219_CONFIG_GAIN_8 (3 << 12) 63 #define INA219_CONFIG_BADC_MASK 0x0780 64 #define INA219_CONFIG_BADC(adc) ((adc & INA219_CONFIG_BADC_MASK) << 7) 66 #define INA219_CONFIG_SADC_MASK 0x0078 67 #define INA219_CONFIG_SADC(adc) ((adc & INA219_CONFIG_BADC_MASK) << 3) 69 #define INA219_CONFIG_xADC_9B 0 70 #define INA219_CONFIG_xADC_10B 1 71 #define INA219_CONFIG_xADC_11B 2 72 #define INA219_CONFIG_xADC_12B 3 73 #define INA219_CONFIG_xADC_2S 9 74 #define INA219_CONFIG_xADC_4S 10 75 #define INA219_CONFIG_xADC_8S 11 76 #define INA219_CONFIG_xADC_16S 12 77 #define INA219_CONFIG_xADC_32S 13 78 #define INA219_CONFIG_xADC_64S 14 79 #define INA219_CONFIG_xADC_128S 15 81 #define INA219_CONFIG_MODE_MASK 0x0007 82 #define INA219_CONFIG_MODE(mode) ((mode & INA219_CONFIG_MODE_MASK) << 0) 83 #define INA219_CONFIG_MODE_POWER_DOWN 0 84 #define INA219_CONFIG_MODE_SHUNT_TRG 1 85 #define INA219_CONFIG_MODE_BUS_TRG 2 86 #define INA219_CONFIG_MODE_SHUNT_BUS_TRG 3 87 #define INA219_CONFIG_MODE_ADC_OFF 4 88 #define INA219_CONFIG_MODE_SHUNT_CNT 5 89 #define INA219_CONFIG_MODE_BUS_CNT 6 90 #define INA219_CONFIG_MODE_SHUNT_BUS_CNT 7 100 #define REG_CONFIG_VALUE 0x399F 138 float _shuntResistor;
143 #endif // ERRIEZ_INA219_H_ #define INA219_SHUNT_RESISTOR
Default shunt resistor in Ohm.
#define INA219_I2C_ADDRESS
Default I2C address.
bool available
Successful conversion.
void registerWrite(uint8_t reg, uint16_t val)
Write to INA219 register.
bool powerUp()
Power-up INA219.
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()
float busVoltage
Bus voltage in V.
bool begin()
Initialize INA219.
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.
bool powerDown()
Set INA219 in power-down mode.