TonyGo

I2Cscan.py

Mar 6th, 2026
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | Source Code | 0 0
  1. # i2c Scan
  2.  
  3. import machine
  4.  
  5. I2C_SDA_PIN = 40  # PRESTO    
  6. I2C_SCL_PIN = 41  #          
  7. i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
  8.  
  9. print('Scanning I2C bus.')
  10. devices = i2c.scan() # this returns a list of devices
  11.  
  12. device_count = len(devices)
  13.  
  14. if device_count == 0:
  15.     print('No i2c device found.')
  16. else:
  17.     print(device_count, 'devices found.')
  18.  
  19. for device in devices:
  20.     print('Decimal address:', device, ", Hex address: ", hex(device))
Advertisement
Add Comment
Please, Sign In to add comment