def i2c_scan(bus_num=1):
global HAVE_SMBUS
if not HAVE_SMBUS:
return []
bus = smbus.SMBus(bus_num) # 1 indicates /dev/i2c-1
devices = []
for device in range(128):
try:
bus.read_byte(device)
logger.info("Found i2c device at addr: {}".format(hex(device)))
devices.append(device)
except Exception: # exception if read_byte fails
pass
return devices
# Must run some activites on the main thread, e.g. PyGame event polling
评论列表
文章目录