Yes, there are a few pins on the Pico that’re designed specifically to be the default pins for SPI/I2C. And in most Micropython builds it is configured so that when you don’t specify pins to use for an SPI/I2C bus pins 8 and 9 for data and clock automatically get used.
However, as Python is an interpreted language rather than compiled into OP codes for some specific hardware like C for a PIC chip, you can actually modify the UF2 firmware package generated to use different pins as the defaults instead without needing to specify it in your script:
Thanks for that Will tuck this info away in the old grey thing until I decide to try my hand at a Pico. One of these days I will do it. Have got a couple but haven’t tried in earnest yet.
The RP2040 is an amazing micro and very flexible in pin assignments. Each GPIO pin has multiple functions determined by the software.
The micropython library I was using on a Pico defined the Serial Peripheral Interface as SPI(0). I wondered what pins it was using so I could get the wiring right.
That was when I discovered the difference between the Raspberry Pi documentation and what I thought the Micropython defaults were. The python code I listed above is an easy and simple way of determining the pins when not defined in the library.
Thought it may be of use to someone else and is a ‘gotcha’ to check it your code does not work. Could just be a simple wiring error.
For reference re the Micropython defaults in the i2c and SPI libraries.
Section 3.6 gives the i2c generic usage, and also details the Micropython ‘defaults’ for i2c.
See Table 2 on page 16
Similarly Section 3.7 gives the generic SPI usage, and also the Micropython ‘defaults’ for SPI
See Table 3 on page 16
If you really want to dig into the RP2040 microprocessor on the Pico boards try this…
It is VERY detailed, is 639 pages long (i,e, 20+ pages on i2c configuration and protocol management), and brain-hurting , so it is way easier to take the setup provided by the authors of the Micropython libraries.
And you can get our latest projects and tips straight away by following us on: