RTC voltage problems

I am trying to install a DS1307 RTC module into my weatherstation, but I am having problems. At the moment I just have a simple sketch for displaying the time on the little 2x16 LCD. The RTC seems to retain the time correctly after power to the arduino is lost, but only loads the correct time sometimes. For example I have to switch the arduino on and off multiple times until the correct time is shown, often it just says 165:165:1 165/165.

I notice this is only when another component is connected. For example if I connect the RTC directly and display the time through the serial port then it works every time. But as soon as I add another component (e.g. the LCD) then I experience the problems above.

Im using an 820 point breadboard and connecting components using the power rails. It shoulden't be a lack of current because I can run the LCD, a DHT11 sensor, SD card, and a relay without much trouble. And it shoulden't be a voltage problem if I'm using the power rails??

Maybe I can solve this problem easily by using a pullup resistor on the RTC somewhere?

Thanks in advance for any advice greatly appreciated.

It would be easier to help if we saw a schematic and a photo of your wiring. One possibility is a poor power or ground connection.

Ok so it's basically this. But when I connect the RTC +V wire directly to the arduino (cutting the LCD out) then it outputs the correct serial time each time. Otherwise I have to keep turning it on and off until the correct time appears.

It seems to work most often by plugging in the wall wart, there is a small spark at the connection. Next flicking the switch on and off rapidly seems to work some of the time. The reset button has no effect when plugged into the wall.

When connected via usb it seems to work more often than when plugged into the wall, I did notice it display the wrong time through serial (LCD disconnected) a few times, so maybe its the RTC after all. The reset button almost always causes the right time to be displayed when connected through serial (no LCD).

Im baffled.

It sounds as though the LCD display was inducing transients on the shared +5V and/or ground connection. Putting a decoupling capacitor between the power rails of the breadboard, close to where the LCD power and ground wires plug into the breadboard, might have helped.

Also you haven't said which RTC module you are using - if it is one without pull-up resistors on
the I2C bus you will need to add pull-up resistors yourself.

Any thoughts on which size/how many capacitors needed to account for the transient voltages? I want to include 3 relays, an SD card, DHT11 temp/humidity sensor, and a transceiver module along with the RTC. Do I need a capacitor for each component? Also are they just regular capacitors or special "smoothing" capacitors?

Photo isn't a datasheet - what module is that?

For decoupling you should to follow best practice - Mike's guide is here: De-coupling

Here is the updated diagram. I am still waiting for some 47 uF to replace the 0.22uF shown.

Initially I thought it solved the problem, I turned it on and the time was correct. I turned it off and on again a few times and it worked for about the first 5 times or so and then it showed the incorrect time thereafter.

Could I maybe use something like this pseudo code:

while (time_not_correct)
{
time_get_rtc;
}

So that it keeps trying to get the time from the RTC?

Have you tried delaying for a second after power up, before the Arduino tries to read the time from the RTC?

I thought I was using the TimeRTC sketch from the website. It #includes the <DS1307RTC.h> library which seemed to only get the time at the setup function using setSyncProvider(RTC.get);   // the function to get the time from the RTC and just seems to display it in the loop - not sure how it gets the time every instance the digitalClockDisplay() is called, which only seems to have a printDigits function which I doubt is getting information from the RTC, it also has a 1000 ms delay in the loop.

Here is the code I am using. It has a 1000ms delay in the loop before it requests the time. It doesn't seem to matter if the delay is at the end of the setup function or at the start of the loop function or both, it still only works some of the time. It seems to work in spurts, if I plug it into the USB for example and the time is correct then its usually correct if I replug it in again and vica versa. Is this indicative of low frequency noise in need of the 47uF capacitors?

//Arduino 1.0+ Only
//Arduino 1.0+ Only

#include <LiquidCrystal.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68

LiquidCrystal lcd(2,3,4,5,6,7);

void setup(){
  Wire.begin();
  Serial.begin(9600);
      lcd.begin(16, 2);
      lcd.clear();
  // Print a message to the LCD.
  lcd.print("It is");
}

void loop(){
  delay(1000);
  printDate();

}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());


 lcd.setCursor(2, 1);
    switch (weekDay)                      // Friendly printout the weekday
  {
    case 1:
      lcd.print("MON  ");
      Serial.print("MON  ");
      break;
    case 2:
      lcd.print("TUE  ");
      Serial.print("TUE  ");
      break;
    case 3:
      lcd.print("WED  ");
      Serial.print("WED  ");
      break;
    case 4:
      lcd.print("THU  ");
      Serial.print("THU  ");
      break;
    case 5:
      lcd.print("FRI  ");
      Serial.print("FRI  ");
      break;
    case 6:
      lcd.print("SAT  ");
      Serial.print("SAT  ");
      break;
    case 7:
      lcd.print("SUN  ");
       Serial.print("SUN  ");
      break;
  }

  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
 
   lcd.setCursor(8,1);
  
  lcd.print(monthDay);
  lcd.print("/");
  lcd.print(month);
  lcd.print("/");
  lcd.print(year);

  lcd.setCursor(8,0);
  lcd.print(hour);
  lcd.print(":");
  lcd.print(minute);
  lcd.print(":");
  lcd.print(second);
  lcd.println("   ");
  
}

Well im ready to give up on this. I knew I shoulden't have got a DS1307, I see nothing but problems with it. I don't have a datasheet for the module. The capacitors don't do anything. It knows what the time is, it just doesn't want to update it unless its just the RTC connected to the arduino.. how useful is that?

If I wait a few minutes sometimes the time randomly shows up. I don't know how to fix this. The most time I've spent on this project is the damn RTC and its just not worth it anymore... whats the point if I can't even make the clock work. You'd think that you could at least get a clock module that actually works in conjunction with other devices, so if anyone can suggest one I'll gladly buy it and turn this DS1307 module into a paper weight.

The first thing you may consider is to do it step by step..

  1. remove the LCD and the sw stuff related to LCD
  2. wire the RTC module only (Vcc, Gnd, SDA, SCL)
  3. Serial.print() all the data you get from RTC to serial and watch the stuff on the terminal
  4. when you will get familiar with the RTC you may follow with LCD

Do not wire everything at once.. :wink:

PS:

library which seemed to only get the time at the setup function using

setSyncProvider(RTC.get); // the function to get the time from the RTC

and just seems to display it in the loop - not sure how it gets the time every instance the digitalClockDisplay() is called, which only seems to have a printDigits function which I doubt is getting information from the RTC, it also has a 1000 ms delay in the loop.

The stuff works in following manner:

  1. you must have "Time" library installed

  2. Time lib provides a "systime" which runs inside the arduino, independently from the external RTC

  3. "setSyncProvider(RTC.get)" only says to the Time lib, that there is a function called "RTC.get()" somewhere defined (you have to provide it) which returns "unix time" (that is a single number, ie 1344959494 - seconds since 1.1.1970) from the external RTC or GPS or..

  4. then, when you call a function called "now()" which returns the actual systime (not the RTC time) in form of the "unix time", the now() also synchronizes the internal "systime" with the external RTC, when the "Sync interval" (set to 300secs by default) is over - it means the actual systime is synced with RTC at regular intervals only (could be set to other interval). When you read now() and the sync interval is not over, the now() only returns the systime without syncing.

  5. Time library provides everything you need for timekeeping - have a look on it..
    Arduino Playground - HomePage

As I have stated, when directly connected with no LCD and print serial it seems to work. I HAVE noticed it print the wrong time through serial rarely but this is usually corrected after 10 seconds or so.

It seems to manfunction more often when the backlight is connected with or without the Vcc and Gnd connected. Which is not suprising since it probably uses more power for the backlight and I guess where transient voltage might occur, but the decoupling capacitors didn't do anything. I connected the + end of the 47uF to the + power rail, and the - end into the gnd power rail with the + end closer to the source than the - end. If anything, it just delays how fast the LCD text appears (fades in more slightly).

The time saved on the module is correct, I haven't needed to set the time on the RTC again. It just doesn't always fetch the time when something other than the RTC is connected, which is frustrating because I know the time is set correctly and it can display it.

Again I don't have the datasheet just the picture of the module and im sure it has pullup resistors, but can't I add some external pullup resistors to the data wire to increase the voltage?

pito:
The first thing you may consider is to do it step by step..

  1. remove the LCD and the sw stuff related to LCD
  2. wire the RTC module only (Vcc, Gnd, SDA, SCL)
  3. Serial.print() all the data you get from RTC to serial and watch the stuff on the terminal
  4. when you will get familiar with the RTC you may follow with LCD

Do not wire everything at once.. :wink:

PS:

library which seemed to only get the time at the setup function using

setSyncProvider(RTC.get); // the function to get the time from the RTC

and just seems to display it in the loop - not sure how it gets the time every instance the digitalClockDisplay() is called, which only seems to have a printDigits function which I doubt is getting information from the RTC, it also has a 1000 ms delay in the loop.

The stuff works in following manner:

  1. you must have "Time" library installed

  2. Time lib provides a "systime" which runs inside the arduino, independently from the external RTC

  3. "setSyncProvider(RTC.get)" only says to the Time lib, that there is a function called "RTC.get()" somewhere defined (you have to provide it) which returns "unix time" (that is a single number, ie 1344959494 - seconds since 1.1.1970) from the external RTC or GPS or..

  4. then, when you call a function called "now()" which returns the actual systime (not the RTC time) in form of the "unix time", the now() also synchronizes the internal "systime" with the external RTC, when the "Sync interval" (set to 300secs by default) is over - it means the actual systime is synced with RTC at regular intervals only (could be set to other interval). When you read now() and the sync interval is not over, the now() only returns the systime without syncing.

  5. Time library provides everything you need for timekeeping - have a look on it..
    Arduino Playground - HomePage

Thanks for explaining it, I thought it was something along those lines. But it has to sync on startup, or when the function is first called right? Because otherwise it would print 45:165:165 for 300 seconds on startup regardless. So I am asking how can I make sure that it is synced? Before it does anything else?

By the way, as you can see the code I'm using doesn't include the time library.

If connecting the backlight is causing it to malfunction, then the backlight may be overloading the Arduino. How are you powering the Arduino? Do you have a resistor connected in series with the backlight, and if not, are you certain that the LCD already includes a backlight resistor?

But it has to sync on startup, or when the function is first called right? Because otherwise it would print 45:165:165 for 300 seconds on startup regardless. So I am asking how can I make sure that it is synced? Before it does anything else?

In setup () I do :

..
        Serial.begin(115200);

	// SYNC the RTC and systime at reset
	setSyncProvider(RTC.get);   // the function to get the time from RTC
	if(timeStatus()!= timeSet) 
		Serial.println("Unable to sync with the RTC");
	else
		Serial.println("RTC has set the system time");  
	setSyncInterval(300); // set the number of seconds between re-sync of systime
	time_t sys_t_start = now();  // keep the unix reset start time
..

Again, RTC.get() must return unix time. Set it to UTC, and, you may use Timezone library to adust to your local time (and summer time) automatically.
Have fun! :slight_smile:

dc42:
If connecting the backlight is causing it to malfunction, then the backlight may be overloading the Arduino. How are you powering the Arduino? Do you have a resistor connected in series with the backlight, and if not, are you certain that the LCD already includes a backlight resistor?

I'm not sure if the backlight is solely responsible, but I have a 2k resistor in series yes. I am using a 12v 500mA adaptor for power, or the USB connection to laptop.

While measuring the voltage to confirm it was within the 5v range, I accidentaly shorted the 5V and the GND pins on the RTC module; which seems to cause the correct time to appear (If the LCD doesn't go blank, in which case the time is still correct after shorting when monitored through serial). What does this mean?

I tried touching the connections with a capacitor to see if it would have the same effect but no luck.

here you can download the datasheet WayEngineer.com is for sale | HugeDomains

alnath:
here you can download the datasheet http://www.wayengineer.com/index.php?main_page=product_info&products_id=913

Following the link the page says "4.Solving the problem of DS1307 with spare battery cannot read or write". But I can't find any information on this in the data sheet. It seems like the problem I'm having, how do I solve it?

Hello,

I don't know exactly what's my problem. Maybe it's the power supply or whatever else.

What happens to me is:

  • I have done a home automation system and it has been working properly for 5 months.
  • It includes RTC DS1307.
  • I have a copy of the system in my lab in order to test the setups before to update my working automation system (with RTC too).
  • Sometimes, RTC on my test arduino have failed, and it doesn't give the time. I solved the problem each time trying a lot of things (reset, turn off/on, changing the pins of side on the TinyRTC...).
  • Today, my definitive arduino (the one which is working for 6 months) is not giving me the RTC time. Nothing has changed this night, but it doesn't work today.

¿What kind of problem do you think I have?

Today I have bougth 2 modules DS3231, in order to replace the DS1307 (and solving by the time its bad precission).

My home automation project is here: My home automation (webserver + HTML control) - Home Automation - Arduino Forum

I think its the same problem as me. It sounds like the backup battery is part of the problem. I haven't tried, but have you tried taking the battery out?

So you think DS3231 will be better? Do you have DS1307 TinyRTC I2C module as well?