Skip to content
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

Changing default I2C HW pins on Raspberry Pi Pico RP2040 #2289

Open
MIKHANYA opened this issue Nov 2, 2023 · 5 comments
Open

Changing default I2C HW pins on Raspberry Pi Pico RP2040 #2289

MIKHANYA opened this issue Nov 2, 2023 · 5 comments

Comments

@MIKHANYA
Copy link

MIKHANYA commented Nov 2, 2023

I'm using Raspberry Pi Pico with earlephilhower arduino-pico core.
And screen SSD1309_128X64 on 12,13 Pins. And this initialization line in the code U8G2_SSD1309_128X64_NONAME0_F_HW_I2C u8g2(U8G2_R0)
In Arduino IDE, I decided to simply change the default I2C pins in the file. From default 4,5.
Users/User/Library/Arduino15/packages/rp2040/hardware/rp2040/3.6.0/variants/rpipico/pins_arduino.h

// Wire
#define PIN_WIRE0_SDA  (12u)//(4u)
#define PIN_WIRE0_SCL  (13u)//(5u)

But in PlatformIO I can't do that way, can you tell me how to change them in other way ?

@olikraus
Copy link
Owner

olikraus commented Nov 2, 2023

There is a command for this, see the reference manual.

@larrybud2004
Copy link

But in PlatformIO I can't do that way, can you tell me how to change them in other way ?

Did you figure this out? I can't get this to work with Earl's core. Trying:

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(PIN_WIRE0_SCL, PIN_WIRE0_SDA, U8X8_PIN_NONE);

which translates to pin 5, 4 respectively, but no output on the display. I switch back to the standard core, and change to PIN_WIRE_SCL, PIN_WIRE_SDA, which are the same values (5,4) and the display works.

@egnor
Copy link

egnor commented Apr 13, 2024

What you need to do is configure Wire (the Arduino I2C layer) with your pins, and NOT pass them to U8g2. See the documentation for Earle Philhower's core's I2C interface; you need to do something like this:

Wire.setSDA(your_sda_pin);
Wire.setSCL(your_scl_pin);
U8G2_SSD1309_128X64_NONAME0_F_HW_I2C u8g2(U8G2_R0);  // do NOT pass SDA or SCL pins, you MAY pass reset pin
u8g2.begin();

This is because the code in U8g2 to initialize I2C doesn't know how to supply SDA and SCL pins using that core. (In fact, the ONLY Arduino-based system it knows how to do that on is the ESP32. This should probably be clarified and/or improved.)

It's important NOT to pass SDA and SCL pins to the constructor on the RP2040 (normally it should be harmless if you've otherwise configured Wire correctly) because of another unfortunate interaction which I'll write up in a separate bug...

@olikraus
Copy link
Owner

I actually like the solution with setSDL and setSCL.
Thanks for providing this.

@olikraus
Copy link
Owner

see also: #2425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants