I am currently trying to get a SSD1315 oled screen to display the time from an RTC however when the oled is initialized and set to begin the RTC starts showing an incorrect date.
My setup is a Seeed studio sensor kit shield on top of a data-logger shield on an Arduino Uno R3.
The data-logger shield looks like this one Logging Recorder Data Logger Module Shield XD-204 for Arduino UNO SD Card,Shield Board but not branded Keyes. It has an SD card reader and an RTC (I believe it is a DS1307). I am using the U8x8 library for the screen and the RTClib for the RTC though I have tried with a different RTC library with the same result.
#include <Arduino.h>
#include <Wire.h>
#include <U8x8lib.h> //Screen
#include <RTClib.h> //RTC
U8X8_SSD1306_128X64_NONAME_HW_I2C Oled(U8X8_PIN_NONE); //As used by Grove
RTC_DS1307 rtc;
bool oled = true; //When true screen is on but time is bugged. When False time is correct.
void setup() {
Serial.begin(57600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (oled) {
Oled.begin();
Oled.setFlipMode(true);
}
}
void loop() {
DateTime now = rtc.now();
Serial.println(now.timestamp());
if (oled) {
Oled.setFont(u8x8_font_chroma48medium8_r);
Oled.setCursor(0, 0);
Oled.println(now.timestamp(2)); //Date
Oled.println(now.timestamp(1)); //Time
}
delay(1000);
}
Googleing has shown other people with the same issue but there is either no fix or the fix is something I have tried and has not worked.