Giter VIP home page Giter VIP logo

ina219_we's Introduction

INA219_WE

An Arduino library for the INA219 current and power sensor module.

It allows to set various ADC modes, gains and bus voltage ranges. Continuous mode, triggered mode, power down and ADC off mode are supported. Default shunt size is 0.1 ohms, but you can change it.

You can run the library on an ATtiny, I tested it on the ATtiny85. To do so, you need to also install the TinyWireM library from Adafruit. An example sketch is included.

I attached a list of public functions and a fritzing scheme for the example sketches.

You find further details here:

https://wolles-elektronikkiste.de/ina219 (German)

https://wolles-elektronikkiste.de/en/ina219-current-and-power-sensor (English)

ina219_we's People

Contributors

holgerhees avatar maximweb avatar simoschip2000 avatar waynepiekarski avatar wollewald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ina219_we's Issues

i2C problem with usb host shield

Hi,
I am using https://github.com/felis/USB_Host_Shield_2.0 lib to use an usb host shield to run a barcode device. It is SPI interface.
I am having trouble using the Wire.begin(); directive in order to init the i2c hardware with the USB host shield
commenting out the Wire.begin(); let my barcode scanner work but when I use Wire.begin(); in setup for arduino uno the reader did not work. The i2c device uses the A4 A5 pins on the board.

Did anybody have that problem before?

Regards,
Nuri Erginer

calculation

If this ok? "mV/1000"
loadVoltage_V = busVoltage_V + (shuntVoltage_mV/1000);

Wouldn't that be correct?
loadVoltage_V = busVoltage_V + (shuntVoltage_mV*1000);

Greetings Michael

Can the reading of the resuts be speed ut with burst reading?

I am making a power logger to log the power consumption for a esp32 BME280 sensor that's is active less than 350ms thanks to ESPNOW to a SD card and are with your great library getting really good measurement speeds since it can set the ADC to 9-bit unlike other libraries. I get a full sampling every 1700us (shunt, busvoltage, current and voltage) and have seen that I get varied values between the measurements so its not just the same INA219 reading read twice.

I noticed that each "get_value" request is taking way more (200-220us each, 620 for three) than the 84us the 9-bit conversion in the datasheet states and started to think it about and remembered that I read that Sparkfun BME280 library (in pull request 50) is using burst reading according to bme280 datasheet section 4 and reads all registers at one time and then divides them up. Would this be possible to do here as well and will it speed up the reading and minimise the risk that two "get" is from different samplings? I noticed that this is way over my head and I do not have the knowledge myself to do it but thought it might be something you know how to do and was interested in?

Just an idea... that might be totally stupid but thought it was worth asking you.

Best regards, Albin

Can the reading of results be speed up?

I am making a power logger to log the power consumption for a esp32 BME280 sensor that's is active less than 350ms thanks to ESPNOW to a SD card and are with your great library getting really good measurement speeds since it can set the ADC to 9-bit unlike other libraries. I get a full sampling every 1700us (shunt, busvoltage, current and voltage) and have seen that I get varied values between the measurements so its not just the same INA219 reading read twice.

I noticed that each "get_value" request is taking way more (300-700us) than the 84us the 9-bit conversion in the datasheet states and started to think it about and remembered that I read that Sparkfun BME280 library (in pull request 50) is using burst reading according to bme280 datasheet section 4 and reads all registers at one time and then divides them up. Would this be possible to do here as well and will it speed up the reading and minimise the risk that two "get" is from different samplings? I noticed that this is way over my head and I do not have the knowledge myself to do it but thought it might be something you know how to do and was interested in?

Just an idea... that might be totally stupid but thought it was worth asking you.

Best regards, Albin

Not an issue but a possible contribution ...don't know where else to put it ;-)

Hi Wolle.

Excellent library. Probably the most comprehensive that I found. Thank you very much for having written it and sharing it.

I am working on a project and I needed the system to find the shunt offset voltage and the optimal gain settings, so I developed the following (2 functions) that you might find a way to integrate to the INA219_WE library, if you so desire.

The 1st function : It simply requires that the output of the INA219 does not draw any current (open output).
The second function : Establishes the optimal "setPGain()" dynamically (...the function can be called on a regular basis by the application program) in other to take advantage of the optimal sensitivity. Here they are.

First function.
/**************************************************************************************************************************/
void Diagnostics::findINA219OffsetVoltage(){

Serial.println(F("\nFinding the MEAN of of the INA219 sensor and store the correction value"));

float shuntVoltageSmaller = 10.0f; // Make it such that a INA219 value will always be smaller
float shuntVoltageLarger = 0.0f; // Make it such that a INA219 value will always be larger if not 0
float shuntVoltageBuffer = 0.0f;

for(int i = 0; i < 1000; i ++) {

activityWheel();

shuntVoltageBuffer = fp.diagnosticsGetShuntVoltage_mV();

if (shuntVoltageBuffer < shuntVoltageSmaller) {
  shuntVoltageSmaller = shuntVoltageBuffer;
}

if (shuntVoltageBuffer > shuntVoltageLarger) {
  shuntVoltageLarger = shuntVoltageBuffer;
}

MY_MILLI_DELAY(5);                                         // Same as delay(), but using millis()

}

Serial.print("\bShunt Voltage Smaller : "); Serial.println(shuntVoltageSmaller);
Serial.print("Shunt Voltage Larger : "); Serial.println(shuntVoltageLarger);

shuntVoltageBuffer = (shuntVoltageSmaller + shuntVoltageLarger) /2.0f;

Serial.print("Average of the Smaller and Larger Shunt Voltage Values : "); Serial.println(shuntVoltageBuffer,3);
ds.variousData.INA219ShuntOffsetVoltageCompensation = shuntVoltageBuffer;

Serial.print(F("\b\nShunt OFFSET Voltage MEAN of Smaller/Larger of the INA219 : ")); Serial.println(ds.variousData.INA219ShuntOffsetVoltageCompensation,3);

/******************************************/
// The following method does not give an enough precise result ! (Kept for documentation)
// Serial.println(F("\b \nFinding the AVERAGE of and of the INA219 sensor"));
// shuntVoltageBuffer = 0;
// for (int i = 0; i <500; i++) {
// activityWheel();
// shuntVoltageBuffer += fp.diagnosticsGetShuntVoltage_mV();
// MY_MILLI_DELAY(5);
// }
// Serial.print(F("\b \nShunt OFFSET Voltage AVERAGE of the INA219 : ")); Serial.println((shuntVoltageBuffer) /1000.0f,3);

EEPROM.put(ds.eepromPointers.eepromINA219OffsetVoltageCompensation, ds.variousData.INA219ShuntOffsetVoltageCompensation);
Serial.print("INA219 Shunt Offset Voltage Value from EEPROM : "); Serial.println(EEPROM.get(ds.eepromPointers.eepromINA219OffsetVoltageCompensation, ds.variousData.INA219ShuntOffsetVoltageCompensation),3);
Serial.print("INA219 Shunt Offset Voltage Value from VARIABLE: " ); Serial.print(ds.variousData.INA219ShuntOffsetVoltageCompensation);
}

/**************************************************************************************************************************/
void Diagnostics::activityWheel() {

static uint32_t timer = millis();
static uint8_t counter = 0;

if (millis() - timer >= 200) {

timer = millis();

Serial.print(F("\b"));

if (counter == 0) {
  Serial.print(F("|"));
}
else if (counter == 1) {
  Serial.print(F("-"));
}
else if (counter == 2) {
  Serial.print("\\");
}    
else if (counter == 3) {
  Serial.print("|");
}
else if (counter == 4) {
  Serial.print("/");
}
else if (counter == 5) {
  Serial.print(F("-"));
}
counter ++;

if (counter >= 6) {
  counter = 0;
}

}
}

/**************************************************************************************************************************/
Second function.

void FunctionProcessing::adjustINA219Gain() { // Function organize in such a way that the gain is not continuously reprogrammed if not needed

if (ds.variousData.currentOutputValue >= 1.600f) { // Between 1.6 A and 3.2 A

if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG320) {

  ina219.setPGain(PG_320);

  ds.variousData.INA219PresetGain = ds.INA219Gain::PG320;

  Serial.println("PG set to PG320");
}

}

else if (ds.variousData.currentOutputValue >= 0.800f) { // Between 0.8 A and 1.6 A

if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG160) {

  ina219.setPGain(PG_160);

  ds.variousData.INA219PresetGain = ds.INA219Gain::PG160;

  Serial.println("PG set to PG160");      
}

}

else if (ds.variousData.currentOutputValue >= 0.400f) { // Between 0.4 A and 0.8 A

if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG80) {

  ina219.setPGain(PG_80);

  ds.variousData.INA219PresetGain = ds.INA219Gain::PG80;

  Serial.println("PG set to PG80");      
}

}

else if (ds.variousData.currentOutputValue > 0.000f) { // Between 0.0 A and 0.4 A

if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG40) {

  ina219.setPGain(PG_40);

  ds.variousData.INA219PresetGain = ds.INA219Gain::PG40;

  Serial.println("PG set to PG40");      
}

}

else if (ds.variousData.currentOutputValue <= 0.000f) { // 0.0 A

if (ds.variousData.INA219PresetGain != ds.INA219Gain::PG40) {

  ina219.setPGain(PG_40);

  ds.variousData.INA219PresetGain = ds.INA219Gain::PG40;

  Serial.println("PG set to PG40"); Serial.println(F("No current detected in the INA219 Sensor. Check VOLTAGE REGULATOR !!!"));
}

}
}

/*****************************************************************/
Finally while in the initialization (setup():
/* The shunt offset voltage is found by the diagnostics function with the voltage regulator removed (see Diagnostics.cpp) */
if (ds.variousData.INA219ShuntOffsetVoltageCompensation > 0.0f) {
ina219.setShuntVoltOffset_mV(ds.variousData.INA219ShuntOffsetVoltageCompensation); // insert the shunt voltage (millivolts) you detect at zero current (i.e INA219 open output)

Regards,

Rene-Jean Mercier

in function : getShuntVoltage_mV()

Correct me if I am wrong. In Function : getShuntVoltage_mV(), I believe that it should read: + shuntVoltageOffset.

float INA219_WE::getShuntVoltage_mV(){
int16_t val;
val = (int16_t) readRegister(INA219_SHUNT_REG) + shuntVoltageOffset;
if((abs(val))== shuntOverflowLimit){
overflow = true;
}
else{
overflow = false;
}
return (val * 0.01);
}

Impossible to use together with ADS1115_WE

Hello. Thanks for amazing set of libraries.

I have a problem using INA219_WE together with ADS1115_WE:

/.../libraries/INA219_WE/src/INA219_WE.h:62:3: error: conflicting declaration 'typedef enum INA219_MEASURE_MODE measureMode'
 } measureMode;
   ^
/.../libraries/ADS1115_WE/src/ADS1115_WE.h:77:3: note: previous declaration as 'typedef enum ADS1115_MEASURE_MODE measureMode'
 } measureMode;
   ^

As you can see there is a conflict with names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.