Having problems with DS1307/RTClib hanging my Arduino

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
mlgualtieri
 
Posts: 5
Joined: Sat Dec 14, 2013 10:11 pm

Having problems with DS1307/RTClib hanging my Arduino

Post by mlgualtieri »

I recently purchased a DS1307 Real Time Clock Breakout Board Kit, and am having problems getting it working. When I loaded up the code provided in the online how to, nothing printed out to my serial console. I've fiddled with this and other RTC examples for hours and I just can't seem to get anything working. I'm suspecting that the issue might be software related, but that is just a guess.

I have verified that the battery voltage is reaching the DS1307 chip, and that 5v is being input into the breakout board from the Arduino. The pins are also plugged into the correct positions. I also just retouched up all my solder connections, just to make sure that it wasn't related to a bad joint.

If I run this code, nothing is output onto my serial console:

Code: Select all

#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();
    delay(1000);
}
If I comment out everything in loop() I get the message "RTC is NOT running!" printed out. This would make sense as I haven't been able to set the default time. Also, if I try to set the time with the RTC.adjust, this also causes the arduino to hang, and the time is not updated from what I can tell.

I have been able to in certain cases get just one of the 'now' parameters to print, but can only get one to print at a time. If I try to print two, then it will hang.

So, I'm not sure what is happening and am out of ideas. I am using the Arduino IDE 1.0.5 under Gentoo Linux, with gcc avr-4.6.3, binutils avr-2.23.2, and cross-avr/avr-libc-1.8.0. The code compiles fine and loads onto the Arduino, but it just doesn't do anything.

Any help is appreciated!

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

Hanging is usually an i2c connectivity problem. If you post photos of your solder and wiring we'll see if we can spot any problems.

mlgualtieri
 
Posts: 5
Joined: Sat Dec 14, 2013 10:11 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by mlgualtieri »

Thanks for getting back to me! Below are the requested images. The black wire goes to ground, orange to +5v, yellow to SDA, and grey to SLC. I also have the blob of solder under the battery, and as I mentioned in my previous post have verified 3v entering the chip.
IMG_20131215_101910.jpg
IMG_20131215_101910.jpg (750.79 KiB) Viewed 3471 times
IMG_20131215_101509.jpg
IMG_20131215_101509.jpg (450.93 KiB) Viewed 3471 times
IMG_20131215_101447.jpg
IMG_20131215_101447.jpg (434.87 KiB) Viewed 3471 times

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

Your solder and connections look OK. The example code should run without changes. From the symptoms, it sounds like you are communicating with it partially. I'm going to assume that you just got a flaky DS1307 chip. If you contact support @adafruit.com with a link to this thread we can send you a new one.

mlgualtieri
 
Posts: 5
Joined: Sat Dec 14, 2013 10:11 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by mlgualtieri »

Sounds good... Thanks for your help! I was also wondering about the chip. I'll follow up on the thread after I put the new one in place.

User avatar
tim mcpherson
 
Posts: 24
Joined: Tue Jan 01, 2013 6:01 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by tim mcpherson »

Hi,

While I've mentioned it before to tech support, it apparently still has the same problem.

The code in the setup loop that reads:

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

The RTC.adjust function will only execute while the preceding: if (! RTC.isrunning()) is TRUE.

In other words the RTC.adjust() will not execute unless the RTC is NOT running and needs to be moved out of the 'if' condition in order to set the time.

It worked for me to set the time. I hope this helps others trying to set the time with this code.

Tim

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

In other words the RTC.adjust() will not execute unless the RTC is NOT running
This is by design. Otherwise, the time would get set back to the compile time anytime the Arduino was powered up or reset.

To stop the RTC, disconnect power and pull the RTC battery our for a few minutes. Then re-install the battery, power it up and upload the (freshly compiled!) code to reset the time.

User avatar
tim mcpherson
 
Posts: 24
Joined: Tue Jan 01, 2013 6:01 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by tim mcpherson »

I'm sorry I didn't make my point clear again.
The way the code is written. The adjust function will never execute because it is nested in the 'not running' conditional. It needs to be moved out of the nesting if you want to set the time upon compiling. You have it commented out to prevent unwanted execution, but it will never execute even if un-commented the way you have it now. Try it and see. I'm sorry I can't make it any more clear.

Tim

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

Hi Tim,

I have run this code many times on many DS1307s and DS3231s and it has worked fine every time. The RTC.adjust() call should start the clock running. This is a fairly mature library and we have had few reports of problems with it.

mlgualtieri
 
Posts: 5
Joined: Sat Dec 14, 2013 10:11 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by mlgualtieri »

Ok... I received the new DS1307 breakout today. I soldered it up, loaded the code, and again no output. I doubt I received two bad units, so something else must be the problem. I'm unsure what though.

Could the Arduino be bad? This Arduino does work perfect in other applications, but I've not used the analog pins on this unit.

I have verified that the 5v input from the Arduino is reaching the chip, as well as 3v input from the battery.

EDIT: Problem sort of solved. I started thinking it was a software issue again, so I brought out a old testing laptop I had in the closet and installed the Arduino IDE on it. Loaded up the sketch, and it worked! I don't know why it would work here and not on my regular laptop. I'm guessing it might have something to do with the crossavr toolchain and the bytecode that is actually loaded onto the Arduino. I've never had any previous problems, so there could be an issue deep in the library that arises with this specific toolchain. Anyway, I was able to integrate the clock into my project, and load the sketch onto the Arduino, so it's good to go.

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

Interesting. Every once in a while we run across anomalies like that due to compiler differences. What are the two different systems you are running?

mlgualtieri
 
Posts: 5
Joined: Sat Dec 14, 2013 10:11 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by mlgualtieri »

adafruit_support_bill wrote:Interesting. Every once in a while we run across anomalies like that due to compiler differences. What are the two different systems you are running?
My main laptop runs Gentoo Linux (with the crossdev toolchain detailed in my initial post). I'm embarrassed to say the machine that got it working was an old WinXP laptop :oops: that was used to test installation of a Linux OS my previous company had developed.

Currently, all my other machines are running Gentoo, and since I thought it might have been an issue with Gentoo's crossdev toolchain (which is was), the more expedient option was to try on the WinXP laptop instead of installing another distro on another machine.

Unfortunately, I can't do any more testing for the time being, as the unit was packaged up in a box and shipped out this morning. I needed the RTC to finish off an Arduino word clock I built as a Christmas gift. The final product looks and works great -- although I was in such a hurry to get it packaged and shipped this morning I forgot to take a picture/video of the final assembly!

Thanks again for your help! I feel as though I should reimburse Adafruit for the second breakout board, as it was not a hardware fault.

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

Not a problem. We all learned something from it. :D

thunnus
 
Posts: 4
Joined: Sun Dec 29, 2013 5:05 pm

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by thunnus »

Hello

I apologize for the intervention

I have a small problem (lack of some knowledge in arduino and c / c + + :roll: ), I'm starting with the Arduino.
I am doing my 1st project, which consists of recording a temperature of a LM35 or Thermistor sensor with data logging in nini SD card in case of high temperature alarm with buzzer and strobes lights and the option of using a Mini Thermal Printer for printing with a push button and show the same time this information in an LSD with the event date.

But I'm with the following problem, change the analog ports between lcd backpack and DS1307 because librares are the two with the analog ports A4 and A5, and tabmbem can not settle with reading the DS1307 for Mini Printer.

Any help is appreciated!

User avatar
adafruit_support_bill
 
Posts: 89226
Joined: Sat Feb 07, 2009 10:11 am

Re: Having problems with DS1307/RTClib hanging my Arduino

Post by adafruit_support_bill »

@thunnus - Please start a new thread for your question. It is not related to the topic of this thread.

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

Return to “Arduino”