How can I read date and time from PCF85063A rtc in esp32 board by using i2c protocol

#include <PCF85063A.h>

PCF85063A rtc;
time_t t;

void setup() {
  tmElements_t tm;

  Serial.begin(57600);

  Serial.println(String("Resetting RTC, status: ") + rtc.reset());
  Serial.println("Setting time to Tue, 08 Nov 2016 23:49:50");

  /* Convert Unix timestamp to tmElements_t */
  breakTime(1478648990, tm);
  rtc.time_set(&tm);
}

/* Print human readable time */
void print_time(tmElements_t t) {
  Serial.print(String("Year ") + (1970 + t.Year));
  Serial.print(String(" Month ") + t.Month);
  Serial.print(String(" Day ") + t.Day);
  Serial.print(String(" Wday ") + t.Wday);
  Serial.print(String(" Hour ") + t.Hour);
  Serial.print(String(" Minute ") + t.Minute);
  Serial.print(String(" Second ") + t.Second);
  Serial.print("\n");
}

void loop() {
  tmElements_t t;

  /* Get and print current time */
  rtc.time_get(&t);
  print_time(t);

  /* Print Unix timestamp */
  Serial.print("Unix time: ");
  Serial.println(makeTime(t));

  delay(1000);
}
Arduino: 1.8.19 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, None"

In file included from C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:25:0:

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.h:101:19: error: 'tmElements_t' has not been declared

     bool time_get(tmElements_t *now);

                   ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.h:110:19: error: 'tmElements_t' has not been declared

     bool time_set(tmElements_t *new_time);

                   ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:98:21: error: 'bool PCF85063A::time_get' is not a static data member of 'class PCF85063A'

 PCF85063A::time_get(tmElements_t *now)

                     ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:98:21: error: 'tmElements_t' was not declared in this scope

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:98:35: error: 'now' was not declared in this scope

 PCF85063A::time_get(tmElements_t *now)

                                   ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:99:1: error: expected ',' or ';' before '{' token

 {

 ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:117:21: error: 'bool PCF85063A::time_set' is not a static data member of 'class PCF85063A'

 PCF85063A::time_set(tmElements_t *new_time)

                     ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:117:21: error: 'tmElements_t' was not declared in this scope

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:117:35: error: 'new_time' was not declared in this scope

 PCF85063A::time_set(tmElements_t *new_time)

                                   ^

C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master\PCF85063A.cpp:118:1: error: expected ',' or ';' before '{' token

 {

 ^

Multiple libraries were found for "TimeLib.h"

 Used: C:\Users\shanawaz\Documents\Arduino\libraries\Time-master

 Not used: C:\Users\shanawaz\Documents\Arduino\libraries\Time-1.6.1

Multiple libraries were found for "PCF85063A.h"

 Used: C:\Users\shanawaz\Documents\Arduino\libraries\pcf85063a-master

 Not used: C:\Users\shanawaz\Documents\Arduino\libraries\PCF85063A-Arduino-Library-master

exit status 1

Error compiling for board ESP32 Dev Module.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

please help me Anyone :pray: :pray: by using wire library

Why not use the internal rtc of the ESP32?

Did the PCF85063A example work?

We are using external RTC device and I'm testing example only but still I'm getting error.

Hi, @kalyantillu
to use structure "tmElements_t t;"
you need the Timelib.h library.

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