Setting The Time On DS1307

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Setting The Time On DS1307

Post by motionpotion »

Hi,

For the NeoPixel clock project I am using an FTDI Friend to program the micro-controller and DS1307 clock module. Everything seems to get uploaded correctly when I follow the instructions here: https://learn.adafruit.com/ds1307-real- ... g-the-code to set the time. But when I check the time via the serial monitor in the Arduino IDE I get an incorrect time as in the attached screenshot:
arduino-time.png
arduino-time.png (53.53 KiB) Viewed 1748 times
My computer time is set correctly but it doesn't upload the correct time.

I also tried setting a time via the code as follows:

Code: Select all

rtc.adjust(DateTime(2014, 9, 4, 22, 12, 30));
but that comes back with 19th of August 2014 instead of the date I set it to.

When I set the date using the following code:

Code: Select all

rtc.adjust(DateTime(__DATE__, __TIME__));
the resulting output is:

2165/165/165 165:165:85
since midnight 1/1/1970 = 1418514385s = 16417d
now + 7d + 30s: 2014/12/20 23:46:55

but again the date on my mac is set to 2014/09/04 and the time is: 22:56:55

This is the base code I downloaded via the link on the DS1307 page.

What am I doing wrong?

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

We have seen the 2165/165/165 165:165:85 problem before. It generally indicates a bad ground connection to the DS1307. Check your wiring.

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I checked the wiring and everything seems fine and connected properly.

I have a DC Boarduino from the NeoPixel Clock project. In the Arduino IDE which board should I have selected under Tools -> Board ->?

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

Please post a picture showing your soldering

You can use the Boarduino with the Arduino IDE as a "Diecimila / Duemilanove" compatible. If you have the ATmega328 version, select "Duemilanove with ATmega328". Otherwise select "Diecimila/Duemilanove with ATmega168"

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I've tried with my Extech voltage meter to check all of the solder points and they seem to be connected. I also took out the battery and tested it and it is producing 3.1 volts. I have the arduino plugged into the mains and it is connected via the DC input. I'm connected via USB FTDI Friend and that seems to be working ok because I tried transferring some of the example programs to the arduino and they work (i.e. I tried the strandtest project).

Here are some photos of the soldering:
arduino-ds1307-1.JPG
arduino-ds1307-1.JPG (628.42 KiB) Viewed 1702 times
arduino-ds1307-2.JPG
arduino-ds1307-2.JPG (678.98 KiB) Viewed 1702 times
arduino-ds1307-3.JPG
arduino-ds1307-3.JPG (473.91 KiB) Viewed 1702 times

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

That all looks good. I'm stumped.
Let's try replacing the DS1307 board. Please email [email protected] with a link to this thread for a replacement

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I have another ds1307 here that I can assemble and try. Just need to practice how to unsolder all those joints to the breadboard on the existing ds1307 board. :)

The last time I was sent a free replacement item customs tried to charge me for it so I'll try to avoid that for as long as possible. :/

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I replaced the existing ds1307 in the circuit with the newly built ds1307. Still the same problem. The ds1307 program compiles and is uploaded with no problems but the time is not correct. I have no hair left to pull out now. :/

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

You're still getting the 2165/165/165 165:165:85 problem? Try resoldering everything having to do with the ground connection.

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I've just returned to this project and still the same issue (now tried two different ds1307). Using the default code to set the time on the ds1307 I just get "RTC is NOT running!".

I have desoldered and replaced every cable too now but still can't set the clock. What am I missing?

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

Post some new pictures. Maybe something will jump out at me.

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

I am getting those new photos prepared now for upload. Is there something I need to do to initialise the ds1307?

It seems to be accepting the code when I upload it from the sketch. I can also upload the default sketch project to the neo pixel ring called "strandtest" and that displays the sequence of alternating LED's on the neo pixel ring so that part seems to be working fine.

Just the clock seems to be working but doesn't ever accept the correct time setting.

[EDIT]
NeoPixelOne.png
NeoPixelOne.png (911.96 KiB) Viewed 1514 times
Adding the photo. And have just discovered something - the jumper on the pins at the end of the arduino chip (to the left of the green wire) was on PWR pins. I moved it to the SEL pins and now the time gets set but the time doesn't seem to be set correctly. It gets set to 21:9:56 instead of the current time of 21:35:56. If I remove the FTDI cable the clock stops working completely even though it is still receiving power.

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

Re: Setting The Time On DS1307

Post by adafruit_support_rick »

motionpotion wrote: I moved it to the SEL pins and now the time gets set but the time doesn't seem to be set correctly. It gets set to 21:9:56 instead of the current time of 21:35:56.
Can you post the sketch you're using to set the time?
motionpotion wrote: If I remove the FTDI cable the clock stops working completely even though it is still receiving power.
Can you post a detailed top view with the ftdi cable removed?

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

Below is the sketch that should set the time to the time that the code is compiled at (but it sets it about 25 minutes slow).

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();

  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(F(__DATE__), F(__TIME__)));
    rtc.adjust(DateTime(__DATE__, __TIME__));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2014,12,15,19,46,00));
    //rtc.adjust(now());
  }    
}

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);
}

motionpotion
 
Posts: 29
Joined: Tue Jul 29, 2014 9:15 am

Re: Setting The Time On DS1307

Post by motionpotion »

Here is the top view:
NeoPixelTwo.png
NeoPixelTwo.png (814.01 KiB) Viewed 1513 times

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

Return to “Clock Kits (discontinued)”