Jump to content

Arduino rtc problem

Sharon24

i have the arduino leonardo and RTC3231 module and it work fine...until DST came

 

i tried to adjust the time but there is no changes

code i use:

 

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(9600);

  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(2016, 3, 30 ,17, 21, 20));

  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.day(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.year(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(1000);
    
}

he always stuck at hour behind the time i gave him

even if he take the from the pc ( rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); )

Case: NZXT H440 CPU: i7 6700K @ 4.0 Cooler: Antec Kuhler H2O 920 Graphics Card: Zotac Mini GTX1070 Ti Motherboard: Gigabyte Z170 K3 RAM: Kingstone Fury 2x8GB Storage: Crucial P1 SSD, Seagate - Barracuda 2TB 3.5, Hitachi - Deskstar 500 3.5" PSU: Corsair Enthusiast 550W 80+ Mouse: Logitech G403 OS: Windows 10 Home 64bit  Audio: ATH-AD500X

Link to comment
Share on other sites

Link to post
Share on other sites

Case: NZXT H440 CPU: i7 6700K @ 4.0 Cooler: Antec Kuhler H2O 920 Graphics Card: Zotac Mini GTX1070 Ti Motherboard: Gigabyte Z170 K3 RAM: Kingstone Fury 2x8GB Storage: Crucial P1 SSD, Seagate - Barracuda 2TB 3.5, Hitachi - Deskstar 500 3.5" PSU: Corsair Enthusiast 550W 80+ Mouse: Logitech G403 OS: Windows 10 Home 64bit  Audio: ATH-AD500X

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×