high dynamic range current/voltage sensors (ina228) working


Well-known member
I have two ina228 boards (Adafruit) connected to i2c port 0 on a teensy 3.6 (4.1 would work as well).
I have written a datalogger for them. I can get by with 100ms acquistion time so I just build up buffers larger than 512
and write them out.
I output to CSV file on the on-board microSD.
I have built a number of different displays, all of which are battery powered (including ws2812 strips and up to 3x3 64by64 led matrix)
so I am interested in actually seeing battery life.

libraries necessary:
#include <CSV_Parser.h>
#include <SD.h>
#include <SPI.h>
#include <Adafruit_INA228.h>

Documentation includes the ina228 data sheet and not much else is needed.
The ina228 have hard-wired pullups that are 9.8k I have two in parallel at
addresses 0x40 and 0x41. Any more than 2 would require cutting etch to the 9.8k pullup resistors
on additional boards.
sure there are a lot of details but its simple:
The Adafruit_INA228.h has some examples as does the CSV_Parser.h library

The ina228 board has three solder jumpers on the back (none connected at default)
I bridge the top jumper so that the V+ is connected to VBUS.
You can connect high side or low side. Default is high side measuring meaning:
V+ is where your power supply goes can go up to 85V DC.
V- is where your load is connected.
Jumping VBUS to V+ allows the ina228 to measure voltage. Note: to measure voltage the ground of your power supply/load
must be connected to the GND of the ina228.

VIN is the input voltage for the i2c bus (for teensy 3.3v) Both are pulled up on board (see later).

The example programs for reading voltage/current etc. need to be changed to reflect the Shunt resistor is .015 ohms on the Adafruit board.

I have two ina228 connected to the MPU i2c bus. Addresses are 0x40, 0x41
No bridge for board #1
I bridged the A0 tab on back of board #1

I define:
#define NUM_INA228 2
#define INA228_I2C_ADDRESS_0 0x40
#define INA228_I2C_ADDRESS_1 0x41

I create the two instances:
Adafruit_INA228 ina228[NUM_INA228 ] =
{ Adafruit_INA228(), Adafruit_INA228() };

I setup each class:

I then call (as examples):
voltage0 = ina228[0].readBusVoltage();
current0 = ina228[0].readBusCurrent();
voltage1 = ina228[1].readBusVoltage();
current1 = ina228[1].readBusCurrent();

I also note that both boards have hard wired SCL/SDA pullup resistors
each at 9.8k ohm.
Since there are two in parallel, this drops the SCL/SDA pullup to 4.9K.
Since I have no long wires connecting the ina228 to the MPU, either works.

I do note that a more commonly accepted i2c pullup is around 4.7K so I am not sure why Adafruit chose 9.8k.

Adding more than 2 ina228 in parallel would require any additional boards to have the pullup resistors removed. There are four 10k resistors on board. The two closest to the shunt resistor are the pullups for SCL and SDA respectively.