Two devices with I2C and an Arduino Uno...

I'm trying to make a clock with a DS3231 (I2C) and an OLED 1.3" IIC (also I2C) I am using the U8glib library and the DS3231 library. Now to my problem... I have hooked up both devices to the SDA and SCL pins on my Arduino Uno with separate 5V and GND pins. I have set up this code:
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C 128x64(col2-col129) SH1106,Like HeiTec 1.3' I2C OLED
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
#define MENU_ITEMS 2
char *menu_strings[MENU_ITEMS] = {"HELLO","WORLD"};
bool check = false;

void draw(void) {
if(!check) {
uint8_t i, h;
u8g_uint_t w, d;
u8g.setFont(u8g_font_fub17);
u8g.setFontRefHeightText();
u8g.setFontPosTop();

h = u8g.getFontAscent()-u8g.getFontDescent();
w = u8g.getWidth();
for( i = 0; i < MENU_ITEMS; i++ ) {
d = (w-u8g.getStrWidth(menu_strings[i]))/2;
u8g.setDefaultForegroundColor();
u8g.drawStr(d, i*h, menu_strings[i]);
}
check = true;
} else {
menu_strings[0] = rtc.getTimeStr(1);
menu_strings[1] = rtc.getDateStr(1);
check = false;
}
}

void setup(void) {
rtc.begin();
}

void loop(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );

delay(10000);
}
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C 128x64(col2-col129) SH1106,Like HeiTec 1.3' I2C OLED
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
#define MENU_ITEMS 2
char *menu_strings[MENU_ITEMS] = {"HELLO","WORLD"};
bool check = false;

void draw(void) {
if(!check) {
uint8_t i, h;
u8g_uint_t w, d;
u8g.setFont(u8g_font_fub17);
u8g.setFontRefHeightText();
u8g.setFontPosTop();

h = u8g.getFontAscent()-u8g.getFontDescent();
w = u8g.getWidth();
for( i = 0; i < MENU_ITEMS; i++ ) {
d = (w-u8g.getStrWidth(menu_strings[i]))/2;
u8g.setDefaultForegroundColor();
u8g.drawStr(d, i*h, menu_strings[i]);
}
check = true;
} else {
menu_strings[0] = rtc.getTimeStr(1);
menu_strings[1] = rtc.getDateStr(1);
check = false;
}
}

void setup(void) {
rtc.begin();
}

void loop(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );

delay(10000);
}
In which I've tried to have the code talk to one of the devices after another, 10 seconds apart... Which works, but the display seems to have some problems with that. It displays the two lines of text cut off, I'll add a picture. Whenever I remove the lines where the code interacts with the RealTimeClock module, the display works fine... I've read about adresses overlapping, but I don't know how to deal with that, or if that's even the case here. I'd be delighted if anyone had an idea and could maybe help! Have a nice day!
No description
5 Replies
Gammos
GammosOP2w ago
No description
Gammos
GammosOP2w ago
Here's another picture of the cut-off text
Maverick
Maverick2w ago
Are you sure the driver is SH1106?
Gammos
GammosOP2w ago
Not 100%, it just says 1.3 IIC on the back...
Maverick
Maverick2w ago
Try to find out, or try SSD1306 or Sh1107 and see if it works.

Did you find this page helpful?