m-rtijn / mpu6050

A Python module for accessing the MPU-6050 digital accelerometer and gyroscope on a Raspberry Pi.
MIT License
296 stars 145 forks source link

Update to smbus2 #31

Open aaroncwhite opened 4 years ago

aaroncwhite commented 4 years ago

Hey, thanks for the library! I've had to update to smbus2 so it plays nice with another library. Figure it might be useful. Not sure if this is still maintained, but just in case!

m-rtijn commented 4 years ago

Hey @aaroncwhite, thanks for the pull request!

Is there any particular reason to always want to use smbus2 over the standard python(3)-smbus package? If not, I rather keep this merge request open and refer to it in the README, to have the standard smbus package as the default and let people know that someone also made a fork using smbus2.

ThinkalVB commented 3 years ago

What about this ?

import imp
try:
    imp.find_module('smbus')
    import smbus
except ImportError as e:
    import smbus2 as smbus
m-rtijn commented 3 years ago

@ThinkalVB this assumes that if the regular smbus is not available, then smbus2 will be available and/or you want to use smbus2. Which is an assumption that you probably should not make. I think it is better for users to explicitly choose which smbus version they use, either by using the master branch or using the fork by @aaroncwhite.