Using the INA3221 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_INA3221 library, and running the provided example code.
You may find that using DC jacks with terminal blocks to interface between your power supply and load (device) will make interfacing with the INA3221 a little easier.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout using the STEMMA QT connector with a power supply and device (load) connected to channel 1. You can use the same power supply and load wiring for the additional two channels (power supply to + and load to -):
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
- Power supply GND to load GND (black wire)
- Power supply positive to breakout 1+ (red wire)
- Load positive to breakout 1- (orange wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
- Power supply GND to load GND (black wire)
- Power supply positive to breakout 1+ (red wire)
- Load positive to breakout 1- (orange wire)
Library Installation
You can install the Adafruit_INA3221 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_INA3221, and select the Adafruit INA3221 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
If the dependencies are already installed, make sure you update them through the Arduino Library Manager before loading the example!
#include "Adafruit_INA3221.h" #include <Wire.h> // Create an INA3221 object Adafruit_INA3221 ina3221; void setup() { Serial.begin(115200); while (!Serial) delay(10); // Wait for serial port to connect on some boards Serial.println("Adafruit INA3221 simple test"); // Initialize the INA3221 if (!ina3221.begin(0x40, &Wire)) { // can use other I2C addresses or buses Serial.println("Failed to find INA3221 chip"); while (1) delay(10); } Serial.println("INA3221 Found!"); ina3221.setAveragingMode(INA3221_AVG_16_SAMPLES); // Set shunt resistances for all channels to 0.05 ohms for (uint8_t i = 0; i < 3; i++) { ina3221.setShuntResistance(i, 0.05); } // Set a power valid alert to tell us if ALL channels are between the two // limits: ina3221.setPowerValidLimits(3.0 /* lower limit */, 15.0 /* upper limit */); } void loop() { // Display voltage and current (in mA) for all three channels for (uint8_t i = 0; i < 3; i++) { float voltage = ina3221.getBusVoltage(i); float current = ina3221.getCurrentAmps(i) * 1000; // Convert to mA Serial.print("Channel "); Serial.print(i); Serial.print(": Voltage = "); Serial.print(voltage, 2); Serial.print(" V, Current = "); Serial.print(current, 2); Serial.println(" mA"); } Serial.println(); // Delay for 250ms before the next reading delay(250); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. After the INA3221 is recognized over I2C, you'll see the voltage and current readings for all three channels print to the Serial Monitor every 250 milliseconds. In the screenshot below, a QT Py CH32V203 running a NeoPixel swirl example was connected to channel 0 and a 9V guitar pedal was connected to channel 1. Nothing was connected to channel 2.
Text editor powered by tinymce.