Files
OpenMQTT-Gateway/lib/Arduino-INA226/INA226_alert/INA226_alert.ino
T

68 lines
1.7 KiB
Arduino

/*
INA226 Bi-directional Current/Power Monitor. Alert Example.
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/cyfrowy-czujnik-pradu-mocy-ina226.html
GIT: https://github.com/jarzebski/Arduino-INA226
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
*/
#include <Wire.h>
#include <INA226.h>
INA226 ina;
void setup()
{
Serial.begin(115200);
Serial.println("Initialize INA226");
Serial.println("-----------------------------------------------");
// Default INA226 address is 0x40
ina.begin();
// Configure INA226
ina.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
// Calibrate INA226. Rshunt = 0.01 ohm, Max excepted current = 4A
ina.calibrate(0.01, 4);
// Enable Bus Over-Voltage Alert
// ina.enableBusOvertLimitAlert();
// ina.enableBusUnderLimitAlert();
// ina.setBusVoltageLimit(3.33);
// Enable Shunt Over-Voltage Alert
// ina.enableShuntOverLimitAlert();
// ina.enableShuntUnderLimitAlert();
// ina.setShuntVoltageLimit(0.0055);
// Enable Power Over-Limit Alert
ina.enableOverPowerLimitAlert();
ina.setPowerLimit(0.130);
// ina.setAlertInvertedPolarity(true)
}
void loop()
{
Serial.print("Bus voltage: ");
Serial.print(ina.readBusVoltage(), 5);
Serial.println(" V");
Serial.print("Bus power: ");
Serial.print(ina.readBusPower(), 5);
Serial.println(" W");
Serial.print("Shunt voltage: ");
Serial.print(ina.readShuntVoltage(), 5);
Serial.println(" V");
Serial.print("Shunt current: ");
Serial.print(ina.readShuntCurrent(), 5);
Serial.println(" A");
Serial.println("");
delay(1000);
}