Zanduino / INA

Combined Arduino library for reading multiple INA2xx power monitor devices
GNU General Public License v3.0
158 stars 41 forks source link

Wrong voltage reading with INA226 #90

Closed TeguhTeknisi closed 1 year ago

TeguhTeknisi commented 2 years ago

Hi Zanshin, Thanks for the library. I want to ask about voltage reading using INA226

i use INA226 to read voltage and amperage from Solar Charger Controller to Li Ion 7S Battery My PV is 600wp, so i order and use this module https://www.aliexpress.com/item/1005003306504394.html Its have R002 and sugested max reading is 20A

the problem is, voltage only read 25v it should be 28v so i modified the code to get 28v reading. but when there is no input ( no sun ), the voltage reading will drop 1 volt and there is 20mA reading.

is that normal behavior?

here the code i use

//***Libraries***
#include <Wire.h>              // adds I2C library 
#include <LiquidCrystal_I2C.h> // adds LCD 16x2
#include <INA.h>               // Zanshin INA Library 

//LCD 1602
LiquidCrystal_I2C lcd(0x3F,16,2);
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

//INA226
INA_Class      INA;
byte devicesFound =      0; ///< Number of INAs found
float ina_current;
float ina_voltage;
float Power_Value;

void setup()
{
  //I2C
  Wire.begin();
  //LCD
  lcd.begin(16,2);
  lcd.init();
  lcd.backlight();

  // Print a message to the LCD.
  lcd.clear();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("ESP8266 + INA226");
  lcd.setCursor(0,1); 
  lcd.print("Power Monitor");
  delay (60);
  lcd.clear();

  devicesFound = INA.begin(41, 2000, 0);   
  INA.setBusConversion(8500);   
  INA.setShuntConversion(8500);
  INA.setAveraging(128); 
  INA.setMode(INA_MODE_CONTINUOUS_BOTH); 
}

void loop()
{
  ina_voltage = INA.getBusMilliVolts() / 975.0;  
  if ( INA.getBusMicroAmps() / 1000 < 20 ) { ina_current = 0; } else { ina_current = INA.getBusMicroAmps() / 1000.0; }
  Power_Value = ina_voltage * ina_current ;

  lcd.clear(); 
  lcd.setCursor(0,0);
  lcd.print(ina_voltage, 2); 
  lcd.print("V ");
  lcd.setCursor(7,0);
  lcd.print(Power_Value / 1000, 1);
  lcd.print("W ");
  lcd.setCursor(0,1);
  lcd.print(ina_current / 1000, 2);
  lcd.print("A");    

}

Edit: NVM , its because onboard rshunt is too hot and make the ina226 chip getting hot. After moving the rshunt to eksternal pcb, the problem is gone.

Best Regrads, Teguh