We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ea6033e commit d664a80Copy full SHA for d664a80
examples/03-i2c-scan/i2c_scan.py
@@ -0,0 +1,28 @@
1
+"""
2
+I2C scanner
3
+
4
+Scan the I2C (Inter-Integrated Circuit) bus for connected
5
+devices and print their addresses. This script is useful
6
+for identifying I2C devices connected to your microcontroller.
7
8
+Authors:
9
+- MicroPython
10
+- Tomas Fryza
11
12
+Creation date: 2023-06-17
13
+Last modified: 2024-11-02
14
15
16
+from machine import I2C
17
+from machine import Pin
18
19
+# Init I2C using pins GP22 & GP21 (default I2C0 pins)
20
+i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100_000)
21
22
+print("Scanning I2C... ", end="")
23
+addrs = i2c.scan()
24
+print(f"{len(addrs)} device(s) detected")
25
26
+print("dec.\t hex.")
27
+for addr in addrs:
28
+ print(f"{addr}\t {hex(addr)}")
0 commit comments