Skip to main content

Project Based Engineering Instrumentation High Level Coding and Microcontrollers

Section 7.4 Using an I2C Scanner

If you’re having trouble getting an I2C device to work, it’s a good idea to run an I2C scanner to make sure you can see the device and that you have the correct address. Here is a simple I2C scanner code that you can run on your CPX/CPB.
import time
import board
import busio

i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
    pass

try:
  while True:
      print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()])
  time.sleep(2)