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.

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

1 Answer1

-1

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

answeredApr 17, 2018 at 18:48
jpo43's user avatar
1
  • Thank you for the advice @senpaiscuba. I am new to stackoverflow and did not realize you could edit after posting.CommentedApr 17, 2018 at 18:58

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.