Skip to content

Instantly share code, notes, and snippets.

@kungpfui
kungpfui / scan_for_i2c_devices
Created January 13, 2020 20:16
Scan for I2C devices with smbus2 library (like i2cdetect)
#!/usr/bin/env python3
from smbus2 import SMBus
def scan(force=False):
devices = []
for addr in range(0x03, 0x77 + 1):
read = SMBus.read_byte, (addr,), {'force':force}
write = SMBus.write_byte, (addr, 0), {'force':force}