def __init__(self, bus_number=None):
"""Initialize i2c communication with the sensor and sets default parameters.
Default parameters: continuous integration (not started) with 12ms cycles, gain 1x, pre-scale 1.
:param bus_number: the i2c bus number (usually 0 or 1, depending on the hardware). Use the i2cdetect command
line tool to identify the right bus. If set to None, will use the Raspberry Pi revision number to guess which
bus to use.
"""
if bus_number is None:
# Use Rasbperry Pi revision to choose bus number
board_revision = RPi.GPIO.RPI_REVISION
if board_revision == 2 or board_revision == 3:
bus_number = 1
else:
bus_number = 0
self.bus = smbus.SMBus(bus_number)
self.use_continuous_integration()
self.set_gain_and_prescaler(1, 1)
评论列表
文章目录