olikraus / u8g2

U8glib library for monochrome displays, version 2
Other
4.91k stars 1.03k forks source link

2 Hardware I2C SSD1306 screens cannot run at the same time, HELP! HELP! HELP! #2273

Open mason334 opened 9 months ago

mason334 commented 9 months ago

First of all, I love u8g2.

I am using a ESP32S3 board, with two SSD1306 OLED screens connected.

Here are my constructors: U8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, / reset=/ U8X8_PIN_NONE, / clock=/ 20, / data=/ 21);
U8G2_SSD1306_96X16_ER_F_HW_I2C u8g3(U8G2_R0, / reset=/ U8X8_PIN_NONE, / clock=/ 2, / data=/ 42);

Well, I can only get one screen to work at a time. If I power the 2 screens up at the same time, none of them can work properly.

When I switched one of them to software I2C, the 2 screens can work at the same time.

But software I2C has very low fps, around 5FPS. Hardware I2C can get me to 70FPS.

So, it looks like I cannot run 2 Hardware I2C screens at the time.

Is there a way to run 2 Hardware I2C screens at the time?

Thanks for any comments and suggestions.

olikraus commented 9 months ago

The problem is the pin remapping: U8g2 will execute a Wire.begin() only if you call u8g2.begin(). As arguments for this Wire.begin() ESP allows the pins for the bus communication. Once you call the second u8g2.begin() this pin configuration is overwritten, so only the display with the second u8g2.begin() will work.

It might work if you execute Wire.begin(21, 20) before u8g2.sendBuffer() and Wire.begin(42, 2) before u8g3.sendBuffer().