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

smbus2 reading incorrect value from I2C register #115

Open
pmi123 opened this issue Aug 6, 2024 · 1 comment
Open

smbus2 reading incorrect value from I2C register #115

pmi123 opened this issue Aug 6, 2024 · 1 comment

Comments

@pmi123
Copy link

pmi123 commented Aug 6, 2024

I have a Pi Zero W reading registers from an AdaFruit MAX17042 battery fuel gauge https://www.adafruit.com/product/5580 using the I2C bus with a single cell LiPo battery and a 68 Ohm resistor and red LED as a load. AdaFruit provides some C code to interface to the board https://github.com/adafruit/Adafruit_CircuitPython_MAX1704x/tree/main and I can read the voltage from the register on the chip using the I2C bus, and it appears to be accurate. When I try to read the same register using smbus2 I get a different value.

The value read from the Adafruit code is 513D:
adafruit-1
The value read from the smbus2 code is 5113:
smbus2-1

I am using data = self.i2cbus.read_word_data(self.i2caddress, register) to read the registers on the MAX17048 chip. The python files for the code I am using are attached as .txt.files.
i2ctest.txt
MAX17048.txt

If I use smbus instead of smbus2 to read the MAX17042's registers, I get the correct result. I have attached the updated MAX17048.py code to use smbus instead of smbus2.
MAX17048-smbus.txt

@kplindegaard
Copy link
Owner

Hi @pmi123.
smbus2 is not a clever library. It is just a wrapper on top of the Linux kernel's i2c bus interface with the objective to simplify i2c and SMBus communication in Python. It doesn't do any sort of data conversion or adjustments, just pipes through the commands and responses as is.

I am not familiar with the device you have, but aren't the differences in the received word values very small? 513D vs 5113 are not a lot if the whole word range is used. Thus leaving room for measurement error/noise, I mean....?

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

No branches or pull requests

2 participants