jarzebski / arduino-ina226 Goto Github PK
View Code? Open in Web Editor NEWINA226 Bi-directional Current/Power Monitor Arduino Librar
License: MIT License
INA226 Bi-directional Current/Power Monitor Arduino Librar
License: MIT License
There is a blocking wait for one millisecond, that results in a maximal sampel frequency lower than 1kHz.
Hello,
Thanks for this nice library. I see functions to set the limit alerts but no function to turn off alerts. Is this on purpose? Otherwise I would create at least one function to disable all alerts or all the individual functions to disable alerts.
Hi.. I have a problem to use 2 module INA226 with protocol I2C.
I write this sketch but it doesn't work. the Arduino IDE give me errors. Can you help me?
`/*
INA226 Bi-directional Current/Power Monitor. Simple 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_5V;
INA226 ina_3.3V(0x45);
void checkConfig()
{
Serial.print("Max possible current 5V: ");
Serial.print(ina_5V.getMaxPossibleCurrent());
Serial.println(" A");
Serial.print("Max current 5V: ");
Serial.print(ina_5V.getMaxCurrent());
Serial.println(" A");
Serial.print("Max shunt voltage 5V: ");
Serial.print(ina_5V.getMaxShuntVoltage());
Serial.println(" V");
Serial.print("Max power 5V: ");
Serial.print(ina_5V.getMaxPower());
Serial.println(" W");
Serial.print("Max possible current 3.3V: ");
Serial.print(ina_3.3V.getMaxPossibleCurrent());
Serial.println(" A");
Serial.print("Max current 3.3V: ");
Serial.print(ina_3.3V.getMaxCurrent());
Serial.println(" A");
Serial.print("Max shunt voltage 3.3V: ");
Serial.print(ina_3.3V.getMaxShuntVoltage());
Serial.println(" V");
Serial.print("Max power 3.3V: ");
Serial.print(ina_3.3V.getMaxPower());
Serial.println(" W");
}
void setup()
{
Serial.begin(115200);
Serial.println("Initialize INA226");
Serial.println("-----------------------------------------------");
// Default INA226 address is 0x40
ina_5V.begin();
ina_3.3V.begin();
// Configure INA226
ina_5V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
ina_3.3V.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
// Calibrate INA226. Rshunt = 0.1 ohm, Max excepted current = 4A
ina_5V.calibrate(0.1, 4);
ina_3.3V.calibrate(0.1, 4);
// Display configuration
checkConfig();
Serial.println("-----------------------------------------------");
}
void loop()
{
Serial.print("Bus voltage 5V: ");
Serial.print(ina_5V.readBusVoltage(), 2); // valore a 2 cifre decimali
Serial.println(" V");
Serial.print("Bus power 5V: ");
Serial.print(ina_5V.readBusPower(), 3); // valore a 3 cifre decimali
Serial.println(" W");
Serial.print("Shunt voltage 5V: ");
Serial.print(ina_5V.readShuntVoltage(), 5);
Serial.println(" V");
Serial.print("Shunt current 5V: ");
Serial.print(ina_5V.readShuntCurrent(), 4); // valore a 3 cifre decimali
Serial.println(" A");
Serial.print("Bus voltage 3.3V: ");
Serial.print(ina_3.3V.readBusVoltage(), 2); // valore a 2 cifre decimali
Serial.println(" V");
Serial.print("Bus power 3.3V: ");
Serial.print(ina_3.3V.readBusPower(), 3); // valore a 3 cifre decimali
Serial.println(" W");
Serial.print("Shunt voltage 3.3V: ");
Serial.print(ina_3.3V.readShuntVoltage(), 5);
Serial.println(" V");
Serial.print("Shunt current 3.3V: ");
Serial.print(ina_3.3V.readShuntCurrent(), 4); // valore a 3 cifre decimali
Serial.println(" A");
Serial.println("");
delay(1000);
}`
Wire.requestFrom(...) should not be encapsulated by a Transmission.
The begin/end Transmission is only needed for sending data to a I²C slave by send().
https://playground.arduino.cc/Main/WireLibraryDetailedReference#beginTransmission
while(!Wire.available()) {};
is also not needed. When Wire.requestFrom() has returned the I2C transmission has ended and the data is in the buffer.
To get the maximum accuracy for Current and Power, the following equation should be used.
Current_LSB = (float)((Maximum Expected Current)/(2^15))
I used it to measure 4 to 20mA current with this and I was able to achieve the accuracy of +/-2 uA which when compared to the readings on Fluke 787B.
Could you change lisence to MIT. GPL requires that also my code has to be under GPL, what it never will be. I changed my NMEA2000 library to MIT so that it can be used freely.
I have proposed some changes to the function:
void INA226::setShuntVoltageLimit(float voltage){// MODIFIED by GCAR
uint16_t value = voltage/2.5e-6;
writeRegister16(INA226_REG_ALERTLIMIT, value);
}
getMaskEnable should be public to give access to CNVR flag to coordinate value reading
INA226 example code seems to work on ProMini hardware but not on the Bluefruit NRF52.
I have confirmed my Bluefruit NRF52 i2c functionality using a TMP100 sensor.
Any ideas?
Andy
Line 307 has a semicolon
#endif;
This leads to a warning
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.