Conflict with u8g2 and sensors on I2C

I have suvccesfully displayed messages on a 128x32 I2C OLED using the u8g2 library and the following constructor on an UNO:

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=/ SCL, / data=/ SDA, / reset=*/ U8X8_PIN_NONE);

but as soon as I request values from a sensor on the same I2C bus the screen freezes. The sketch carries on as I get serial output.

I've tried the other constructors with no output (including HW), tried defining the address as another suggested (u8g2.setI2CAddress(0x78);//I2C address multiplied with 2 (the lowest bit must be zero)) but still nothing.

Its doubling frustrating as I had it working on a U8 library and can't get that going now either!

Any others got over this problem, if so how?

Many of the Ebay SSD1306 displays do not ACK the I2C properly.
Most libraries have an option to handle these badly configured displays.

A properly configured SSD1306 will work on the same bus with any other proper I2C devices. The Wire.h library should work fine.

If your SSD1306 is non ACKing, I suggest that you put it on different pins to the regular hardware I2C devices.

David.

Hi

First check, whether your display works with U8g2 HW I2C (without any other I2C device on the bus). If the OLED does NOT work with the u8g2 hardware constructor, then (as David mentioned) the OLED is broken and does not support Hardware I2C.
In such a case you can not use the two devices on the same bus. However, you could use any other pair of pins for the SW I2C for the display.

If your display works as with HW I2C, then there should be a good chance that the OLED works together with any other I2C devices on the bus. The only other problem might be, that the library/code for the other I2C does not use the more modern "beginTransmission/endTransmission" commands of the Arduino IDE.

The u8g2 FAQ also addresses this question:

Oliver

Thanks for the pointers both. I had seen that post but didn't understand the implication. After testing it seems I have a non-acknowledging part as it only works with SW I2C, which is a bit frustrating, so I'll try creating a SW bus for the screen and put the sensors on the hardware bus.

If it is essential to use the library u8g2, I use Wire.end() and Wire.begin() as example below:

Wire.end();

u8g2.begin();
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_inr16_mf);
u8g2.setCursor(0, 32);
u8g2.print(luminance);
} while ( u8g2.nextPage() );

Wire.begin();

This worked for me very well! Thanks a lot!!
Is there a reason why this workaround needs to be used with the u8g2 library? After all the i2c display I am using should work with all the other i2c sensors in perfect harmony right?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.