U8G2 + DS3231 clash on I2C

Hi guys!

I’m building controller for my reef aquarium on Arduino Pro Mini and have a problem with I2C.
I connected OLED display and DS3231 to the appropriate SDA and SCL ports.

Screen had been worked perfect until I started to request time from rtc.

So, in the next example if I uncomment time = rtc.getTime(); the screen stops working.

What I’m doing wrong?

#include <Wire.h> 
#include <U8g2lib.h>
#include <DS3231.h>

U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
DS3231  rtc(SDA, SCL);
Time  time; 

void setup()
{
  Wire.begin();

  u8g2.begin();
  rtc.begin();
  rtc.setTime(23,59,59);
  delay (1000);

//  time = rtc.getTime();

….

I wonder why the DS3231 requires the SDA and SCL arguments. Maybe this is a software I2C vs. hardware I2C issue: Either both devices are accessed via software I2C or both have to be access via hardware I2C. Mixing the access methods does not work.

Try to put u8g2 into software I2C by using this constructor:

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

Will this work?

Oliver

Hi Oliver!
Thank you for your advice.
Unfortunately with SW constructor screen doesn't work at all.

Should I use Wire and its beginTransmission(), endTransmission(), etc?

Which of the many DS3231 libraries are you using? Go to Sketch->Include Library->Manage Libraries... and put DS3231 in the 'filter' box. Look for which one is marked INSTALLED.

AGVR:
Hi Oliver!
Thank you for your advice.
Unfortunately with SW constructor screen doesn't work at all.

Should I use Wire and its beginTransmission(), endTransmission(), etc?

Wire commands are used within u8g2 itself. You do not need to call them.
If the SW constructore does not work, then something is wrong with your SCL and SDA macros.You may use the pin number instead.

Oliver