flav1972 / ArduinoINA219

An Arduino library for the INA219 I2C current monitor
17 stars 16 forks source link

TI INA219 hi-side i2c current/power monitor Library for Arduino

Authors

John De Cristofaro

Jukka-Pekka Sarjanen

gandy92

Flavius Bindea

Tests and fonctionalities

Known bugs:

Dependencies:

Usage

Basic

Look at ina219_test exemple sketch. This example works out of the box for Adafruit's INA219 Breakout.

Include defintions and define needed object:

#include <Wire.h>
#include <INA219.h>

INA219 monitor;

In the setup() function initialise the INA219:

monitor.begin();

Then in the loop() function make calls to different functions that are returning the values:

  Serial.print("raw shunt voltage: ");
  Serial.println(monitor.shuntVoltageRaw());

  Serial.print("raw bus voltage:   ");
  Serial.println(monitor.busVoltageRaw());

  Serial.println("--");

  Serial.print("shunt voltage: ");
  Serial.print(monitor.shuntVoltage() * 1000, 4);
  Serial.println(" mV");

  Serial.print("shunt current: ");
  Serial.print(monitor.shuntCurrent() * 1000, 4);
  Serial.println(" mA");

  Serial.print("bus voltage:   ");
  Serial.print(monitor.busVoltage(), 4);
  Serial.println(" V");

  Serial.print("bus power:     ");
  Serial.print(monitor.busPower() * 1000, 4);
  Serial.println(" mW");

Enhanced setup

If you want to use a different setup or if you do not use the Adafruit's breakout then in the setup() function you need to call configure() and calibrate().

An exemple is in ina219_test_nondefault.

Extract of the setup() function:

  monitor.begin();

  // setting up our configuration
  monitor.configure(INA219::RANGE_16V, INA219::GAIN_2_80MV, INA219::ADC_64SAMP, INA219::ADC_64SAMP, INA219::CONT_SH_BUS);

  // calibrate with our values
  monitor.calibrate(SHUNT_R, SHUNT_MAX_V, BUS_MAX_V, MAX_CURRENT);

functions

All the functions are well comented in INA219.h and INA219.cpp

Licence

MIT license