Can't RUN ds1307 example properly to set time [SOLVED]

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
DanPolka
 
Posts: 108
Joined: Tue Feb 18, 2014 5:31 am

Can't RUN ds1307 example properly to set time [SOLVED]

Post by DanPolka »

I can't get the example ds1307 sketch from the RTClib for Adafruit DS1307 Real Time Clock breakout board kit to RUN PROPERLY (on an Arduino Uno rev3, compiled with IDE 1.0.5 -r2). I did remove the "if (! RTC.isrunning()) {" section as has been suggested.

The other example, datecalc, does seem to run, however.

I'm on a Windows Vista machine, and other sketches run on the Uno.

With Uno disconnected, I removed the battery, waited while I measured its voltage, and reinserted the battery.
The battery voltage is 3.36, inserted with + on top.

I used the example ds1307 sketch from the Adafruit Learning System "Understanding the Code" page to try to set the time,
http://learn.adafruit.com/ds1307-real-t ... g-the-code ,
and modified it to remove the
"if (! RTC.isrunning()) {" section, and added some debug serial print statements to it.

Before the added debug prints, nothing was printed on the serial monitor at all.

With debug prints before and after the
"rtc.adjust(DateTime(__DATE__, __TIME__));",
the debug text BEFORE the adjust time is printed, but the debug text
AFTER adjust time is NOT printed, nor is any debug text INSIDE the main loop printed, nor are the originally intended prints inside the loop printed, either.

With the ADJUST TIME commented out, the debug text both before and after the adjust time statement prints, as does the FIRST debug text INSIDE the main loop, BUT no further printing from inside the loop occurs.

On the other hand, the results of running the DATECALC example are these:

dt0 2000/1/1 0:0:0 = 946684800s / 10957d since 1970
dt1 2001/1/1 0:0:0 = 978307200s / 11323d since 1970
dt2 2009/1/1 0:0:0 = 1230768000s / 14245d since 1970
dt3 2009/1/2 0:0:0 = 1230854400s / 14246d since 1970
dt4 2009/1/27 0:0:0 = 1233014400s / 14271d since 1970
dt5 2009/2/27 0:0:0 = 1235692800s / 14302d since 1970
dt6 2009/12/27 0:0:0 = 1261872000s / 14605d since 1970
dt7 2009/12/27 1:0:0 = 1261875600s / 14605d since 1970
dt8 2009/12/28 0:0:0 = 1261958400s / 14606d since 1970
dt9 2010/1/3 0:0:0 = 1262476800s / 14612d since 1970

The modified ds1307 example code is this:
(I tried to use the "copy for forum" tool, but a bunch of errors not previously seen under compile nor upload occurred.)

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);
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();
  Serial.println("setting the time/date?");
  // following line sets the RTC to the date & time this sketch was compiled
  rtc.adjust(DateTime(__DATE__, __TIME__));
  Serial.println("finished setting the time/date?");
 }

void loop () {
  Serial.println("in beginning of loop");
    DateTime now = rtc.now();
  Serial.println("just after DateTime 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 midnight 1/1/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);
}
Does anyone have any idea what might be going wrong here??
Last edited by DanPolka on Thu Feb 20, 2014 2:07 am, edited 2 times in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Can't RUN ds1307 example properly to set time

Post by adafruit_support_rick »

Your code seems to run fine for me:

Code: Select all

setting the time/date?
finished setting the time/date?
in beginning of loop
just after DateTime now
2014/2/19 11:45:16
 since midnight 1/1/1970 = 1392810316s = 16120d
 now + 7d + 30s: 2014/2/26 11:45:46

in beginning of loop
just after DateTime now
2014/2/19 11:45:19
 since midnight 1/1/1970 = 1392810319s = 16120d
 now + 7d + 30s: 2014/2/26 11:45:49

in beginning of loop
just after DateTime now
2014/2/19 11:45:22
 since midnight 1/1/1970 = 1392810322s = 16120d
 now + 7d + 30s: 2014/2/26 11:45:52

...etc...
Please post some clear, detailed pictures of both sides of the breakout board. A picture showing your connections to the arduino would also be helpful

DanPolka
 
Posts: 108
Joined: Tue Feb 18, 2014 5:31 am

(SOLVED)Re: Can't RUN ds1307 example properly to set time

Post by DanPolka »

SIGH!! Yes, you're absolutely right, my code SHOULD run, IF I had the breakout board POWERED UP!! :oops:

I had the ds1307 board directly plugged ONTO into my Uno, to use the analog pins as power and ground for that board, and had made TWO coding mistakes: the first and in this instance now obvious (& relevant to your request to see my hookup!), was that I didn't include ANY statements at all to make the analog pins be hi & lo outputs!

And then when I went to fix that lack, I had earlier misunderstood the pinout A to D translation, because the PICTURE describing the use of the analog pins as gnd and pwr was of a Duemilanove, and I presumed that the pin translation described there (A2= 16, A3 = 17) was WRONG for a UNO, when in fact is was NOT WRONG. (From a board pinout diagram, I wrongly concluded that I should use pin numbers 25 & 26, and did so at first, until I found that wasn't giving +5 & gnd.)

So it works fine now. :roll:

And what's funny, so to speak, is that I only realized my mistake as I was thinking to ask here if the Chronodot board might ever be built in a similar way so IT could be plugged directly into the Uno like the ds1307! And of course, at that point, I realize that I needed CODE to make that idea work, and hadn't included it!

So I just have one more question: is there a way to indicate on this thread that the problem is solved??

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Can't RUN ds1307 example properly to set time [SOLVED]

Post by adafruit_support_rick »

You can edit the topic title to include the word 'SOLVED'

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”