Skip to content

Repository files navigation

Root4root_INA219

Library for Texas Instruments INA219 IC - Bidirectional Current/Power Monitor

Quick Example:

#include<Arduino.h>
#include"Root4root_INA219.h"
Root4root_INA219 ina219; //0x40 addressvoidsetup() {
Serial.begin(9600);
ina219.begin();
}
voidloop() {
float busvoltage = 0;
float current_mA = 0;
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
Serial.println(busvoltage);
Serial.println(current_mA);
delay(1000);
}

Advanced Usage:

#include<Arduino.h>
#include"Root4root_INA219.h"
Root4root_INA219 ina219(0x40);
voidsetup() {
//Max expected current 20A with 10 milliOhms shunt,//calculates calibration register value. 2000, 100 by default.
ina219.begin(20000, 10);
//Change configuration register to fit your requirements.//Check Readme for more options, or read .h file
ina219.changeConfig(INA219_CONFIG_SHUNT_ADC_RESOLUTION_12BIT_8S_4260US |
INA219_CONFIG_BUS_VOLTAGE_RANGE_16V,
INA219_CONFIG_SHUNT_ADC_RESOLUTION_MASK |
INA219_CONFIG_BUS_VOLTAGE_RANGE_MASK);
//Same as above://ina219.changeConfig(0x0058, 0x2078);
Serial.begin(9600);
}
voidloop() {
Serial.println(ina219.getBusVoltage_V());
Serial.println(ina219.getCurrent_mA());
Serial.println("--------------------");
//ina219.getBusVoltage_mV();//ina219.getPower_mW();//ina219.getShuntVoltage_mV();delay(1000);
}

Available Methods:

//ConstructorRoot4root_INA219(uint8_t addr = INA219_ADDRESS, TwoWire *theWire = &Wire);
//DEFAULT_MAX_EXPECTED_CURRENT 2000 mA//DEFAULT_SHUNT_RESISTOR 100 mOhmvoidbegin(uint16_t expected = DEFAULT_MAX_EXPECTED_CURRENT, uint8_t rshunt = DEFAULT_SHUNT_RESISTOR);
voidsetCalibration(uint16_t expected, uint8_t rshunt);
voidchangeConfig(uint16_t value, uint16_t mask); //See header file to findout config and masks constants.uint16_tgetBusVoltage_mV();
floatgetBusVoltage_V();
floatgetShuntVoltage_mV();
int16_tgetShuntVoltage_raw(); //raw, shunt voltage register valuefloatgetCurrent_mA();
int16_tgetCurrent_raw(); //raw, current register value (not in Amps)floatgetPower_mW();
int16_tgetPower_raw(); //raw, power register value (not in Watts)voidpowerSave(bool on);
voidreset();
voidtrigger(); //For trigged measure mode//!! Following methods are mainly used for testing purpouses:voidreadRegister(uint8_t reg, uint16_t *value);
voidwriteRegister(uint8_t reg, uint16_t value);

License:

MIT

Author:

Paul aka root4root <root4root at gmail dot com>
Any comments/suggestions are welcomed.

About

Arduino Library for Texas Instruments INA219 IC

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages