Pages: [1]   Go Down
Author Topic: Problem with Real Time Clock Module  (Read 2049 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have bought this RTC module but I have problems making it work.

I use the examples in the Time library, eg. TimeRTCSet. When I set the time with a time command from the serial monitor, the time is set correctly. But when I read it back after resetting Arduino, it always starts with 17:18:09  27 2 2037 which is also the value it starts with even when I remove the RTC module completely. So the RTC doesn't do much in my setup.

SCL is connected to A5 and SDA to A4. And the CR2032 is inserted in its holder.

When I connect my LCD scope to SCL and SDA I see a constant high value. No impulses to see whatsoever. Now I don't know much about the I2C protocol, but I would assume that I could see "something" on these pins, right?

I would very much like to test if the RTC module is working or not. Any ideas how?

Thanks in advance smiley

Martin
Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2352
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

a picture would be helpful, try swapping the sda scl lines around, sounds like a connection issue
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3942
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The SCL and SDA connections are correct as you described them. I can confirm that the TimeRTCSet does in fact work. I don't have the same RTC module, but a different one based on the same DS1307 chip.

Very stupid question (no offense intended), the RTC is also connected to ground and 5V, yes?

Given the configuration of the module in the picture you linked, if you have male headers soldered to the board, a neat trick is to plug it straight into the Arduino's headers as follows:

GND to A2
VCC to A3
SDA to A4
SCL to A5
(let that last pin, DS, hang over the end of the header)

and power it by including the following in your code:

Code:
   pinMode(A2, OUTPUT);
    digitalWrite(A2, LOW);
    pinMode(A3, OUTPUT);
    digitalWrite(A3, HIGH);
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Found similar problem on 2 different type of RTC Modules - To fix, remove battery, wait 30 seconds and replace.
 
Re sketch  TimeRTCSet did you have problems getting to run? I'm using a UNO and although .h files are loaded are getting compile errors like:
error: stray '#' in program
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3942
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Re sketch  TimeRTCSet did you have problems getting to run? I'm using a UNO and although .h files are loaded are getting compile errors like:
error: stray '#' in program

No trouble with the sketch here. Arduino 1.0.1.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK this is not meant to be funny so, if your code is kosher, hear me out. I believe I have traced my sudden RTC problems to the motherboard in my desktop.

I fixed it by using a 9v wall-wart for power instead of the USB cable. If you are using a USB cable, you could have the same problem.

There has been prior evidence that my USB supply has been close to the edge. I have just had to replace the mobo and it appears that the new one is just that much short of grunt.  If things are marginal, it could be that the LCD is the villain in the act, most particularly the backlight in a 16x2 display. In that event, you might find the proof by removing the LCD and getting output from serial instead. 
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys,

Thanks for your replies.

I went to bed after starting this thread. When I tried this morning, the RTC worked!

rbright suggests waiting 30 secs before inserting the battery. Although I can't know for sure, perhaps I didn't remove it for long enough yesterday. Probably only like 10 secs which normally is enough for electronics stuff to "pass out". But I know that I left the module without battery overnight and that might have done it.

Jack Christensen's trick to power it from the analog pins is neat as I can simply insert the module in the connector. Thanks! Can I do the same from the digital pins? That is, power low-power devices instead of using 5v and Gnd?

TimeRTCSet is compiling fine under Arduino 1.0. No problems here.

Btw, I noticed that when the module works correctly but the time has not been set, it starts with 00:00:00 1-1-2000. When the module doesn't work or is not connected, the start time is 17:18:09  27 2 2037. I thought that the library would detect that the module wasn't present, but apparently not.
« Last Edit: December 11, 2012, 04:33:41 am by marlar » Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3942
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Jack Christensen's trick to power it from the analog pins is neat as I can simply insert the module in the connector. Thanks! Can I do the same from the digital pins? That is, power low-power devices instead of using 5v and Gnd?

Can't take credit, saw it on Adafruit's site. But yes digital pins would work as well, just stay within the current limitations of the microcontroller, 20mA per pin to be conservative. Analog pins can be used just like digital pins.

Quote
Btw, I noticed that when the module works correctly but the time has not been set, it starts with 00:00:00 1-1-2000. When the module doesn't work or is not connected, the start time is 17:18:09  27 2 2037. I thought that the library would detect that the module wasn't present, but apparently not.

Yeah that might be a good idea. Easy to add to the sketch:

Code:
/*
 * TimeRTCSet.pde
 * example code illustrating Time library with Real Time Clock.
 *
 * RTC clock is set in response to serial port time message
 * A Processing example sketch to set the time is inclided in the download
 */

#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
#define RTC_ADDR 0x68

void setup()
{
    pinMode(A2, OUTPUT);
    digitalWrite(A2, LOW);
    pinMode(A3, OUTPUT);
    digitalWrite(A3, HIGH);
    Serial.begin(9600);
   
    if ( !rtcPresent(RTC_ADDR) ) {
        Serial.println("RTC not connected!");
        for (;;);    //do not pass go, do not collect $200, loop forever
    }
   
    setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus() !=  timeSet)
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");     
}

void loop()
{
    if(Serial.available())
    {
        time_t t = processSyncMessage();
        if(t >0)
        {
            RTC.set(t);   // set the RTC and the system time to the received value
            setTime(t);         
        }
    }
    digitalClockDisplay(); 
    delay(1000);
}

//check to see if the RTC is there
boolean rtcPresent(byte addr)
{
    Wire.beginTransmission(addr);
    Wire.write(0x00);
    if (Wire.endTransmission() != 0)
        return false;
    else
        return true;
}

void digitalClockDisplay()
{
    // digital clock display of the time
    Serial.print(hour());
    printDigits(minute());
    printDigits(second());
    Serial.print(" ");
    Serial.print(day());
    Serial.print(" ");
    Serial.print(month());
    Serial.print(" ");
    Serial.print(year());
    Serial.println();
}

void printDigits(int digits)
{
    // utility function for digital clock display: prints preceding colon and leading 0
    Serial.print(":");
    if(digits < 10)
        Serial.print('0');
    Serial.print(digits);
}

/*  code to process time sync messages from the serial port   */
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message

time_t processSyncMessage()
{
    // return the time if a valid sync message is received on the serial port.
    while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
        char c = Serial.read() ;
        Serial.print(c); 
        if( c == TIME_HEADER ) {       
            time_t pctime = 0;
            for(int i=0; i < TIME_MSG_LEN -1; i++){   
                c = Serial.read();         
                if( c >= '0' && c <= '9'){   
                    pctime = (10 * pctime) + (c - '0') ; // convert digits to a number   
                }
            }   
            return pctime;
        } 
    }
    return 0;
}
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yeah that might be a good idea. Easy to add to the sketch:

Thanks!
Logged

Pages: [1]   Go Up
Jump to: