HI everyone,
I am currently trying to use a DS3231 external RTC on my M5Stack core grey.
I have tried many different libraries but problem remains the same :
- I know the RTC is seen. I have run I2C scan and my DS3231 RTC has the 0x57 address.
- I am able to set the current time into the RTC.
- I am able to read the RTC. But the info displayed on the Lcd is not correct or maybe the reading is wrong. The seconds displayed are chaotic and the minutes go down when the seconds reach 60...
For example :
Here, for this exemple, I am using the RTCLib library from Adafruit.
Here is my code :
#include "RTClib.h"
#include <M5Stack.h>
#include <Wire.h>
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(9600);
M5.begin();
Wire.begin();
if (! rtc.begin()) {
M5.Lcd.println("Couldn't find RTC");
Serial.flush();
abort();
}
//Adjust the time to the current one
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop () {
//Getting the time
DateTime now = rtc.now();
//Printing it on M5 Lcd
M5.Lcd.print(now.year(), DEC);
M5.Lcd.print('/');
M5.Lcd.print(now.month(), DEC);
M5.Lcd.print('/');
M5.Lcd.print(now.day(), DEC);
M5.Lcd.print(" (");
M5.Lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
M5.Lcd.print(") ");
M5.Lcd.print(now.hour(), DEC);
M5.Lcd.print(':');
M5.Lcd.print(now.minute(), DEC);
M5.Lcd.print(':');
M5.Lcd.print(now.second(), DEC);
M5.Lcd.println();
delay(3000);
}
My question are :
- what is wrong with my code ?
- while scanning for I2C adress, I can find 4 different adresses. I know RTC is 0x57 because when disconnecting the DS21 this one disapear frome the scan. But is it possible tha the other devices scanned interfere with my RTC ?
- should I specify which adress of the I2C to read ? something like Wire.requestFrom(0x57, ...) ?
Thank you for your help, I am stuck here for 2 days...!
Best wishes to everybody for the new year.
Morgan