INA219 python library

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
alvin_yc
 
Posts: 1
Joined: Wed Oct 09, 2013 4:58 pm

Re: INA219 python library

Post by alvin_yc »

Hi,
I just got 2x INA219 High Side DC Current Sensor Breakout and try to read these 2x DC current & voltage output.

Here are what I did:
- I run "sudo i2cdetect -y 1" to check address. It shows address 40 & 41.
- I managed to connected up to 1st motor to Breakout board (ox40) and no problem to read DC current and voltage.
- I also set up 2nd motor to Breakout board (ox41) and change program " Subfact_ina219.py" address to "__INA219_ADDRESS = 0x41" and constructor to " def __init__(self, address=0x41, debug=False):". Then I run "ina219_example.py". I have no problem read 2nd motor current and voltage.

Any ideal how can I program to read these 2x motors' current & voltage same time?

Thanks,

User avatar
marks3
 
Posts: 52
Joined: Fri Oct 12, 2012 1:07 pm

Re: INA219 python library

Post by marks3 »

One easy way and sort of a lazy approach would be to run two copies of the python script in the background. Pass an argument to the script so it can decide which port to monitor.

Or just be really sloppy and create two versions of the script with the port addresses hard-coded and then run them both in the background.

Hope this helps.

User avatar
mr8k
 
Posts: 2
Joined: Fri Feb 06, 2015 12:57 pm

Re: INA219 python library

Post by mr8k »

Hi,
I am building a multi battery monitor using INA219 and INA220. Using Raspberry Pi.

I am linking my program to ADAFRUIT_I2C.py and SUBFACT_INA29.py. All is OK BUT my bus voltage ADC resolution appears to be only 9 bits. (The shunt ADC is OK at 12 bits). So I only have voltage steps of around 12mV rather than 4mV !

Can I change something in Subfact-ina219/py to resolve this. If so what?

thanks in advance for any help.

cheers

Peter

User avatar
marks3
 
Posts: 52
Joined: Fri Oct 12, 2012 1:07 pm

Re: INA219 python library

Post by marks3 »

I still monitor this form for my own education. You got me on this one - I can't say I have looked at the resolution to that accuracy. I agree that if the chip is capable then why not use it to the best resolution in the range you desire but I can't help. I wish the code was in C and not Python :)

Mark

User avatar
static
 
Posts: 188
Joined: Thu Dec 23, 2010 6:21 pm

Re: INA219 python library

Post by static »

I'm getting ready to move, and I don't have my INA219 anymore.
However, I'm looking at putting in a multiple battery monitor at my new house, for a solar backup system. I'll put an order in for some new parts next week, but it will be a while before I can work on this.

User avatar
mr8k
 
Posts: 2
Joined: Fri Feb 06, 2015 12:57 pm

Re: INA219 python library

Post by mr8k »

Sorted out the issue of Adafruit in219 with a Raspberry Pi only reading 8 bit bus voltage. There is a strange set of code in "Subfact_ina219.py" that causes this.

To overcome the issue and read bus voltage down to millivolts resolution apply the following changes to the file "Subfact_ina219.py"

FIND LINES
-----------------------------------------------------------------------------------
def getBusVoltage_raw(self):
result = self.i2c.readU16(self.__INA219_REG_BUSVOLTAGE)

# Shift to the right 3 to drop CNVR and OVF and multiply by LSB
return (result >> 3) * 4

-----------------------------------------------------------------------------------
REPLACE WITH
-----------------------------------------------------------------------------------

def getBusVoltage_raw(self):
result = self.i2c.readList(self.__INA219_REG_BUSVOLTAGE,2)
if (result[0] >> 7 == 1):
testint = (result[0]*256 + result[1])
othernew = self.twosToInt(testint, 16)
return othernew
else:
return (result[0] << 8) | (result[1])

------------------------------------------------------------------------------------

FIND LNES
------------------------------------------------------------------------------------
def getBusVoltage_V(self):
value = self.getBusVoltage_raw()
return value * 0.001

------------------------------------------------------------------------------------
CHANGE MAGNITUDE MULTIPLIER TO 0.0005 AS BELOW
------------------------------------------------------------------------------------
def getBusVoltage_V(self):
value = self.getBusVoltage_raw()
return value * 0.0005

------------------------------------------------------------------------------------


Hope this helps anyone with a low 8 bit resolution output from the Adafruit INA219 routines, which by the way also work for the INA220 chip which i built up myself, as I needed low side current measurements, i.e. with a shunt between ground and the power source.


cheers

Peter

User avatar
static
 
Posts: 188
Joined: Thu Dec 23, 2010 6:21 pm

Re: INA219 python library

Post by static »

Peter,
Nice work, amigo!

User avatar
Anna553
 
Posts: 11
Joined: Thu May 28, 2015 10:47 pm

Re: INA219 python library

Post by Anna553 »

Hi,
Currently, I am trying to connect the raspberry pi B+ and ina219 together. However, when I try to check the ina219 address using "sudo i2cdetect -y 1", the address was not detected. I followed this tutorial "http://www.raspberrypi-spy.co.uk/2014/1 ... rettyPhoto" to do the configuration for i2c. Can anyone tell me why wasn't the ina219 address detected?? Thanks!!
I had connected the vcc to 5v, gnd to gnd, SCL to pin 05 and SDA to pin 03.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: INA219 python library

Post by adafruit_support_mike »

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

User avatar
Anna553
 
Posts: 11
Joined: Thu May 28, 2015 10:47 pm

Re: INA219 python library

Post by Anna553 »

adafruit_support_mike wrote:Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.
Attachments
Here it is. Thanks!! :)
Here it is. Thanks!! :)
Optimized-IMG_0675.JPG (701.93 KiB) Viewed 2416 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: INA219 python library

Post by adafruit_support_mike »

Thank you.

Your soldering looks good and the connections are correct. Let's make sure you're actually getting contact though. Take a voltage measurement between the VCC and GND pins on the INA219 breakout, and check continuity between the solder joints on the breakout's SDA/SCL pins and the pin header on the RasPi.

Sometimes you get a broken wire inside a jumper, making a visually perfect circuit fail.

User avatar
Anna553
 
Posts: 11
Joined: Thu May 28, 2015 10:47 pm

Re: INA219 python library

Post by Anna553 »

adafruit_support_mike wrote:Thank you.

Your soldering looks good and the connections are correct. Let's make sure you're actually getting contact though. Take a voltage measurement between the VCC and GND pins on the INA219 breakout, and check continuity between the solder joints on the breakout's SDA/SCL pins and the pin header on the RasPi.

Sometimes you get a broken wire inside a jumper, making a visually perfect circuit fail.
Hi, thanks for your reply. I had checked the voltage and continuity, it is fine. However, this is my results. Could it be the INA219 is faulty?
Attachments
Optimized-IMG_0678.JPG
Optimized-IMG_0678.JPG (334.14 KiB) Viewed 2385 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: INA219 python library

Post by adafruit_support_mike »

That does sound like a dead sensor.

Did you get it from Adafruit, and if so, when?

User avatar
Anna553
 
Posts: 11
Joined: Thu May 28, 2015 10:47 pm

Re: INA219 python library

Post by Anna553 »

adafruit_support_mike wrote:That does sound like a dead sensor.

Did you get it from Adafruit, and if so, when?

Yeah, not really sure of any methods to check whether its faulty, but guess it is.
I didn't get it from adafruit though. Have you got any suggestions on how do I resolve this or must I purchase a new sensor?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: INA219 python library

Post by adafruit_support_mike »

I just looked back at the photos and saw the Adafruit logo on the board in your photo.. I'm guessing you got it from one of our resellers?

If so, how long have you had it? Our return/replacement period is 30 days, and I think most of our resellers offer the same terms.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”