INA228 power and energy monitor

The TI INA228 measures current, bus voltage and power to 20 bits through a 15 milliohm shunt, and adds up energy and charge as it goes.

Aliases: Adafruit INA228, INA228 module, coulomb counter, energy meter. It is the monitor for a battery's state of charge or a project's energy use over a day: the chip keeps the running totals itself.

Pins

Pin What it does
VCC, GND Supply, 2.7 to 5.5 V.
SCL, SDA I2C. The board carries the pull-ups.
ALERT Pulls low on a conversion when the conversion-ready alert is on.
VBUS The bus voltage input: tie it to the load's supply side.
IN+, IN- The two ends of the 15 milliohm shunt, in series with the load.

Properties

address, 0x40 to 0x4F. Nothing to drag: the current is the circuit's own.

Reading it on an Arduino

With Adafruit's library, which Mokxi ships as Adafruit_INA228.h:

#include <Adafruit_INA228.h>
Adafruit_INA228 ina228;

void setup() {
  Serial.begin(9600);
  ina228.begin();
  ina228.setShunt(0.015, 10.0);
}

void loop() {
  Serial.print(ina228.readCurrent());
  Serial.print(" mA  ");
  Serial.print(ina228.readEnergy());
  Serial.println(" J");
  delay(1000);
}

How it talks

SHUNT_CAL (0x02) sets the current LSB: 13107.2e6 x LSB x R. The shunt (0x04), bus (0x05) and current (0x07) are 20-bit fields in three bytes, the power (0x08) 24 bits, and the energy (0x09) and charge (0x0A) 40 bits that accumulate with each conversion until RSTACC clears them. DIAG_ALRT (0x0B) has the conversion ready flag; the device ID at 0x3F reads 0x2281.

What it does not model

The limit comparisons and their alerts, the shunt temperature compensation, and noise.

Common mistakes

Leaving VBUS unconnected: power and energy read zero. Forgetting setShunt() with the board's real shunt: the current is scaled by the wrong resistance.