-
-
Notifications
You must be signed in to change notification settings - Fork 212
Raspberry Pico SPI and I2C pins #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Pico-R3-A4-Pinout.pdf |
I know about the pins I can use. But how to configure? |
This is an example of using the I2C to drive an LCD |
@Grumpy-Mike What have the code todo with ArduinoCore-Core? |
Don't understand the question sorry. |
This is my understanding | miss-understanding. I have been using the code from earlephilhower/arduino-pico with some success. I wanted to use the official Arduino release and followed the link to this repo. Initial Process (Not using README.md):
There is no data being sent to the display. I tried GP0/GP1, GP4/GP5, GP12/GP13, GP17/GP16, GP21/GP20 no luck on any. How do I define (within a Sketch) the Pico pins used by the Wire API for SCL and SDA? Second Process:
I gave up and went back to using earlephilhower/arduino-pico So Three questions I have!
I have to say that I am VERY excited about using Arduino code for my Pico. I do not wish to seem critical but at the moment this is not usable without help from the developers. That earlephilhower/arduino-pico API adds setSCL(n) and setSDA(n) to the Wire API and it just works. Please help me understand the above issues. Regards Stuart |
The code of earlephilhower/arduino-pico is based on c++ sdk of Arduino. This core is based on Mbed. |
Hi Stuart It is working with the mbed Arduino and Adafruit graphics libs |
The official hardware documentation says following. SPI0 I think the board definition should follow the official docs as a reference. There is a need a function to set alternative pins for UART, SPI, I2C |
I forgot, we need some standard pins for I2C 1, SPI 1 and UART 1 |
Hi everyone,
Keep in mind that selecting the wrong pins (if the mux is not possible) will raise a runtime error (with the usual "morse-like" led blink). |
The hardware docs of pico the default pins are marked, see screenshot from the doc. |
@sstaub as marked I meant the silkscreen on the board itself, which we always considered the "golden standard" for naming. |
As this post covers issues about the Pico I2C pins I'm querying a related issue, which has to do with PeripheralNames.h found in mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040 folder. I noticed that the default pins for MBED_I2C0 is p28, p27 but p28 is GND (as per Pico pinout diagram). |
@Gerriko Yes, but you have to look at the pinout of the RP2040, not the Pico. P28 is GPIO17. |
@sebromero appreciate the feedback. I see it now... I should've read @facchinm 's comment (above the pinout graphic), which now makes sense. |
The standard pins should follow https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/pico.h |
Hello guys, Is there an easy way to swap the I2C pin definition to match I2C0 in place of I2C1? |
I noticed that in pins_arduino.h (found in mbed_rp2040/2.0.0/variants/RASPBERRY_PI_PICO) it has I see (from above post) this is controlled within the Wire library (wire.h): EDIT: So SDA0/SCL0 can be used but not sure how to include both. |
Learn by doing... So I modified the pins_arduino.h file to the following
Note that I used GP20 and GP21 for SDA0 & SCL0 as GP4 & GP5 assigned for SPI I then changed I just tested using both I2C ports with 2 Wii nunchucks. It's pretty cool to have both working with the same I2C address. |
Like mentioned some times before, The default pins for SPI and I2C should follow the official documentation and code of the Raspi org. Making an Arduino specific pin routing is ok for the Arduino products, but not for the Raspberry Pico because it will confuse the users. There is no default assignment for SPI1, I2C1 and UART1(Serial2) so default pins can assigned without restriction. |
I can only talk from experience. Confusion is typically caused by
assumption and poor and/or lack of documentation.
In my case I have not spent much time studying the Raspi org docs so I had
no preconceived view as to which default pins should be used for I2C, SPI
or UART. But then for Arduino the documentation is not ready yet. So in
this case I can see that many would refer to Raspi docs on the assumption
this would work.
So you are right, it would help interoperability if the Arduino default
pins are aligned to Raspi. However there may well be others constraints
that make this difficult and thus does not have to be a requirement.
Looking at the core Arduino code for pico it looks like you would need to
at least assign default pins numbers for I2C1/SPI1 etc. to enable the
function.
Then it's up to the user to change using the manual assignment command if
the want to use.
At least from my point of view, I know that it is now possible to use the 2
x I2C ports in the same sketch once the core library is modified.
…On Fri 23 Apr 2021, 08:40 Stefan Staub, ***@***.***> wrote:
Like mentioned some times before, The default pins for SPI and I2C should
follow the official documentation and code of the Raspi org. Making an
Arduino specific pin routing is ok for the Arduino products, but not for
the Raspberry Pico because it will confuse the users. There is no default
assignment for SPI1, I2C1 and UART1(Serial2) so default pins can assigned
without restriction.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#194 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC23YAQ4OQDKXRPBZ5FNYGLTKEP5DANCNFSM425PVFZQ>
.
|
Confusing is that |
Yes that's true. It would be helpful to match Wire with I2C0 and Wire1 with
I2C1.
…On Fri 23 Apr 2021, 09:18 Stefan Staub, ***@***.***> wrote:
Confusing is that WIRE is routed to I2C 1.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#194 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC23YASWNLAK4N25HVPSNETTKEUMZANCNFSM425PVFZQ>
.
|
Thanks for the tips @Gerriko ;) this is working nicely |
@facchinm I agree, making the pins configurable via constructor is an okay option which avoids changing the core API. I do think though that it would be a good idea to stick to the default pin assignment from https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/pico.h . Accordingly I'd match Wire with the I2C0 and Wire1 with |
I have a ZS-042 DS3231 RTC module connected to the Pico on pins 6 and 7. I2C Scanner shows no devices found. Using MicroPython:
Works perfectly and as expected. What should I change in the Arduino I2C Scanner program to get it to work? UPDATE: I tested it with earlephilhower/arduino-pico with the module connected to pins 4 and 5, and I2C Scanner works as expected |
Hi,
|
I have yet to try this as I forgot to bring my pullup Rs at home. Thanks! |
My question concerns which SPI pins can be used with the arduino::MbedSPI(...) constructor. I tried to find out with a small test program, which resulted in the blinking LED 4 short 4 long, and now I can't upload anymore.
Help, please! Thank you. Jean-Marc |
@ZinggJM It's because your firmware immediately crashes when the board boots. Put the board in bootloader mode and upload again:
|
Thank you for the quick answer. I think I tried this, but I have to wait again during compilation. Which pins could I try for the second SPI channel? |
Sketch uses 14000 bytes (0%) of program storage space. Maximum is 16777216 bytes. Doesn't seem to work as serial channel. |
And you no longer can upload programs. And don't know which pins can be used for SPI. Is it possible to use an ST-Link-V2 to clear the program, or would it cause more damage? |
The blinking stops, but the Pico is put into USB memory mode, and doesn't accept program upload. Thank you for any help. |
@ZinggJM try the following and see if it works Create a empty program (just the setup and loop and nothing more) That should fix the pico not working |
Ive also ran into this issue where it would crash on start I had it happen trying to access my mpu6050 (pins 2, 3) |
Thank you @MNS26. Yes, I found this solution also. But the easy solution is to exit and restart the Arduino IDE, to make sure no serial line is selected, then put the pico to usb storage mode, and then compile and upload. Upload seems to copy to usb storage if no serial line is selected. The SPI pins can be selected according to the pinout diagram. Each optional SPI pin is indicated with one of the two possible SPI channels. But pins of the two channels can't be mixed. |
@ZinggJM great to hear you fixed it. Like you said mixing I2C0 and I2C1 pins will cause a mbed crash, i made sure to check the pins for I2C1 before using them. The arduino I2C scanner code (with some tweaks) does work but the moment i modify it to write to the mpu6050 it crashes mbed |
The modification to the example code was.
And wherever |
It would also be nice if you could follow the lead of Earl Philhower. He added two functions setSDA() and setSCL() to the Wire library. Here is when the issue came up for him. Here is his documentation for these functions. My reason for suggesting this is it would be nice to have as much compatibility with both platforms as possible. The MBED board library is now the "official" one for the Pico, but the other one has a lot of users that would like the compatibility so they can port over to the MBED board library. |
Just as a follow up for future folks searching this out. I wanted to use both I2C channels on the Pico but struggled when any reference to Wire1 was made in my code. I think the overall consensus in this thread is that since there are no default pins assigned to I2C1 SDA and I2C1 SCL then the pins_arduino.h file shouldn't include them. So if you need to use both I2C channels on the Pico as I did here is how to do it: Find the pins_arduino.h file for your Pico board. On my M1 Mac using Arduino IDE 2.0 the file was found in Library/Arduino15/packages/arduino/hardware/mbed_rp2040/(VERSION NUMBER)/variants/RASPPBERRY_PI_PICO/pins_arduino.h Add or modify the following lines: // Wire
#define PIN_WIRE_SDA (4u)
#define PIN_WIRE_SCL (5u)
#define PIN_WIRE_SDA1 (2u)
#define PIN_WIRE_SCL1 (3u)
#define WIRE_HOWMANY (2)
#define I2C_SDA (digitalPinToPinName(PIN_WIRE_SDA))
#define I2C_SCL (digitalPinToPinName(PIN_WIRE_SCL))
#define I2C_SDA1 (digitalPinToPinName(PIN_WIRE_SDA1))
#define I2C_SCL1 (digitalPinToPinName(PIN_WIRE_SCL1)) Note that 4u and 5u (pins 6 and 7 on the Pico board) are the default I2C0 pins. There is no default for the I2C1 pins, and I just choose the two pins above (pins 4 and 5) since they are listed on the graphic found above as I2C1 and are not otherwise special, they aren't default pins for any other function and they aren't analog input pins). You can change these to whatever suits your project though. With those changes I was able to read from 2 AS5600 magnetic encoders which have a hard-wired I2C address, making them unable to co-exist on the same I2C channel. Hope this is useful for someone in the future. It would have saved me a day of searching :-) |
His approach is similar to ARDUINO_NANO33BLE |
Raspberry Pico
How to determine which pins are used for SPI, and how to do this for SPI1. Are there any standard pins?
Same for I2C. Is there any API (with examples)?
The text was updated successfully, but these errors were encountered: