Two identical RTC DS3231 with the same library but only one shows DST

Hi,
I've found a strange behaviour ( at least for a newbie as I am) with RTCs.
I've been using for several months two identical RTC DS3231bought from the same seller but I just realized that one is showing the correct DST while the other shows one hour earlier.
Both are controlled with the same library RTClib.h and the code is the same.
Which could be the reason of this behaviour ? By the way, I solved the issue through software but I would like to understand what I'm missing. Thanks for your help

Are you sure you initialized them the same? To my knowledge there is no DST function in the
DS3231.

It does indeed have no DST.
The time is written to the DS3231, and every second it advances the time. That's all it does.

Current time is stored in rtc eeprom memory. When you are updating current time you just increment currently stored value. Make functions to setup current time by storing new values (hours-minutes-seconds) in eeprom and after that you can increment your value. Also check i2c address to match your code

A DS3231 does not have EEPROM. It has what is known as registers and they rely on the power supply (Vcc or battery) to keep their values.

Hi,
thanks all for your suggestions/comments.
I'm enclosing the code that with one of the DS3231 RTCs gives as a result one hour earlier. If I uncomment lines 40-44 obviously the hour value is correct. The other DS3231 (same model, same seller) with the same code gives the hour value correct without the need for DST correction. Since RTC doen't have DST I do not understand why it happens

#include <Wire.h>
#include <RTClib.h> // for the RTC
RTC_DS3231 rtc;

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_ADDR   0x3C
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 1  // Pin 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

boolean isDST = true; // Set to true if DST is in effect

void setup() {
  Serial.begin(115200);
  while (!Serial);
  delay(1000);

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

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false, false)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;) ;
  }

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.ssd1306_command(SSD1306_DISPLAYON);
}

void loop() {
  DateTime now = rtc.now();
/*
  // Adjust for DST (if applicable)
  if (isDST) {
    // Add an hour during DST
    now = now + TimeSpan(0, 1, 0, 0); // Add 1 hour
  }
*/
  char dateBuffer[20];
  sprintf(dateBuffer, "%02u-%02u-%04u %02u:%02u:%02u", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
  Serial.println(dateBuffer);

  display.clearDisplay();
  display.setCursor(0, 0);
  display.println(dateBuffer);
  display.display();
  delay(1000);
}

OK. Now, when and how did you last set the time on your RTCs? You are of course aware that these RTCs are like a traditional, old-fashioned clock, in that you need to set the time before it can tell you the right time.

Did they at first both show the same time as each other, and then later the one-hour difference appeared? Or was there always this one-hour difference?

Possibly the time on one of the RTCs got corrupt somehow?

Hi,
I think you hit the target.
I do not remember to have manually set the time on these RTCs but ince I've used these RTCs also with library getting the time from a NTP server it probably happened that for one of them syncing happened during DST while for the other no. Is it a plausible explanation ? Thanks

That sounds like it might explain it.

There are a few different ways to set the time on an RTC.

Here is some code that I have, from a very long time ago, for setting the time on an RTC. In order to use it, you would need to change the numbers in the code to the correct date and time: the year would need to become 0x24 for 2024, the month would need to become 0x04 for April or 0x05 for May, and so forth. For example, if you want the 29th day of the month, you would input 0x29 for the day of the month.

#include "Wire.h"

void setup() {
  Wire.begin();
  Serial.begin(9600);
  // program to precisely set Chronodot
  Wire.beginTransmission(0x68); // address DS3231
  Wire.write(0x00); // select register
  
  Wire.write(0x30); // seconds (BCD)
  Wire.write(0x43); // minutes (BCD)
  Wire.write(0x17); // hours (BCD)
  Wire.write(0x07); // day of week (I use Mon=1 .. Sun=7)
  Wire.write(0x15); // day of month (BCD)
  Wire.write(0x09); // month (BCD)
  Wire.write(0x13); // year (BCD, two digits)
  
  Wire.endTransmission();
}

void loop() {
  delay(500);  
}

With this code, you can set the RTC to whatever date and time you choose, which might be useful for testing or other purposes. I am showing it to you so that you can set your RTC to the correct time, or 1 hour behind, or 1 hour ahead, or whatever you need.

Hi,
thanks for your advice and for sharing a useful code. As an old (74) newbie I really appreciate the help. Have a nice day

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.