RTC -timer issue

Dear all,
I am trying to do simple program where its flow chart as below.
1)how to run Arduino time , is there any library for it.
2)how to syn arduino time with rtc time()?? any coding example??mean to say if RTC failed it should run on arduino time.
please help me in above two issue either in coding or sharing some link

if nothing worked,what will be alternate option.

option 1 in my mind:
board : arduino UNO v3
it has limited eeprom i.e 1kb .

What do you means "Arduino" time the arduino has no clock!. All yo can do is elapsed time!.

Mark

holmes4: What do you means "Arduino" time the arduino has no clock!. All yo can do is elapsed time!.

Mark

I wanted to simple way.I have RTC DS1307 . Assume that my RTC has gone bad , i wanted to run my program on the basis of Arduino time.Arduino time run on basis of timer of MCU. if arduino board get shutdown it might set default value. SO its OK for me.@that time we can take other action or which rarely to happen , since controller are on running with battery .

pseudo code: RTC failed can be check using Wire library. check if (rtc failed) yes: get arduino time no : write RTC time to Arduino time or syn with arduino time

I know that there is a time.h library but I never ever use it before, and I don't know if is useful in this case.

Instead of that I did a kind of RTCtimer emulator with just arduino and a LCD display 7seg 4dig. be aware: the code is form a debugging session and may content some missing parts, please double check.

// display 4 digit 7 segments
int Digit1 = A0;
int Digit2 = A1;
int Digit3 = A2;
int Digit4 = 5;

int SegmentA = 6;
int SegmentB = 7;
int SegmentC = 8;
int SegmentD = 9;
int SegmentE = 10;
int SegmentF = 11;
int SegmentG = 12;
int SegmentDP = 13;

byte H = 0;
byte h = 5;
byte M = 2;
byte m = 2;
int ms = 0;
byte s = 0;

unsigned long mills;
unsigned long old_mills;

byte del = 1;

int calib = 235;


//235 se adelanta unos milisegundos
//236 se atraza unos milisegundos
// cambiar el "del" aumenta o disminuye mucho la velocidad
void setup() {
  // put your setup code here, to run once:
  pinMode(Digit1, OUTPUT);
  pinMode(Digit2, OUTPUT);
  pinMode(Digit3, OUTPUT);
  pinMode(Digit4, OUTPUT);

  pinMode(SegmentA, OUTPUT);
  pinMode(SegmentB, OUTPUT);
  pinMode(SegmentC, OUTPUT);
  pinMode(SegmentD, OUTPUT);
  pinMode(SegmentE, OUTPUT);
  pinMode(SegmentF, OUTPUT);
  pinMode(SegmentG, OUTPUT);
  pinMode(SegmentDP, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly: 
  

   ms = ms + 1;
   if (ms >= calib){
   ms = 0;
   s= s + 1;
   }
   

  if (s >= 60){
    s = 0;
    m = m + 1;
  }
  if (s%2){
    digitalWrite(SegmentDP,LOW);
  }
  else{
    digitalWrite(SegmentDP,HIGH);
  }
  if (m >= 10){
    m = 0;
    M = M + 1;
  }
  if (M >=6){
    M = 0;
    h++;
  }
  if ( h >= 10){
    h = 0;
    H = H + 1;
  }
  if (H >= 10){ 
    H = 0; 
  }

  if ((H==1) && (h==3)){
    H=0;
    h=1;
  }

  numero(m);  
  digitalWrite(Digit1,HIGH);
  delay(del);
  digitalWrite(Digit1,LOW);
  numero(M);
  digitalWrite(Digit2,HIGH);
  delay(del);
  digitalWrite(Digit2,LOW);
  numero(h);
  digitalWrite(Digit3,HIGH);
  delay(del);
  digitalWrite(Digit3,LOW);
  numero(H);
  digitalWrite(Digit4,HIGH);
  delay(del);
  digitalWrite(Digit4,LOW);
//ultimo ajuste
delayMicroseconds(10);
}

// numeros
void numero(int i) //dibuja el numero especificado antes se debe encender el digito
{

  switch (i){

  case 1: 
    digitalWrite(SegmentA, HIGH);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, HIGH);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, HIGH);
    digitalWrite(SegmentG, HIGH);
    break;

  case 2:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, HIGH);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, LOW);
    digitalWrite(SegmentF, HIGH);
    digitalWrite(SegmentG, LOW);
    break;

  case 3:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, HIGH);
    digitalWrite(SegmentG, LOW);
    break;

  case 4:
    digitalWrite(SegmentA, HIGH);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, HIGH);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, LOW);
    break;

  case 5: 
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, HIGH);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, LOW);
    break;

  case 6:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, HIGH);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, LOW);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, LOW);
    break;

  case 7:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, HIGH);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, HIGH);
    digitalWrite(SegmentG, HIGH);
    break;

  case 8:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, LOW);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, LOW);
    break;

  case 9:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, HIGH);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, LOW);
    break;

  case 0:
    digitalWrite(SegmentA, LOW);
    digitalWrite(SegmentB, LOW);
    digitalWrite(SegmentC, LOW);
    digitalWrite(SegmentD, LOW);
    digitalWrite(SegmentE, LOW);
    digitalWrite(SegmentF, LOW);
    digitalWrite(SegmentG, HIGH);
    break;
  }
}

this is the link of that topic: http://forum.arduino.cc/index.php?topic=174496.msg1295737#msg1295737

seems to be precise but is not, don't remember how many time is defaced but it can be adjust with delay() and microdelay() LOL in that tread I post that I was using a RTC module but is only mounted in the bread board, noting to do with the code. I suppose that I was starting with the (7,4) lcd

Dear all,

Below i posting pupose of above isssue. When your running over the RTC it work fine . As soon as removed the PIN a4 and a5 it show these errors. Since it cant find signal. At this instant i wanted to run on Arduino time

have a look here http://www.pjrc.com/teensy/td_libs_Time.html

nilton61:
have a look here
http://www.pjrc.com/teensy/td_libs_Time.html

I tested below code , it work fine with /without RTC. i have attached sample code i am working on . I never want to keep it main loop. I want to run only when rtc is get error

/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

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

void setup()  {
  Serial.begin(9600);
  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()
{
   digitalClockDisplay();  
   delay(1000);
}

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.rar (2.6 KB)

IS there any update on the below problem of the RTC