← index #13536Issue #17562
Off-topic · high · value 2.243
QUERY · ISSUE

RP2040 I2C bus breaks if pins are changed at runtime

openby desultoryopened 2024-01-27updated 2024-02-12

MicroPython v1.22.1 on 2024-01-05; Raspberry Pi Pico with RP2040

If I attempt to re-init the bus on another set of pins, things break and cannot recover until I do a full hardware reset:

>>> from machine import Pin, I2C
>>> a = I2C(1, freq=400000, scl=27, sda=26)
>>> a.readfrom_mem(118, 0xA1, 1)
b'K'
>>> a = I2C(1, freq=400000, scl=3, sda=2)
>>> a.readfrom_mem(118, 0xA1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO
>>> a = I2C(1, freq=400000, scl=27, sda=26)
>>> a.readfrom_mem(118, 0xA1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO

I'm not sure how else I can recover from this other than unplugging it and plugging it back in, soft resets do not correct the issue.

CANDIDATE · ISSUE

docs: I2C default pins 4,5 not 8,9 for the RP2 port

openby BobSteinopened 2025-06-25updated 2025-09-20
docs

Documentation URL

https://github.com/micropython/micropython/blob/6fee099cae58644ea49ca0f470e9cb00a7da8f29/docs/rp2/quickref.rst?plain=1#L339

Description

In the quickref for RP2 (Raspberry Pi Pico family) it has a line of code under Hardware I2C bus:

i2c = I2C(0) # default assignment: scl=Pin(9), sda=Pin(8)

Unless I'm missing something I'm pretty sure this should be:

i2c = I2C(0) # default assignment: scl=Pin(5), sda=Pin(4)

That would agree with the board pinout diagram -- see the dark blue areas. It also agrees with an actual device that I just wired up. I haven't found this association anywhere else yet. It might be in the RP2350 datasheet but I got lost in there.

Caution about pin number confusion. The id numbers passed to the machine.Pin constructor are NOT chip pin numbers or board pin numbers. They refer to GPIOnn aka GPnn signal names. So Pin(5),Pin(4) refer to GPIO5,GPIO4 aka GP5,GP4.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied