This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

INA219: Calibrating INA219 for different shunt resistor

Part Number: INA219

Hi,

I am trying to monitor voltage and current of 5 different devices using 5 different INA219 sensors, but the currents are off a bit and the currents fluctuate when they shouldn't.

shunt resistor value: 0.01 ohm

calibration value: 409

max expected current total throughout the board: 12 A

max expected on each device 5 A

Computing System: Raspberry Pi

Attached is the code:

myPowerMonitor.c
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <endian.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#define CONFIG_REG 0
#define SHUNT_REG 1
#define BUS_REG 2
#define POWER_REG 3
#define CURRENT_REG 4
#define CALIBRATION_REG 5
#define INA_ADDRESS_1 0x40
#define INA_ADDRESS_2 0x41
#define INA_ADDRESS_3 0x42 //change this depending what address you have
#define INA_ADDRESS_4 0x43
#define INA_ADDRESS_5 0x44
int interval = 60;
int i2c_bus = 1;
int i2c_address_1 = INA_ADDRESS_1;
int i2c_address_2 = INA_ADDRESS_2;
int i2c_address_3 = INA_ADDRESS_3;
int i2c_address_4 = INA_ADDRESS_4;
int i2c_address_5 = INA_ADDRESS_5;
int handle;
int i2c_read( void *buf, int len )
{
int rc = 0;
if ( read( handle, buf, len ) != len )
{
printf( "I2C read failed: %s\n", strerror( errno ) );
rc = -1;
}
return 0;
}
int i2c_write( void *buf, int len )
{
int rc = 0;
if ( write( handle, buf, len ) != len )
{
printf( "I2C write failed: %s\n", strerror( errno ) );
rc = -1;
}
return rc;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX