Minimalist and high-contrast documentation focusing on hardware wiring and core logic.
I2C uses only two data lines (SDA/SCL) plus power. Multiple I2C devices (like the OLED and RTC) **share** these four pins by connecting them in parallel.
**GND** (Grey) β **GND** (OLED, RTC)
**5V** (Red) β **VCC** (OLED, RTC)
**A5** (Blue) β **SCL** (OLED, RTC)
**A4** (Green) β **SDA** (OLED, RTC)
This code reads the time from the RTC module and displays it on the OLED. Libraries needed: **Wire, RTClib, Adafruit\_GFX, Adafruit\_SSD1306**.
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
RTC_DS3231 rtc;
Adafruit_SSD1306 display(128, 64, &Wire);
void setup() {
Wire.begin();
// Check if RTC is available and running
if (! rtc.begin()) {
// Optionally display an error message here
}
// Zeit einmalig setzen (danach auskommentieren!)
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop() {
DateTime now = rtc.now();
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 20);
// HH:MM:SS
if (now.hour() < 10) display.print("0");
display.print(now.hour());
display.print(":");
if (now.minute() < 10) display.print("0");
display.print(now.minute());
display.print(":");
if (now.second() < 10) display.print("0");
display.print(now.second());
display.display();
delay(500);
}
Vector diagram showing the parallel I2C connection from the Arduino Nano to the OLED Display and the RTC DS3231 Module. Wires are color-coded: **Grey (GND)**, **Red (5V)**, **Blue (SCL)**, **Green (SDA)**.