cmvr-es/test/test_i2c_pca9528.py

25 lines
837 B
Python
Raw Permalink Normal View History

import board
import busio
# 定义所有可能的总线编号
possible_buses = [0, 1, 2, 3, 4, 5]
# 扫描所有总线
for bus_number in possible_buses:
try:
# 初始化I2C总线
i2c = busio.I2C(f"/dev/i2c-{bus_number}")
print(f"正在扫描总线 /dev/i2c-{bus_number}...")
# 尝试锁定并扫描设备地址
if i2c.try_lock():
addresses = i2c.scan()
if addresses:
print(f"在总线 /dev/i2c-{bus_number} 上找到以下设备地址:")
for address in addresses:
print(f" - {hex(address)}")
else:
print(f"未在总线 /dev/i2c-{bus_number} 上找到任何设备。")
i2c.unlock()
except Exception as e:
print(f"无法访问总线 /dev/i2c-{bus_number}: {e}")