Skip to content

Instantly share code, notes, and snippets.

@vsizov
Last active July 2, 2025 13:25
Show Gist options
  • Save vsizov/645d08543609b5678ed2f1f6ec9ceb21 to your computer and use it in GitHub Desktop.
Save vsizov/645d08543609b5678ed2f1f6ec9ceb21 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <RTClib.h>
#define SDA1_PIN 21
#define SCL1_PIN 22
RTC_DS3231 rtc;
void setup() {
Wire1.begin(SDA1_PIN, SCL1_PIN); // Initialize Wire1
if (!rtc.begin(&Wire1)) { // Pass Wire1 to RTC
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(2025, 7, 2, 14, 30, 0)); // Set to current time
}
Serial.begin(115200);
DateTime now = rtc.now();
Serial.println(now.timestamp());
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment