RTC Programming

So I recently purchased an RTC for a project I'm workign on but i can't seem to get it to return the correct time. I'm using the example code in the DS1307RTC library.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "Wire.h"
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
DateTime now =rtc.now();


#ifndef ESP8266
  //while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime((__DATE__), (__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2018, 1, 19, 13, 11, 0));
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(3000);
}

I've gathered the line

"rtc.adjust(DateTime((DATE), (TIME)));"

is supposed to set the time using the clock on your computer, but it doesn't work. I get

"2165/165/165 (Sunday) 165:165:85"

returned in the serial monitor. The closest I've gotten to setting the clock is by uncommenting the line

"rtc.adjust(DateTime(2018, 1, 19, 13, 11, 0));"

and setting the time manually. When I did this the time was 10 minutes behind no matter how I adjusted it. Oh! And in many of the different codes I've tried to fix this problem, half the time a constant stream of

"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is returned. :slight_smile:

Thanks for any help

half the time a constant stream of "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is returned. :slight_smile:

That is a different problem: The Serial Monitor baud rate (lower right) is not the same as the sketch sets it to.

You need only one of the rtc.adjust statements. Try the manual one only..

(deleted)