Ina 219
Ina 219
Ina 219
Guide Contents 2
Overview 3
Why the High Side? 3
How does it work? 3
Assembly 5
Addressing the Boards 5
Wiring 7
Connect to the microprocessor 7
Connect to the circuit 8
Arduino Code 11
Install the Library 11
Load the Example 11
Run it! 12
Customize it 12
Library Reference 13
Construction and Initialization Functions: 13
Sensor Reading Functions: 13
Python & CircuitPython 15
CircuitPython Microcontroller Wiring 15
Python Computer Wiring 15
CircuitPython Installation of INA219 Library 15
Python Installation of INA219 Library 16
CircuitPython & Python Usage 16
Full Example Code 17
Python Docs 18
Downloads 19
Datasheets & Files 19
Schematic & Fabrication Print 19
Since the voltage drop across the resistor is proportional to the current draw, this means that the ground reference will
change with varying current. Having a shifting ground reference can cause problems for many circuits.
The INA219B chip is much smarter - it can handle high side current measuring, up to +26VDC, even though it is
powered with 3 or 5V. It will also report back that high side voltage, which is great for tracking battery life or solar
panels.
Note that when switching inductive loads, the instantaneous voltage levels may greatly exceed steady-state
levels due to inductive kickback. Chip damage can occur if you do not take precautions to protect against
On R3 and later Arduinos, you can connect to the new dedicated SDA & SCL pins next to the AREF pin. On pre-R3
Megas, SDA & SCL are on pins 20 & 21.
Be careful inserting noisy loads that can cause a sharp current draw, such as DC motors, since they can
cause problems on the power lines and may cause the INA219 to reset, etc. When using a DC motor or a
similar device, be sure to include a large capacitor to decouple the motor from the power supply and use a
snubber diode to protect against inductive spikes.
https://adafru.it/rMD
https://adafru.it/rMD
Expand the .zip file to the Libraries folder in your Arduino Sketchbook folder (If you don't know where this is,
open File->Preferences in the IDE and it will tell you the location of your sketchbook folder).
Rename the folder to Adafruit_INA219
Close all instances of the IDE, then re-open one, so that the IDE will recognize the new library.
Customize it
You can adapt, expand or modify the example code to suit your project requirements. For a detailed description of the
available library functions, see the Library Reference on the next page:
Constructs an instance of the Adafruit_INA219. If no address is specified, the default address (0x40) is used. If more
than one INA219 module is connected, it should be addressed as shown on the Assembly page and the configured
address passed to the constuctor.
void begin(void);
Initializes I2C communication with the Adafruit_INA219 device using the default configuration values.
Example:
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219_A;
Adafruit_INA219 ina219_B(0x41);
void setup(void)
{
ina219_A.begin(); // Initialize first board (default address 0x40)
ina219_B.begin(); // Initialize second board with the address 0x41
}
Reads the voltage between GND and V-. This is the total voltage seen by the circuit under test. (Supply voltage -
shunt voltage).
float getShuntVoltage_mV(void);
Reads the voltage between V- and V+. This is the measured voltage drop across the shunt resistor.
float getCurrent_mA(void);
Reads the current, derived via Ohms Law from the measured shunt voltage.
Example:
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python
thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library (https://adafru.it/BSN).
In addition connect some load to measure the current from in series to the sensor's Vin- and Vin+ pins as mentioned
on the wiring page (https://adafru.it/BHR).
First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/tBa) for your board.
Remember for non-express boards like the Trinket M0, Gemma M0, and Feather/Metro M0 basic you'll need to
manually install the necessary libraries from the bundle:
adafruit_ina219.mpy
adafruit_bus_device
Before continuing make sure your board's lib folder or root filesystem has
the adafruit_ina219.mpy, and adafruit_bus_device files and folders copied over.
Next connect to the board's serial REPL (https://adafru.it/Awz) so you are at the CircuitPython >>> prompt.
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use
CircuitPython on Python 2.x, it isn't supported!
import board
import busio
import adafruit_ina219
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_ina219.INA219(i2c)
Now you're ready to read values from the sensor using any of these functions:
Here's a full example to print the voltage and current every second. Save this as code.py on your board's filesystem
and check the output from the serial REPL.
import time
import adafruit_ina219
ina219 = adafruit_ina219.INA219(i2c_bus)
print("ina219 test")
while True:
print("Bus Voltage: {} V".format(ina219.bus_voltage))
print("Shunt Voltage: {} mV".format(ina219.shunt_voltage / 1000))
print("Load Voltage: {} V".format(ina219.bus_voltage + ina219.shunt_voltage))
print("Current: {} mA".format(ina219.current))
print("")
time.sleep(2)