1

I try to change time on windows to test my programing condition but RTC usually keep old time when i change time on windows and re-upload the code . I'm also removing the battery and cut the power it is still not working.

here is my set up and library is https://github.com/adafruit/RTClib

void setup () {
 
#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif
 
  Serial.begin(9600);
   Serial.println("ESP start...");
  pinMode(Ledpin, OUTPUT);
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer, HIGH);
  
  
  delay(3000); // wait for console opening

if (! rtc.begin()) {
  Serial.println("Couldn't find RTC");
 while (1);
}

 
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
   
}
2
  • 4
    Does it print “RTC lost power, lets set the time!”? Commented Oct 6, 2021 at 7:13
  • Thanks. I hadn't seen the rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); construction, which uses the DateTime(char*,char*) routine from github.com/adafruit/RTClib/blob/… and the C environment variables __DATE__, __TIME__ -- Rather than re-upload the code, you might need to re-compile to code to update the time encoded in the binary file.
    – Dave X
    Commented Oct 7, 2021 at 15:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.