Skip to content

Instantly share code, notes, and snippets.

@mattytrentini
Created October 14, 2023 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattytrentini/568cfa9aa7a1cda8fcd158a68d765526 to your computer and use it in GitHub Desktop.
Save mattytrentini/568cfa9aa7a1cda8fcd158a68d765526 to your computer and use it in GitHub Desktop.
i2cdetect in MicroPython
def i2cdetect(addresses):
print(" 0 1 2 3 4 5 6 7 8 9 a b c d e f")
for i in range(0x8):
print(f"{i*0x10:02x}:", end="")
for j in range(0x10):
addr = i * 0x10 + j
if 0x02 < addr < 0x78:
if addr in addresses:
print(f" {addr:02x}", end="")
else:
print(" --", end="")
else:
print(" ", end="")
print("")
addrs = [0x30, 0x36, 0x50, 0x52]
i2cdetect(addrs)
@mattytrentini
Copy link
Author

Output matches Linux's i2cdetect:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 -- -- -- -- -- 36 -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- 52 -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment