1 import Adafruit_PureIO.smbus as smbus
11 def __init__(self, bus_num, mode=MASTER, baudrate=None):
12 if mode != self.MASTER:
13 raise NotImplementedError("Only I2C Master supported!")
17 # print("I2C frequency is not settable in python, ignoring!")
20 self._i2c_bus = smbus.SMBus(bus_num)
21 except FileNotFoundError:
22 raise RuntimeError("I2C Bus #%d not found, check if enabled in config!" % bus_num)
25 """Try to read a byte from each address, if you get an OSError it means the device isnt there"""
27 for addr in range(0,0x80):
29 self._i2c_bus.read_byte(addr)
35 def writeto(self, address, buffer, stop=True):
36 self._i2c_bus.write_bytes(address, buffer)
38 def readfrom_into(self, address, buffer, stop=True):
39 readin = self._i2c_bus.read_bytes(address, len(buffer))
40 for i in range(len(buffer)):