-
Notifications
You must be signed in to change notification settings - Fork 413
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
Default pins for Serial/SPI/I2C not set properly #92
Comments
By default the first available I2C interface was used: So this is inconsistent with the PICO_DEFAULT_I2C_xxx_PINs unless there has been a recent update? |
The doc for Wire (I2C Master and Slave) is clear and concise. Adding the default values for sda and scl for the two I2C Devices would make it even better. |
Re: that picture, if you look at the full image you'll see that That said, using whatever defaults are in the SDK is the right thing to do, but not done yet. So some define needs to be added in the variant.h and it needs to be used in the object constructors for UART0/1, SPI0/1, and I2C0/1. |
Yes, this is the official RPi Pico pinout. Sadly the default colour scheme is subtle: |
:) I don't think I ever saw the official RPI foundation sheet until you pointed me to it just now. Weird, the GOOG gives everything but that document in my experience. Anyway, it is a bug and we should be using the board-specific (variant) defaults. For now, the workaround by @PreciousRoy0 is safe and will continue to work even after this is fixed. |
Each board supplier has it's own defaults, pins are set here in the SDK. So that makes things a bit easier as the #defines are all there for the variants. |
You would think the default #defines would be in the form RP2040_... but it seems other board suppliers have to use PICO_... Some board suppliers appear to have allocated illegal pins to some function... oh well! |
The existing SDK pin |
Yeah I've just been using .setSCL() and .setSDA() for every i2c connection and SPI.setRX... for SPI as a workaround for this. |
About this problem, I have a problem with U8x8lib in SPI, in my 256x64 oled display the HW SPI dont work, I need to set SW SPI, by set the pins to get it works, but its some kind of slow speed... |
What's the issue with the HwSPI? You might be able to tweak your SwSPI settings a little to get better preformance but the time may be better spent getting the HwSPI going. |
@vslinuxdotnet HW SPI is working for folks and there is even an optimized Adafruit GFX lib set: #69 |
The HW SPI works but note that the default SPI pins are:
|
EDIT. I have rewired "my current" Protoshield and changed my suggested schemes. I2C defaults to I2C0 on GP4-5. changed Some alternative schemes to suit Uno Shields. PWM can be done on every pin. I suspect PCINT too. Once that a preferred scheme is chosen it is straightforward to Please offer comments, opinions, improvements, ... The third option looks promising. I might wire up a Protoshield.
David. |
The pin name to GP and default interface mapping varies between board producers (Adafruit Pico mapping is different to RPi Pico, and Sparkfun Pro Micro). Arduino have not released their mapping so it is going to be guesswork what they will do but Dx to GPx seems sensible. The only common mappings so far seem to be TX0 and RX0 (DO, D1) to GP0 and 1 which is sensible. There are only 4 external ADC input pins, Sparkfun have mapped A0-3 to GP26-29 on the Pro Micro variant which seems very sensible, however the Pico uses GP29 for the supply voltage monitor and it is thus not easily available (but hackable with some PCB surgery to the ADC_REF pin). For UNO TFT shields I would map the TFT data bus to consecutive GP pins to prevent the need for data bit swapping. |
Yes, I agree. It would be nice to know what pin mapping an Arduino board proposes. Mostly for their choice of default Wire and default SPI pins. Then libraries and existing code will port very easily. Users do not mind configuring a CS pin. But you can't expect them to guess hardware MISO, MOSI, SCK pins. i.e. this comes down to defining PIN_I2C_SDA, PIN_SPI_MOSI, etc in variant/pins_arduino.h or variant/variant.h Wire.h and SPI.h libraries will use the default pins. But provide extra optional methods for changing pins e.g. Wire.setSDA() Regarding mapping the TFT data bus. Consecutive GP pins are handy but not essential. ARM chips have a barrel-shifter. |
Hi. Trying to get I2C to work with an SSD1306 display. At the moment it works on GP0 and GP1 but I need it to work on different pins. I am using Adafruit_SSD1306.h and the display is created using then following code:
I can see from your docs that I need to use
The docs indicate I have to do this before Wire.begin() but I do not have access to that. Is there a simple way to re-define the default pins. Sorry my c++ is very rusty and I have have tried various things like re-defining PICO_DEFAULT_I2C_SCL_PIN and PICO_DEFAULT_I2C_SDA_PIN but this has no impact. I need to create and configure Wire before passing it to Adafruit_SSD1306 display but cannot see how this is done. It's such a relief to be back in Arduino-land with the RP2040 :-) This chip is brilliant but the standard cpp SDK is really a steep learning curve. MicroPython is much easier but who wants to code in Python! I have been using Arduino for years and the work you have done here is really GREAT. Thank you very much. Regards Stuart |
Please note that I have only had Pico board for 1 day. I have a lot to learn. I suggest that pins_arduino.h should contain default I2C pins e.g. put in variant/generic/common.h for the moment:
and edit C:\Users...\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\1.0.3\libraries\Wire\Wire.cpp
Ideally default SDA1 and SCL1 macros should also go into variant This change makes Adafruit_SSD1306 library work ok for I2C. SPI displays "work" for Adafruit_ILI9341 but are appallingly SLOW. David. |
I've used one of the other pairs of I2C0 (4,5) by putting the calls in setup() just before the display.begin() call in the sketch.
Haven't looked at getting the library to use one of the I2C1 pairs, though. |
@stuartdd , what @blurfl did is the right thing for your issue. You don't need to call it immediately before Wire.begin, just anytime in your code. The setXXX calls just set a class variable that's only used in the begin() method. As for the whole "Which pinout to use" that's definitely on a per-board basis. The Arduino Connect Pico RP2040 board is not going to be the standard for the Rpi Pico board, for example, because the Arduino board has tons of IO hooked directly to onboard sensors and the onboard ESP32. And the |
@prenticedavid |
Thanks @blurfl and @earlephilhower seems so simple when you know what you are doing. Regards Stuart |
Arduino has released its MBED_PICO Core. variant/pins_arduino.h say:
So they make no attempt to support multiple SPI, Wire, ... I suggest that we follow the same plan for the Pico board. Which should make existing Arduino programs port painlessly to the Pico. But still allow custom use of different pins and also spi1, i2c0 if required. Yes, Bodmer was correct. There is no GPxx to Dxx mapping. There are no Dxx symbols. GP23 is just a plain number 23. David. |
A0-3 are defined as GP26-29 as anticipated. |
Using the official Raspberry Pi Pico datasheet and the Adafruit Feather RP2040 schematic, set the default pins for peripherals to match. Fixes #92
#103 implements the default pinout used on the RPI Pico datasheet and the Adafruit Feather RP2040 schematic. These may not match the Arduino MBED core's chosen ones. My eyeballing seemed to show they chose non-RPI Pico pinouts for the SPI0 device. I can't say why that would be, but I'll stick w/the RPi guys' setup unless a consensus forms around others. Anyone who can give it a try and report back, would be much appreciate. |
Using the official Raspberry Pi Pico datasheet and the Adafruit Feather RP2040 schematic, set the default pins for peripherals to match. Fixes #92
Hi, I havo a code like this where i need to controll a rover with a PCA9685 and a vl53l0x for obstacle avoidance. P.S. all my code was working good on an Arduino Nano, but i try to pass to Pico for a more power and memory space
|
First of all, I would not use the Adafruit PWM servo driver, it doesn't know about the RP2040. There is a Secondly, you're assigning invalid pins to the I2C ports. The RP2040 can't place them anywhere, only at specific pins as shown on the graphic in the docs. The Wire = I2C0 => SDA can be |
Also, you can enable full debugging in the IDE which will print error messages to the Serial port when illegal pins are selecter, amongst other useful things. |
Thanks a lot, i will try |
I was having issues getting any i2c sensor to work so after a lot of testing and searching i came across this issue witch is unrelated but did help me https://github.com/earlephilhower/arduino-pico/issues/38#issuecomment-808835731 the tester that was pointed out also did not work.
no i saw that PICO_DEFAULT_I2C_SCL_PIN and PICO_DEFAULT_I2C_SDA_PIN ar defined but when correctly connected it does not work.
i fixed this by setting the pins at the beginring of my program
Wire.setSCL(PICO_DEFAULT_I2C_SCL_PIN);//gp5 Wire.setSDA(PICO_DEFAULT_I2C_SDA_PIN);//gp4
now i don't know if this is an issue but seeing that they are defined you would expect it to use them if not explicitly told to use different pins right? I figured i would let you know.
The text was updated successfully, but these errors were encountered: