DS1307 RTC sketch and help needed.

Folks,

I am making progress with some DS1307 RTC boards, but am stuck with the sketch.

This is a working sketch which writes the time to the RTC and reads it back.

It is dodgy - yes I know - but it works, kinda.

This is the output I get from it if I say NO to the question:

Would you like to set the date and time now? Y/N
Sunday
2016/05/11

Oh, seems the extra characters won't translate.

It is "wrong" as in the Sunday is supposed to be the month, and after year/month/date is supposed to be the week day.

Putting that aside, at any time, you can enter:
2016,05,11,03,14,05,00

2016
11 May (or May 11)
Wednesday (03)
14:05:00 time
Then the output becomes correct.

Ok, no worries.

I close the window (serial monitor) and unplug the Arduino.
Plug in the Arduino and open the window.

Corrupt again.

Sorry, but I don't understand what I am doing wrong.

It has been a while, and I accept I have forgotten things I used to know.

Anyone - please.

Seral_clock_1307_new.zip (6.13 KB)

http://bildr.org/2011/03/ds1307-arduino/

DS1307 RTC=DS1307();             // Create RTC object

No.

DS1307 RTC; // Create DS1307 instance called RTC

Yes.

void loop()
{
  setTime_2();

No. I don't want to set the time. So, let's set it anyway, on EVERY pass through loop. Why?

Oh, wait. That is not necessarily what that function does. It's just a dumb name.

       year = Serial.parseInt();
        if (year >= 100 && year < 1000)
            Serial.println("Error: Year must be two digits or four digits!");

So, the user enters 16 for the year.

       RTC.set(DS1307_YR,rtc[6]-2000);                 //rtc[6] Year only has years since 2000 so 10 represents 20100.

You just set the year to -1984. Why?

   Serial.println(months[month-1]);

Anonymous printing sucks.

Serial.print("The month is ");
Serial.println(months[month-1]);

Takes little extra effort, and conveys a LOT more information. I suggest that you do that for all of your prints.

 rtc[6] = year;
  rtc[5] = month;
  rtc[4] = date;
  rtc[3] = weekday;
  rtc[2] = hour;
  rtc[1] = minute;
  rtc[0] = 0;

Most people would have put the data in the array in the other order...