RTC stuck at 12:00 AM, while it was working before

hi guys, new to this entire Arduino forum and even totally new to adruino itself.

any how, Im building a basic PWM light controller for LEDs and I run in some trouble with my RTC.

below you se my parts:

arduino uno http://www.robotshop.com/ca/arduino-uno-microcontroller.html
sheeld http://www.robotshop.com/ca/dfrobot-lcd-keypad-shield-arduino-5.html
clock http://www.robotshop.com/ca/seeedstudio-electronic-brick-real-time-clock-module.html

so everything connected, (I build the exact same as someone I know that has the same already running)

si I got all the codes from my friend, and only changed the time for the RTC, to the time it was at that time

I uploaded it, and everything was working fine, for testing the LED we programed the time to be on and off 1 minute, so after a test, I would gust push the reset button, and it would go on and off again, as it would reset the time, I programmed it at.

now the thing is, we have 2 sets of code for our LED, one is a analogue and the other is for PWM.

I tested every time with the analogue setting (to drive analogue drivers)

now moving forward I removed the // in front of my PWM code, and put it in front of my analogue code (activating the one, de-activate the other.

I did not do anything ells, and uploaded the code again.

sins that time my RTC is stuck at 12:00 and douse not do a thing, while I had it programmed for 6:59:55

as I have no idea what happened, I pushed the reset button, but nothing, stuck at 12 AM.

thinking I made a mistake in the code, I uploaded the code I knew was working, and that I did not change, but still nothing

so overall my RTC is stuck at a set time (12:00 AM) and is not running.

I also have tried to take all power off (USB, battery and power supply) I did this for over a hour, but still after that I connect everything again, and it shows again the 12:00 AM

any sugestions are welcome,

I know Im not a specialist with all this,in fact I almost dont know what Im doing, exept using ready made codes, and first thy work, and than, nothing, everything stuck at 12 AM

As you are new to the Arduino, please spend a few days on the reference and tutorial section to get an understanding of the capabilities of the Arduino and its language.

That said, could you post your code (preferably between code tags made by the # button) .

The problem looks like a RTC failure so I would advice to triple check all connections and run a separate RTC test application to check it works. Most libraries com with sample applications taht ca be used for this.

Hopes this helpes a bit,

Try a simple sketch to see if you can read/write the RTC registers directly using I2C commands. Could be something simple like the upper bit of the seconds register got set to a 1, which stops the clock from running.

Try this simple sketch to see if your RTC is working.
Send it commands from the IDE Serial Monitor @ 57600.
Type in Commads as F011 to set seconds to 11,
F135 to set minutes to 35, etc.

Read the code for the other registers. Make sure to use data that is within the range of the register you writing.

/*
Test of RTC DS1307 via I2C.
 Counts 
 Seconds, 
 Minutes, 
 Hours, 
 Date of the Month, 
 Month, 
 Day of the week, and 
 Year with Leap-Year
 
 56 bytes battery backed RAM
 Square Wave Output, can connect to INT2/D6 or PD7
 */

/*
Modified to Run thru IDE Serial port
*/
#include <Wire.h>

//variables
byte seconds_address = 0x00;
byte seconds; // bit 7 = Clock Halt, Enabled = 0, Halt = 1
// bits 6-5-3 = tens of seconds 0-6,  bits 3-2-1-0 = units of seconds, 0-9

byte minutes_address = 0x01;
byte minutes;  // bits 6-5-4 = tens of minutes, bits 3-2-1-0 = units of minutes

byte hours_address = 0x02; 
byte hours;  // 7=0. 6 = 1 for 12 hr, 0 for 24 hr.
// bit 5: 12 hr mode = AM(0)/PM(1). 24 hr mode = upper tens of hrs
// bit 4 =  lower tens of hrs, bits 3-2-1-0 = units of hours (0-9)

byte day_week_address = 0x03; 
byte day_week = 0; // range 01-07

byte date_month_address = 0x04;
byte date_month = 0; // range 01-31

byte month_address = 0x05;
byte month = 0; // range 01-12

byte year_address = 0x06;
int year = 0; // upper byte 0-9, lower byte 0-9

byte square_address = 0x07;
byte sqwe = 0;  // square wave enable
// Out-0-0-Sqwe-0-0-RS1-RS0
// Out, Sqwe = 0/0 - Square wave output = 0
// Out, Sqwe = 1/0 - Square wave output = 1
// Out, Sqwe = 0/1 or 1/1 - Square wave output per RS1/RS0
// RS1/RS0 = 00 = 1 Hz
// RS1/RSo = 01 = 4 KHz
// RS1/RS0 = 10 = 8 KHz
// RS1/RS0 = 11 = 32 KHz

byte RTC_ram_address = 0x08; //range = 08-63, 0x08-0x3F

int RTC_address = 0x68; // 1101 000 

byte incomingCommand = 0;
byte RTC_write_command = 0;
byte RTC_read_command = 0;
byte RTC_ram_command = 0;

// use F0xx, F1xx,F2xx, F3xx, F4xx, F5xx, F6xx, F7xx
// to send one register write commands
// use E0xx to read registers back - not coded yet
// use C0xx to read RAM back - not coded yet

byte incomingRegister = 0;
byte RTC_register = 0;
byte incomingData1 = 0;
byte incomingData2 = 0;
byte new_data = 0;
byte outgoingData = 0;
int delay_time = 100;

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long duration = 5000;

void setup() {
  Wire.begin(); // no address, we are master
  Serial.begin (57600);  
  Serial.flush();
  currentMillis = millis();  
}

void loop() {

  if (Serial.available() >3){
    incomingCommand = Serial.read();
    incomingRegister = Serial.read();
    incomingData1 = Serial.read();
    incomingData1 = incomingData1 - 0x30; // convert ASCII to HEX
    incomingData2 = Serial.read();
    incomingData2 = incomingData2 - 0x30;  // convert ASCII to HEX
    new_data = (incomingData1 << 4) + incomingData2;  // put the Upper/Lower nibbles together
    Serial.print ("command ");
    Serial.println (incomingCommand);
    Serial.print ("register ");
    Serial.println(incomingRegister);
    Serial.print ("data1 ");
    Serial.println (incomingData1, HEX);
    Serial.print ("data2 ");
    Serial.println (incomingData2, HEX);
    Serial.print ("combined data ");    
    Serial.println (new_data, HEX);
    
  }
  // *******************************************
//  RTC_write_command = incomingCommand & 0xF0;  // mask off high byte
//  if (RTC_write_command == 0xF0){  // check for Write command
if ((incomingCommand == 'F') | (incomingCommand == 'f')){
  incomingCommand = 0;  // reset for next pass
//    RTC_register = incomingCommand & 0x0F;  // mask off low btye
//    incomingCommand = 0;
//    new_data = incomingData;
    Serial.println (" Sending a command ");
//    switch (RTC_register){
switch (incomingRegister){
  case '0': // write seconds
        Serial.println ("Seconds ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(seconds_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
      delay (delay_time);
      break;
    case '1': // write minutes
    Serial.println ("Minutes ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(minutes_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
      delay (delay_time);
      break;
    case '2': // write hours
        Serial.println ("Hours ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(hours_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '3': // write day
        Serial.println ("Day ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(day_week_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '4': // write date of month
        Serial.println ("Day of Month ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(date_month_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '5': // write month
        Serial.println ("Month ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(month_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '6': // write year
        Serial.println ("Year ");
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(year_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '7': // write square wave
        Serial.println ("Square Wave ");
    Serial.println (RTC_register, HEX);
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(square_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
    case '8': // write RAM
        Serial.print ("RAM ");
    Serial.println (RTC_register, HEX);
      Wire.beginTransmission(RTC_address); // select device
      Wire.send(RTC_ram_address);          // queue the register
      Wire.send(new_data);                  // queue data
      Wire.endTransmission();            // send it
     delay (delay_time);
      break;
      // all others,do nothing
      Serial.println ("Invalid command ");
    }  // end Switch
  } // end if command == 'F'
  // ************************************

  currentMillis = millis();
  if ( (currentMillis - previousMillis) >= duration){
    previousMillis = currentMillis;  
    // Reset the register pointer  
    Wire.beginTransmission(RTC_address);  
    Wire.send(0x00);  
    Wire.endTransmission();   

    Wire.requestFrom(RTC_address,8 );  
    seconds = Wire.receive();  
    minutes = Wire.receive();  
    hours = Wire.receive();  
    day_week = Wire.receive();  
    date_month = Wire.receive();  
    month = Wire.receive();  
    year = Wire.receive();  
    sqwe = Wire.receive();

    // Seconds 
    // bit 7 = Clock Halt, Enabled = 0, Halt = 1
    // bits 6-5-3 = tens of seconds 0-6,  bits 3-2-1-0 = units of seconds, 0-9 

    // Hours
    // 7=0. 6 = 1 for 12 hr, 0 for 24 hr.
    // bit 5: 12 hr mode = AM(0)/PM(1). 24 hr mode = upper tens of hrs
    // bit 4 =  lower tens of hrs, bits 3-2-1-0 = units of hours (0-9)

    Serial.print ("Hrs " );
    Serial.print (hours, HEX);
    Serial.print (" Mins ");
    Serial.print (minutes, HEX);
    Serial.print (" Secs ");
    Serial.print (seconds, HEX);
    Serial.print (" Day ");
    Serial.print (day_week, HEX);
    Serial.print (" Date ");
    Serial.print (date_month, HEX);
    Serial.print (" Month ");
    Serial.print (month, HEX);
    Serial.print (" Year 20");
    Serial.print (year, HEX);
    Serial.print (" Square Wave ");
    Serial.println (sqwe, HEX);

  }
}

Moderator edit: code tags added.

(deleted)

Hi, I seem to be in a similar position.

I'm using a Uno along with the Adafrauit data logging shield (Adafruit Data logging shield for Arduino [v1.0] : ID 243 : $24.80 : Adafruit Industries, Unique & fun DIY electronics and kits), and have wired it exacly as per their instrutions, and used all their library code to get it working.

All sample functions on the shield run fine, other than the RTC which just doesn't tick, sticking on whatever time it was given with the "RTC.adjust" function, even after powering the board down, so I assume the battery/connection is fine.

I have run the "simple" (can't wait for complex) sketch above, but no ticking (I assume there should be)....here's example output:

Hrs 0 Mins 0 Secs 11 Day 1 Date 1 Month 1 Year 200 Square Wave 3
command F
register 1
data1 2
data2 2
combined data 22
Sending a command
Minutes
Hrs 0 Mins 22 Secs 11 Day 1 Date 1 Month 1 Year 200 Square Wave 3
Hrs 0 Mins 22 Secs 11 Day 1 Date 1 Month 1 Year 200 Square Wave 3
Hrs 0 Mins 22 Secs 11 Day 1 Date 1 Month 1 Year 200 Square Wave 3
command F
register 4
data1 2
data2 4
combined data 24
Sending a command
Day of Month
Hrs 0 Mins 22 Secs 11 Day 1 Date 24 Month 1 Year 200 Square Wave 3
Hrs 0 Mins 22 Secs 11 Day 1 Date 24 Month 1 Year 200 Square Wave 3
Hrs 0 Mins 22 Secs 11 Day 1 Date 24 Month 1 Year 200 Square Wave 3

And now when i run Adafruit's setup sketch with "RTC.adjust()" function, the clock is stuck on 2000/1/24 0:22:11 instead of being stuck on the current time!!

Any further ideas would be much appreciated....

I think the reason is the RTC module is overpriced LOL
Post your code. There are multiple reasons this would not work. I suspect you didn't make an effort to tell the RTC to run but nothing can be said solid without seeing code.

BTW, here is my shield, a better solution with library to make menus but It won'twork with the shield you got without major modifications.

Nice shield - now I have shield envy and a stopped RTC.

I did tell the RTC to start running, in fact I was really shouting at one point.

The library was from Adafruit based on JeeLabs' code GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library

Here is Adafruit's setup sketch which I used:

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

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

The output is as follows:

2011/9/4 20:49:43
since midnight 1/1/1970 = 1315169383s = 15221d
now + 7d + 30s: 2011/9/11 20:50:13

2011/9/4 20:49:43
since midnight 1/1/1970 = 1315169383s = 15221d
now + 7d + 30s: 2011/9/11 20:50:13

2011/9/4 20:49:43
since midnight 1/1/1970 = 1315169383s = 15221d
now + 7d + 30s: 2011/9/11 20:50:13

There was no "RTC is Not Running!" error displayed, but still no ticking...
Thanks

Code seems identical to the source you downloaded from.

It is strange that you do get the up to date time, apparently from somewhere, "RTC.adjust(DateTime(DATE, TIME));" I suspect. But you don't get the serial message.

The begin method, according to their code, returns a 1. It doesn't nothing to set the clock. So, is that time "2011/9/4 20:49:43" the approximate time when your code was compiled in your time zone?

My other suspicion is that the crystal is broken or not connected well or shorted so there is no crystal pulse for the RTC to increment its time. Check the connection/soldering.

You can always buy my shield as an alternative :wink:

Yes, that's local time in the UK.

I'll check the soldering, I'm sure it's my fault somewhere....

cheers