kplindegaard / smbus2

A drop-in replacement for smbus-cffi/smbus-python in pure Python
MIT License
243 stars 68 forks source link

SMBusWrapper relic #78

Closed imwatson closed 2 years ago

imwatson commented 2 years ago

Hi,

I'm trying to get a sensor to work with requires smbus2 but includes the line:

from smbus2 import SMBusWrapper, which I think not longer exists as a class in smbus2 (as far as I can tell). This short thread (above) suggests that it was removed and replaced by extension of SMBus. The section causing issues (in a script called sgp30.py) has the following line:

with SMBusWrapper(1) as bus:

Is there a simple change I can make to the scripts that call smbus2 and here that will allow reading of the i2c port on a grove HAT / sgp30 CO2 sensor.

thanks!

imwatson commented 2 years ago

Apologies - it was late last night. The version history of smbus2 provides the problem and the solution:

https://github.com/kplindegaard/smbus2/blob/master/CHANGELOG.md

Leaving this here for others to find, hopefully

imwatson commented 2 years ago

OK - fixed it, the unit now works.

You'll need to edit sgp30.py to (1)

remove SMBusWrapper from line 2 (should now read > from smbus import SMBus, ic2_msg) change line 119 to > with SMBus(1) as bus:

Anywhere you import SMBusWrapper in your code, simply replace with SMBus or remove