1

I'm using a DS1307 RTC (https://www.adafruit.com/product/3296) and an Arduino mega microcontroller trying to simply set and read the time of the RTC. However, whenever I try to output anything to the Serial Monitor, I get stuff like this:

Example Output

The code and the wiring is fairly straightforward which is why I'm confused. I'm just directly attaching the Vcc, GRND, SCL and SDA pins of the clock to the Arduino and using a slightly modified version of the example code as a part of the RTC library Adafruit supplied.

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup () {
  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(57600);
  rtc.begin();

  rtc.adjust(DateTime(2017, 11, 17, 20, 33, 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(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.println();
    delay(1000);
}

So I know I'm doing something wrong but I'm not sure what. Any help would be hugely appreciated.

migrated from electronics.stackexchange.com Nov 20 '17 at 9:17

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Can you post a schematic of how you have the DS1307 wired? – ThreePhaseEel Nov 18 '17 at 0:50
  • Looks like a baud rate issue. Check your clock speed and settings. – Trevor Nov 18 '17 at 1:54
  • Set the serial monitor to 57600 and check. – ammar.cma Nov 18 '17 at 2:38
  • @ammar.cma In the code above you can see that I did set the serial monitor to 57600 – chrispy Nov 19 '17 at 0:24
  • @Trevor What should I be changing it too exactly? – chrispy Nov 19 '17 at 0:25
-1

Change the baud rate to 57600, it specifies at: Serial.begin(57600);

  • Thank you for the advice @senpaiscuba. I am new to stackoverflow and did not realize you could edit after posting. – jpo43 Apr 17 '18 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy