Hi,
I'm about to purchase the DS1307 RTC for use on my Arduino Mega 2560. Before purchasing, has anyone experienced problems using this on the arduino mega? I'd hate to buy it and find out it won't work.
Thanks
DS1307 RTC Arduino Mega
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: DS1307 RTC Arduino Mega
You shouldn't have any problems at all.
The DS1307 uses I2C to communicate, and the Mega can do I2C.
The DS1307 uses I2C to communicate, and the Mega can do I2C.
-
- Posts: 4
- Joined: Tue Jun 24, 2014 2:41 pm
Re: DS1307 RTC Arduino Mega
Well I received it yesterday and soldered up the connections while following the instructions. I downloaded the library and renamed as instructed (https://learn.adafruit.com/ds1307-real- ... no-library). Following the instructions at https://learn.adafruit.com/ds1307-real- ... g-the-code I uncomment the line that starts with RTC.adjust like so:
I upload the code so that it compiles then uploads immediately. However the damn thing won't work. The computer's time is set properly, but this is the output:
So... any ideas why the RTC isn't functional?
Code: Select all
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
Code: Select all
RTC is NOT running!
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
2165/165/165 165:165:85
since 1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1307 RTC Arduino Mega
Could you post clear pictures of your board and the connections to it? Also if you made any changes to the example code please post your code.
-
- Posts: 4
- Joined: Tue Jun 24, 2014 2:41 pm
Re: DS1307 RTC Arduino Mega
Thanks for the reply,
Attached are 2 closeup images; the connections are colored as grey (A5 <-> SCL), white (A4 <-> SDA), red (5V), black (ground).
The code is as it appears in the link I provided in my previous post, but for to make it easy here it is:
Refer to my previous post's hyperlink to see the expected outcome (note that it would be the second serial monitor image provided at said link).
I should also mention that, yes, the battery is good and it is placed with the positive (flat side) side up.
Let me know if there is any additional information you need, thanks.
Attached are 2 closeup images; the connections are colored as grey (A5 <-> SCL), white (A4 <-> SDA), red (5V), black (ground).
The code is as it appears in the link I provided in my previous post, but for to make it easy here it is:
Code: Select all
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
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__));
}
}
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.print(" since 1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}
I should also mention that, yes, the battery is good and it is placed with the positive (flat side) side up.
Let me know if there is any additional information you need, thanks.
- Attachments
-
- RTC2.JPG (265.39 KiB) Viewed 4091 times
-
- Notice that SQW is not used per instructions
- RTC1.JPG (203.42 KiB) Viewed 4091 times
-
- Posts: 295
- Joined: Sat Dec 11, 2010 1:17 am
Re: DS1307 RTC Arduino Mega
You mention you have a Mega 2560. The tutorial is for a Uno and specifically mentions the I2C pins as being Analog 4 and Analog 5. If you used A4 and A5 on the Mega that would explain why it isn't working.
On the Mega, the I2C pins are D20 and D21. They will be labeled on the Mega board itself in the 'communications' area.
Edited to add - I was typing when you made your post. Just swap A4 and A5 to the two I2C pins on the mega and you should be fine.
On the Mega, the I2C pins are D20 and D21. They will be labeled on the Mega board itself in the 'communications' area.
Edited to add - I was typing when you made your post. Just swap A4 and A5 to the two I2C pins on the mega and you should be fine.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1307 RTC Arduino Mega
From the Arduino site
So do as Stephanie says and swap your pins.I2C: 20 (SDA) and 21 (SCL). Support I2C (TWI) communication using the Wire library (documentation on the Wiring website). Note that these pins are not in the same location as the I2C pins on the Duemilanove or Diecimila.
-
- Posts: 4
- Joined: Tue Jun 24, 2014 2:41 pm
Re: DS1307 RTC Arduino Mega
Thanks for the replies,
that worked. Thank you very much for your assistance. Have a great day.
that worked. Thank you very much for your assistance. Have a great day.
- nikhilbadhe88
- Posts: 1
- Joined: Sat Sep 13, 2014 12:45 am
Re: DS1307 RTC Arduino Mega
after connecting all pin as you stated above on anduino mega .it did't works rtc shows garbage values 165/165/165 45:165:165..plz help me.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: DS1307 RTC Arduino Mega
@ nikhilbadhe88 Could you post clear pictures of both sides of your board showing any soldering you have done and the connections to it?
- ShooterBobSC
- Posts: 2
- Joined: Thu Jul 30, 2015 9:54 am
Re: DS1307 RTC Arduino Mega
Did this ever get resolved? I am having the same problem, however, mine was working before.
- ShooterBobSC
- Posts: 2
- Joined: Thu Jul 30, 2015 9:54 am
Re: DS1307 RTC Arduino Mega
Sorry! I reread whole thread and saw OP had wires backwards. MY issue was the board was powered off of a battery when in use and then the USB port while changing program. MY issue was the RTC was still being powered by the battery pack and the Arduino was powered off of the USB. moved power to come off of USB as well, therefore using a common ground and it worked again! :)
Please be positive and constructive with your questions and comments.