Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi only reading 8 bit bus voltage. #8

Open
pliedl opened this issue Jan 13, 2017 · 1 comment
Open

Raspberry Pi only reading 8 bit bus voltage. #8

pliedl opened this issue Jan 13, 2017 · 1 comment

Comments

@pliedl
Copy link

pliedl commented Jan 13, 2017

I wasn't getting linear discharge graphs on a 12v battery discharge. I am a novice but I found the solution to the problem on the Adafruit forum. I don't how to go about modifying the software but here is the fix that worked for me:

To overcome the issue of 8 bit voltage 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


@charkster
Copy link

charkster commented Sep 2, 2017

I did not see the above change in the latest Subfact_ina219.py
I use a different I2C class that has a default endian (not the included Adafruit_I2C.py).
The above change has the endian specified in the readList manipulation of bytes.
It is a superior solution as readList is always the same, while readU16 can be different.
I manually added the above change, as I needed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants