Skip to content

getEpoch() returns wrong epoch on Arduino ESP32 and DS1307 #23

Description

@EduardoBan

I am using the example for the DS2321 on a generic ESP32 board, where I have the DS1307 connected. I change the RTC type to the DS1307 and the UnixTime value it brings is incorrect.

#include<Wire.h>
#include <I2C_RTC.h>

static DS1307 RTC;

void setup()
{
  Serial.begin(9600);
  RTC.begin();

  //RTC.setHourMode(CLOCK_H24);
  RTC.setHourMode(CLOCK_H12);
  RTC.setEpoch(1622904335);
}
void loop()
{
  Serial.println(); 
  Serial.print("UnixTime : ");
  Serial.println(RTC.getEpoch()); 

  Serial.print(RTC.getDay());
  Serial.print("-");
  Serial.print(RTC.getMonth());
  Serial.print("-");
  Serial.print(RTC.getYear());
  Serial.print(" ");
  Serial.print(RTC.getHours());
  Serial.print(":");
  Serial.print(RTC.getMinutes());
  Serial.print(":");
  Serial.print(RTC.getSeconds());
  Serial.print(" ");
    if (RTC.getHourMode() == CLOCK_H12)
    {
      if(RTC.getMeridiem() == HOUR_AM)
        Serial.println(" AM");
      if (RTC.getMeridiem() == HOUR_PM)
        Serial.println(" PM");     
    }
  delay(1000);
}

Result:

UnixTime : 2664326756
6-6-2024 2:45:56  PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions