Ds1307 Not moving forward while arduino powered off

Tick Tock Clock Kits

Moderators: adafruit_support_bill, adafruit

Ds1307 Not moving forward while arduino powered off

Postby obbi13 » Wed Dec 29, 2010 5:56 pm

This is a topic that I started on the Arduino forum. A friend of mine showed me where to put it per Lady Ada's request.

http://www.arduino.cc/cgi-bin/yabb2/YaB ... 606030/3#3

So far I have measured the voltage on the Vbatt and ground pins of the 1307 IC, and the battery is supplying a nice 3.2v. So battery power is not an issue (at least by measure). The code is included in the supplied link.

I can compile and the time will run perfectly but the moment I remove the power from the Arduino the clock stops right there and resume where it left of as soon as I apply power to the Arduino. This is keeping me scratching my head as I can't seem to find the root cause of the problem.

Help!
User avatar
obbi13
 
Posts: 10
Joined: Wed Dec 08, 2010 9:58 pm
Location: Carolina, PR


Re: Ds1307 Not moving forward while arduino powered off

Postby obbi13 » Wed Dec 29, 2010 7:14 pm

arduwino wrote:Can you post the code that you are using?


Yes sir... It's on the link that I posted earlier with photos, but there you go:
Code: Select all
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"
#include <SoftwareSerial.h>    // library to make a soft serial on any defined Pin

#define RTC5vPin 17 // pin 17 (analog pin 3) will be used to provide +5v to the RTC
#define RTCgndPin 16 // pin 18 (analog pin 2) will be used to provide GND to the RTC
#define LCDtxPin 2  // pin 2 to tranmit ro the serial LCD

RTC_DS1307 RTC;
SoftwareSerial LCD = SoftwareSerial(2,LCDtxPin); // create an LCD object with soft serial on pin 2.

void setup () {

    pinMode(RTC5vPin, OUTPUT);        // sets Pin for HIGH output
    digitalWrite(RTC5vPin, HIGH);     // turn pin on (5v) to power RTC
    pinMode(RTCgndPin, OUTPUT);       // sets Pin for output
    digitalWrite(RTCgndPin, LOW);     // turn pin on LOW (GND) to power RTC

    Wire.begin();                     // Initialize I2C
    RTC.begin();                      // Initiaize RTC object
    RTC.adjust(DateTime(__DATE__, __TIME__)); // Sets time per compouter compile time & date
 
    pinMode(LCDtxPin, OUTPUT);         // Set defined Pin as an Output Pin for transmission
    LCD.begin(9600);                   // Initialize LCD comms
    setLCD2x16();                      // Set LCD dimensions
    clearLCD();                        // Clear LCD
}

void loop () {
    DateTime now = RTC.now();         //fetch time snapshot to now
    clearLCD();                       // Clear LCD
    LCD.print("Date: ");              // Print Date: string to LCD
    LCD.print(now.month(), DEC);      // Print month numeric value ie. 12
    LCD.print('/');                   // Print date character divider /
    LCD.print(now.day(), DEC);        // Print day numeric value ie. 25
    LCD.print('/');                   // Print date character divider /
    LCD.print(now.year(), DEC);       // Print year numeric value ie. 2010
   
    LCD.print("Time: ");              // Print Time: string to LCD
    LCD.print(now.hour(), DEC);       // Print hour value ie. 11
    LCD.print(':');                   // Print time character divider :
    LCD.print(now.minute(), DEC);     // Print minute numeric value ie. 22
    LCD.print(':');                   // Print time character divider :
    LCD.print(now.second(), DEC);     // Print second numeric value ie. 30
    delay(1000);                      // Delay for one second
}

void setLCD2x16(){
   LCD.print(0x7C, BYTE);   //command flag
   LCD.print(4, BYTE);    //position
   delay(600);
}
void clearLCD(){
   LCD.print(0xFE, BYTE);   //command flag
   LCD.print(0x01, BYTE);   //clear command.
}

User avatar
obbi13
 
Posts: 10
Joined: Wed Dec 08, 2010 9:58 pm
Location: Carolina, PR

Re: Ds1307 Not moving forward while arduino powered off

Postby adafruit_support_bill » Wed Dec 29, 2010 7:26 pm

Code: Select all
RTC.adjust(DateTime(__DATE__, __TIME__)); // Sets time per compouter compile time & date


As the comment says, that line will reset the RTC time to the compile time every time you reset the Arduino. Unless you recompile every time, the clock will be set back to the last compile time.

Once the RTC has been set once, you don't need to do another RTC.Adjust() call unless the battery runs down.
User avatar
adafruit_support_bill
 
Posts: 16607
Joined: Sat Feb 07, 2009 9:11 am

Re: Ds1307 Not moving forward while arduino powered off

Postby obbi13 » Wed Dec 29, 2010 8:01 pm

I understand that perfectly and that's not the problem that I'm having. The problem that I'm having is that once the clock is set (at compile time) it will run perfectly until I power off the Arduino. As soon as I power up the arduino back (let's say it was without power for one hour) it will resume at the same time that I powered the arduino off. So the clock is now 1 hour behind.
User avatar
obbi13
 
Posts: 10
Joined: Wed Dec 08, 2010 9:58 pm
Location: Carolina, PR

Re: Ds1307 Not moving forward while arduino powered off

Postby adafruit_support_bill » Wed Dec 29, 2010 8:06 pm

So, what is the code you are using then? If you are using the code that you posted, the time will be reset to the compile time.
User avatar
adafruit_support_bill
 
Posts: 16607
Joined: Sat Feb 07, 2009 9:11 am

Re: Ds1307 Not moving forward while arduino powered off

Postby obbi13 » Wed Dec 29, 2010 8:17 pm

arduwino wrote:So, what is the code you are using then? If you are using the code that you posted, the time will be reset to the compile time.


Arduino, thanks for the help. By asking me that question I realized / learned that every time you power up the arduino it's going to run the setup part of the code, thus setting the time (in this case) to the last time it had when the power went off.

Thank you, thank you, thank you !!!!
User avatar
obbi13
 
Posts: 10
Joined: Wed Dec 08, 2010 9:58 pm
Location: Carolina, PR

Re: Ds1307 Not moving forward while arduino powered off

Postby codiy » Sun Jan 02, 2011 12:34 pm

I hope that obbi doesn't mind me hijacking this thread, but I have another issue with the DS1307 not moving forward, period.
I used the example code and then commented out the time setup, but when I use the serial monitor to check the time, it continually gives the time which the sketch was initially compiled. This time does not change on subsequent compiling (with the approrpiate code uncommented), and continues to print out "2010/12/30 14:18:31" over and over (which was the time the first time I compiled the sketch). Below is the code I am using.

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();
   
    pinMode (17,OUTPUT);
    pinMode (16, OUTPUT);
    digitalWrite (17, HIGH);
    digitalWrite (16,LOW);
   
//    int incomingByte = 0;
   
  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 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);
}


Has anyone else experienced this?

The RTC was a stocking stuffer, and most of my tools are still at school, so I have only limited troubleshooting ability right now.
codiy
 
Posts: 23
Joined: Tue Jun 15, 2010 7:36 am


Re: Ds1307 Not moving forward while arduino powered off

Postby codiy » Sun Jan 02, 2011 1:05 pm

Yep, battery is installed and in the proper orientation. I also checked and it is putting out 3.1 V
One thing I did notice on my soldering job is that the little blob I put on the contact did not carry through to the underside of the board. I didn't worry about it as I figured that the drill hole was plated through, and a continuity check said they were connected.
codiy
 
Posts: 23
Joined: Tue Jun 15, 2010 7:36 am


Re: Ds1307 Not moving forward while arduino powered off

Postby codiy » Sun Jan 02, 2011 1:51 pm

no, it has not advanced from the first time it was powered up. What I find strangest is that running the sketch with the time set routine uncommented does no reset the time on the IC.
codiy
 
Posts: 23
Joined: Tue Jun 15, 2010 7:36 am

Re: Ds1307 Not moving forward while arduino powered off

Postby adafruit » Sun Jan 02, 2011 1:54 pm

remove the battery, unplug the arduino
wait 10 minutes. try following the tutorial again
User avatar
adafruit
 
Posts: 10545
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: Ds1307 Not moving forward while arduino powered off

Postby codiy » Sun Jan 02, 2011 2:43 pm

ok, I went through the tutorial again, doublechecking the battery, the COM port and the baud rate, and now I am getting nothing on the serial monitor. I tried the tutorial instructions a few times, to be sure.

However, back when I first hooked the whole thing up (a few days back) I also played around with a sketch to have the arduino spit out the time on serial request. If I upload that sketch, then I get the "RTC is not running" message (every time the 'duino is reset), and when I request the time (by sending "9" through the serial monitor), it sends the generic "Saturday 2000/1/1 0:0:0" time.

here is that code:
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();
   
    pinMode (17,OUTPUT);
    pinMode (16, OUTPUT);
    digitalWrite (17, HIGH);
    digitalWrite (16,LOW);
   
//    int incomingByte = 0;
   
  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();
   
    if (Serial.available() > 0) {
      int incomingByte = Serial.read();
      int day = now.dayOfWeek();
      Serial.print("received: ");
      Serial.println(incomingByte, BYTE);
      if (incomingByte == '9'){
        switch (day){
          case 1:
            Serial.print("Monday  ");
            break;
          case 2:
            Serial.print("Tuesday  ");
            break;
          case 3:
            Serial.print("Wednesday  ");
            break;
          case 4:
            Serial.print("Thursday  ");
            break;
          case 5:
            Serial.print("Friday  ");
            break;
          case 6:
            Serial.print("Saturday  ");
            break;
          case 7:
            Serial.print("Sunday  ");
            break;}
   
    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(30);
}
codiy
 
Posts: 23
Joined: Tue Jun 15, 2010 7:36 am


Next

Return to Clocks

Who is online

Users browsing this forum: No registered users and 0 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [113]

Raspberry Pi[81]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]