olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
5.08k stars 1.05k forks source link

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

Open MIKHANYA opened 11 months ago

MIKHANYA commented 11 months ago

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 commented 11 months ago

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

larrybud2004 commented 9 months ago

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 commented 5 months ago

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 commented 5 months ago

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

olikraus commented 5 months ago

see also: https://github.com/olikraus/u8g2/issues/2425

ChitoKim commented 3 months ago

You can do the same thing on PlatformIO, just the directories are different. pins_arduino.h things are inside ~.platformio\packages\framework-arduinopico\variants. Otherwise, you can set them on .ino file with setSDA, setSCL things.

Plus, if you use 2nd I2C, you need to define macro "WIRE_INTERFACES_COUNT 2". In PlatformIO you can define such macros in your platformio.ini

스크린샷 2024-07-02 181222