0

Can't read INA219 right with Raspberry Pi and i2cget
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Can't read INA219 right with Raspberry Pi and i2cget

by njsss on Fri Sep 13, 2019 4:22 pm

I have a simple setup with a LED and resistor pair just for testing. Both multimeter and python code (with pi-ina219 1.2.0) read the correct value of about 3.3mA.
But when I try to use i2c-tools I couldn't get it right. Here's what I did:

1) I set the CALIBRATION to 16V_400mA with 0x2000
Code: Select all | TOGGLE FULL SIZE
i2cset -y 1 0x40 0x05 0x20 0x00 i  // 8192

2) I then copied the configuration from Adafruit_INA219 lib
Code: Select all | TOGGLE FULL SIZE
INA219_CONFIG_BVOLTAGERANGE_16V = (0x0000), // 0-16V Range
INA219_CONFIG_GAIN_1_40MV = (0x0000),  // Gain 1, 40mV Range
INA219_CONFIG_BADCRES_12BIT = (0x0180), // 12-bit bus res = 0..4097
INA219_CONFIG_SADCRES_12BIT_1S_532US = (0x0018), // 1 x 12-bit shunt sample
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS = 0x0007

this gives me the configeration after "OR": 0x019F
Code: Select all | TOGGLE FULL SIZE
i2cset -y 1 0x40 0x00 0x01 0x9f i

3) I tried to read the current
Code: Select all | TOGGLE FULL SIZE
i2cset -y 1 0x40 0x04 w

This gives me either 0x4400 or 0x4200, which if divided by 20 (ina219_currentDivider_mA = 20) is 8704?

Can someone help me get it right?

njsss
 
Posts: 11
Joined: Wed Aug 31, 2016 11:22 am

Re: Can't read INA219 right with Raspberry Pi and i2cget

by mikeysklar on Mon Sep 16, 2019 8:03 pm

Hello njsss,

When this worked for you where you using our CircuitPython adafruit-blinka and adafruit-circuitpython-ina219 libraries on your Pi?

https://learn.adafruit.com/adafruit-ina ... cuitpython

mikeysklar
 
Posts: 111
Joined: Mon Aug 01, 2016 8:10 pm

Re: Can't read INA219 right with Raspberry Pi and i2cget

by njsss on Tue Sep 17, 2019 6:10 pm

mikeysklar wrote:Hello njsss,

When this worked for you where you using our CircuitPython adafruit-blinka and adafruit-circuitpython-ina219 libraries on your Pi?

https://learn.adafruit.com/adafruit-ina ... cuitpython


No, I did not. I used the pi-ina219 instead (https://pypi.org/project/pi-ina219/). My goal is to use the sensor with c++, so I used python to verify if the value was right.

njsss
 
Posts: 11
Joined: Wed Aug 31, 2016 11:22 am

Re: Can't read INA219 right with Raspberry Pi and i2cget

by mikeysklar on Tue Sep 17, 2019 6:29 pm

Gotcha...that C++ code is a little outside our scope, but if you have any issue with our CircuitPython demo I will be happy to assist you.

mikeysklar
 
Posts: 111
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.