Модуль HW-111 c чипом DS1307 запускается программой
#include <RtcDS1307.h>
RtcDS1307<TwoWire> rtc(Wire);
void setup ()
{
Serial.begin(115200);
Serial.print("compiled: ");
Serial.print(__DATE__);Serial.print(",");
Serial.println(__TIME__);
rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();Serial.println("11");
compiled +=40;
if (!rtc.IsDateTimeValid()){
if (rtc.LastError() != 0){
Serial.print("RTC communications error = ");
Serial.println(rtc.LastError());
}
else{
Serial.println("RTC lost confidence in the DateTime!");
rtc.SetDateTime(compiled);
}
}
if (!rtc.GetIsRunning()) {
Serial.println("RTC was not actively running, starting now");
rtc.SetIsRunning(true);
}
RtcDateTime now = rtc.GetDateTime();
if (now < compiled) {
Serial.println("RTC is older than compile time! (Updating DateTime)");
rtc.SetDateTime(compiled);
}
else if (now > compiled) {
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled) {
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
rtc.SetSquareWavePin(DS1307SquareWaveOut_Low);
} // The end of setup
void loop ()
{
if (!rtc.IsDateTimeValid())
{
if (rtc.LastError() != 0){
// we have a communications error
// see https://www.arduino.cc/en/Reference/WireEndTransmission for
// what the number means
Serial.print("RTC communications error = ");
Serial.println(rtc.LastError());
}
else{
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}
}
RtcDateTime now = rtc.GetDateTime();
printDateTime(now);
Serial.println();
delay(10000); // ten minutes //seconds
} // The end of loop
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[25];
char daysOfTheWeek[7][4] = {"Sun","Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
snprintf_P(datestring,
countof(datestring),
PSTR("%3s, %02u.%02u.%04u %02u:%02u:%02u"),
daysOfTheWeek[dt.DayOfWeek()],
dt.Day(),
dt.Month(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
/*Days=monthDay0 +(timeClient.getHours()*1.+timeClient.getMinutes()*1./60+timeClient.getSeconds()*1./3600)/24;
*/
float Days=dt.Day()+(dt.Hour()*1.+dt.Minute()*1./60+dt.Second()*1./3600)/24;
Serial.print(datestring);Serial.print(" ");Serial.print(Days,8);
}```
Время определяется и выводится правильно с точностью до секунды совпадающее с временем на ПК. Но после отсоединения от компьютера и последующего включения сообщаемое время продолжается от момента выключения с отставанием от времени на ПЛ.