Arduino Nano and INA3221

Hello,

I use an Arduino Nano and a 3 channel INA3221 sensor, which is connected via I2C with the Nano (address 0x40). I installed the recommended library from Tinyu. With the script below and an external voltage of around 5.1 V and an adjustable load I can increase the current up to 325 mA:

Serial output:

CH1:
U1: 5.12 V
I1: 324.00 mA

but when I increase the current above 325 mA I get a negative current value and the value starts to decrease while the real current gets higher. Can anyone explain to me what's happening here?

Serial output:

CH1:
U1: 5.12 V
I1: -302.00 mA

The same is happening on all 3 channels.

Thank's
Martin

Link to the sensor:
https://www.amazon.de/gp/product/B07XXFPNHC/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

#include <Wire.h>
#include <INA3221.h>

#define SERIAL_SPEED 115200 
#define PRINT_DEC_POINTS 3 

INA3221 ina_0(INA3221_ADDR40_GND);

float voltage1 = 0.0;
float current1 = 0.0;
float voltage2 = 0.0;
float current2 = 0.0;

void current_measure_init() {
    ina_0.begin(&Wire);
    ina_0.reset();
    ina_0.setShuntRes(100, 100, 100);
}

void setup() {
    Serial.begin(SERIAL_SPEED);
    current_measure_init();

    while (!Serial) {
        delay(1);
    }
    // Set shunt resistors to 100 mOhm for all channels
}

void loop() {
  
  current1 = ina_0.getCurrent(INA3221_CH1) * 1000, 
  voltage1 = ina_0.getVoltage(INA3221_CH1),
  current2 = ina_0.getCurrent(INA3221_CH2) * 1000, 
  voltage2 = ina_0.getVoltage(INA3221_CH2),
  
  Serial.println("CH1:");
  Serial.print("U1: ");
  Serial.print(voltage1);
  Serial.println(" V");
  Serial.print("I1: ");
  Serial.print(current1);
  Serial.println(" mA");
  Serial.println();

  delay(10000);
}

Please write in English in the main forum or put your topic to the appropriate national category.

Hi Martin.

The value 325 mA is suspicious. Check the shunt resistors on your sensor Are they 100milliohm (R100) resistors or 1 ohm (1R00) resistors?

Peter.

I am also facing this issue, when i try to increase the current, it gives negative values. Did you find any reason for this problem @vetinari108 ?

No, unfortunately nothing new in this case. I‘m working with the INA219 now.

Is INA219 can measure higher currents without any problem?

It has a 3W 100mOhm Shunt, so as far as I know 3A should be no problem.

I just found the reason for that. In the .cpp (source) file of that INA3221 library, 5uV has been used as the sensitivity , where the real value is 40uV. Also in line 418, the variable "val_raw" should be right shifted 3bits as follows. And it should be casted to (int32_t).

res = (int32_t) (val_raw >> 3) * 40;


You could search the .cpp file of the library, typically available in Documents/Arduino/libraries folder. Then edit the INA3221.cpp file.

Great job! Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.