RTC Change Year

Trying to get a DS3231 RTC working on a Arduino Mega.

Most sketches just display a series of "squares" on the serial monitor.

Have tried a few different sketches but all print "Squares" on the monitor when days, hours.minutes and seconds are expected.

Have tried several different RTC's and jumper wires and pretty certain wiring is correct.

Any suggestions?

I have found one that works perfectly & it must also automatically input correct Y, Mo, D, Mi &S as it required no inputs from me to establish these values.

Except it prints the year as 1918 instead of 2018.

I can find this section of code which seems to relate to " setting time" but cannot get it to work for me.

void parse_cmd(char *cmd, int cmdsize)
{
uint8_t i;
uint8_t reg_val;
char buff[BUFF_MAX];
struct ts t;

//snprintf(buff, BUFF_MAX, "cmd was '%s' %d\n", cmd, cmdsize);
//Serial.print(buff);

// TssmmhhWDDMMYYYY aka set time
if (cmd[0] == 84 && cmdsize == 16) {
//T355720619112011
t.sec = inp2toi(cmd, 1);
t.min = inp2toi(cmd, 3);
t.hour = inp2toi(cmd, 5);
t.wday = cmd[7] - 48;
t.mday = inp2toi(cmd, 8);
t.mon = inp2toi(cmd, 10);
t.year = inp2toi(cmd, 12) * 100 + inp2toi(cmd, 14);
DS3231_set(t);
Serial.println("OK");

Appreciate any suggestions on how I can change it to output the correct year?

rtc_ds3231.ino (4.52 KB)

The DS3231 RTC only uses 2 digits to store the year so if your getting 1918 instead of 2018 the problem is in the sketch as the 19 is coming from that and not the RTC.

The problem may go away if after this:

if ((now - prev > interval) && (Serial.available() <= 0)) {
       DS3231_get(&t);

you add:

t.year += 100 ;

It is not clear from what you've what the struct ts is in your ds3231 library, but it looks like it has a year defined as larger than a byte from this:

struct ts t;
. . .
t.year = inp2toi(cmd, 12) * 100 + inp2toi(cmd, 14);

What library are you using ?

Thank you 9V6gt that has fixed the problem.

I am using a library "ds3231_master" which I downloaded from GitHub. This was the only one that I could find that worked.

Any thoughts on why the others would produce the "Squares" on the monitor instead of numbers.

Appreciate the help

All these years later, THE MILLENIUM BUG STRIKES!

Farticus:
. . .
Any thoughts on why the others would produce the "Squares" on the monitor instead of numbers.
. . .

I guess it is that the extraneous information in the bytes representing time are not properly masked out.
For example, the DST3231 byte register for "Month" also has a century flag tucked in at the end as a single bit.
If this is not cleanly masked out, it could result in an unprintable character on the console.
Infact, it could be incorrect handling of this "Century" flag, which has caused your "year 2000" problem.

Thanks 6v6gt, Still too new to understand about "registers" guess I should make that my next level of comprehension.