adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.74k stars 963 forks source link

Custom i2c pins for ESP32 #260

Closed AKTanara closed 1 year ago

AKTanara commented 1 year ago

ESP32 + SSD1306_i2c I want to use custom i2c pins. Since wire library has Wire.begin(SDA,SCL,FRQ) or Wire.setPins(SDA,SCL) functions but it is not until within setup() function that I can run them and the wire object has already passed to the Adafruit_SSD1306 constructor, I do not know how to pass custom pin numbers to the instance of wire that I'm passing to the constructor.

AKTanara commented 1 year ago

I think I have found my solution:

TwoWire myWire = TwoWire(0);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &myWire, OLED_RESET);

void setup() {
    myWire.begin(13, 14);
    ......

I'll test it on HW tomorrow and will report my result here. Meanwhile I appreciate any comments on this solution.

AKTanara commented 1 year ago

Worked like a charm, even didn't need to create a custom TwoWire object:

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
    Wire.begin(13, 14);
    ......

But in my case the address suggested by the library was not correct. My display is 128x64 and the address is: 0x3C Thanks for the great Library and keeping it alive.