forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Milestone
Description
Adafruit CircuitPython 10.0.0-beta.0 on 2025-07-15; Adafruit Fruit Jam with rp2350b
With this code which is embedded in I2C page of many learn guides:
import board
import busio
from microcontroller import Pin
def is_hardware_i2c(scl, sda):
try:
p = busio.I2C(scl, sda)
p.deinit()
return True
except ValueError:
return False
except RuntimeError:
return True
def get_unique_pins():
exclude = [
getattr(board, p)
for p in [
# This is not an exhaustive list of unexposed pins. Your results
# may include other pins that you cannot easily connect to.
"NEOPIXEL",
"DOTSTAR_CLOCK",
"DOTSTAR_DATA",
"APA102_SCK",
"APA102_MOSI",
"LED",
"SWITCH",
"BUTTON",
"ACCELEROMETER_INTERRUPT",
"VOLTAGE_MONITOR",
"MICROPHONE_CLOCK",
"MICROPHONE_DATA",
"RFM_RST",
"RFM_CS",
"RFM_IO0",
"RFM_IO1",
"RFM_IO2",
"RFM_IO3",
"RFM_IO4",
"RFM_IO5",
"TFT_I2C_POWER",
"NEOPIXEL_POWER",
]
if p in dir(board)
]
pins = [
pin
for pin in [getattr(board, p) for p in dir(board)]
if isinstance(pin, Pin) and pin not in exclude
]
unique = []
for p in pins:
if p not in unique:
unique.append(p)
return unique
for scl_pin in get_unique_pins():
for sda_pin in get_unique_pins():
if scl_pin is sda_pin:
continue
if is_hardware_i2c(scl_pin, sda_pin):
print("SCL pin:", scl_pin, "\t SDA pin:", sda_pin)
It results in hard crash, seemingly always after the same pair of pins:
Auto-reload is off.
code.py output:
SCL pin: board.A1 SDA pin: board.A0
SCL pin: board.A1 SDA pin: board.A4
SCL pin: board.A1 SDA pin: board.BUTTON1
SCL pin: board.A1 SDA pin: board.BUTTON2
SCL pin: board.A1 SDA pin: board.CKN
SCL pin: board.A1 SDA pin: board.D1N
SCL pin: board.A1 SDA pin: board.D8
SCL pin: board.A1 SDA pin: board.I2S_DIN
SCL pin: board.A1 SDA pin: board.MISO
SCL pin: board.A1 SDA pin: board.SDA
SCL pin: board.A3 SDA pin: board.A2
SCL pin: board.A3 SDA pin: board.D0N
SCL pin: board.A3 SDA pin: board.D10
SCL pin: board.A3 SDA pin: board.D2N
SCL pin: board.A3 SDA pin: board.D6
SCL pin: board.A3 SDA pin: board.ESP_CS
SCL pin: board.A3 SDA pin: board.ESP_RESET
SCL pin: board.A3 SDA pin: board.I2S_BCLK
SCL pin: board.A3 SDA pin: board.SCK
SCL pin: board.A3 SDA pin: board.SDIO_DATA2
SCL pin: board.A3 SDA pin: board.USB_HOST_DATA_MINUS
[11:33:11.633] Disconnected
[11:33:12.634] Connected
Auto-reload is off.
Running in safe mode! Not running saved code.
You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.
Press any key to enter the REPL. Use CTRL-D to reload.
I found that if I add USB_HOST_DATA_MINUS
to the exclude list then it does not hard crash and is able to successfully complete the pin search.