Wrong Date von RTC Module DS1302

Hello,
im trying to get the actual date time printed in the serial Monitor.
i used the following code for this:

#include <virtuabotixRTC.h>

virtuabotixRTC myRTC(53, 52, 49);

void setup() {
  Serial.begin(9600);
  myRTC.setDS1302Time(00, 40, 11, 5, 16, 7, 2021);
}

void loop() {
  myRTC.updateTime();
  Serial.print("Date / Time: "); 
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  delay(1000); 
}

But the Output in the Serial Monitor is the following:

Date / Time: 45/25/2165 45:85:85
Date / Time: 45/25/2165 45:85:85

I checked the battery. Still has the 3V.

What could cause this problem?

Which timezone/century are you in?

That library looks like it was written by someone unconvinced of the virtues of encapsulation.

I'd be inclined to put the time reporting code in its own function, and call it immediately after the set function in setup().

Looks like you've got the code from here. You may have got the wiring or pin numbers wrong.

I work with a Arduni Mega and used other Digital Pins. does it matter?
It is a big Project and all the other pins are used.

What I meant was that you should check if the pin numbers for CLK, DAT and RST are given correctly to the constructor of the used RTC class. If that is OK, there might be a conflict with some of the used pins so try different pins.

I have perhaps little concrete to add as I have not used that library.
The library I do use has a different format, though. But as you are returning a dateTime, then you might be not retrieving the individual values correctly.

I wonder if it might word trying this:
Change:
Serial.print(myRTC.month);
for
Serial.print(myRTC.month());

and likewise for the other values

Yeah no. Those are variables, which wouldn’t work too well called as functions.

You need to start over at square zero it seems. Wondering isn’t really a good approach.

Experiments have their place, why not try it and see exactly what kind of new pain problem it makes for you?

a7