Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Re: DS 1307 stays behind in time day by day... on: October 04, 2012, 09:55:37 am
Thank you all for your help and ideas!
Regarding Riva:
Thank you for modifying the code. Unfortunately when I am verifying the code I am having an error on line
Code:
if(now.hour == 0) {                     //Is it the midnight hour
.
I changed it to
Code:
if(now.hour() == 0) {                     //Is it the midnight hour
and now it gives me an error on
Code:
  now.seconds(second % 60);       //Put seconds
. The error I get is the following:
Quote
sketch_oct04c.cpp: In function 'void loop()':
sketch_oct04c:38: error: 'class DateTime' has no member named 'seconds'
sketch_oct04c:38: error: 'second' was not declared in this scope
I have stuck with this error.

My code now is :
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"

const int driftComp = 23;    //Seconds to adjust clock by per day to compensate for RTC drift
const int delayComp = 714;  //Milliseconds to delay clock adjust by (driftComp * 1000) - delayCom = 8.5 seconds per 24 hours

RTC_DS1307 RTC;
 LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

void setup () {
   
    lcd.begin(16, 2);
    lcd.clear();
    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 () {
    static boolean driftApplied = false;
   
    DateTime now = RTC.now();
   
    // RTC Drift compensation
    if(now.hour() == 0) {                     //Is it the midnight hour
        if(!driftApplied) {                 //Have I already done drift compensation
            int seconds = now.second();     //Get seconds
            seconds = seconds + driftComp;  //Apply drift
            delay(delayComp);               //Subtract delay
            now.seconds(second % 60);       //Put seconds
            RTC.adjust(now);                //Set clock
            driftApplied=true;              //Signal drift applied
        }
    }
    else{                                   //Not midnight hour
        driftApplied = false;               //Reset drift applied
    }
   
    lcd.clear(); // Clear the LCD screen
    lcd.print("Time: ");
    if (now.hour() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.hour(), DEC); // Output current hour
    lcd.print(":");
    if (now.minute() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.minute(), DEC); // Output current minute
    lcd.print(":");
    if (now.second() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.second(), DEC);
    lcd.setCursor(0, 1);
    lcd.print("Date: ");
    if (now.day() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.day(), DEC); // Output current hour
    lcd.print(":");
    if (now.month() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.month(), DEC); // Output current minute
    lcd.print(":");
    if (now.year() < 10) lcd.print("0"); // Check if we need to add leading zero
    lcd.print(now.year(), DEC);
   
     delay(1000);
}
I have also changed
Quote
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
to
LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

Regarding Jimmy60:
Your way of dealing with the DS1307 sounds very interesting. Could you please sent me your code to have a look?

Many Thanks to all of you!

17  Using Arduino / Programming Questions / Re: DS 1307 stays behind in time day by day... on: October 04, 2012, 06:27:27 am
Thank you Jack and Riva for your answers.
Riva because I am quite new to the Arduino. How can I use your code?
What I am asking is how can I use void adjustClock() function on my program?

My code is a very simple code and i state it below:
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
 
RTC_DS1307 RTC;
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup () {
 
  lcd.begin(16, 2);
  lcd.clear();
  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();
   
  lcd.clear(); // Clear the LCD screen
  lcd.print("Time: ");
  if (now.hour() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.hour(), DEC); // Output current hour
  lcd.print(":");
  if (now.minute() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.minute(), DEC); // Output current minute
  lcd.print(":");
  if (now.second() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.second(), DEC);
  lcd.setCursor(0, 1);
  lcd.print("Date: ");
  if (now.day() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.day(), DEC); // Output current hour
  lcd.print(":");
  if (now.month() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.month(), DEC); // Output current minute
  lcd.print(":");
  if (now.year() < 10) lcd.print("0"); // Check if we need to add leading zero
  lcd.print(now.year(), DEC);
 
  Serial.println();
  delay(1000);
  lcd.clear();
}

Thank you!!!
18  Using Arduino / Programming Questions / DS 1307 stays behind in time day by day... on: October 04, 2012, 05:30:02 am
Hi All,

I am having an Arduino Uno Rev.3 connected with an RTC DS1307 and an LCD 2x16.
I am displaying the time and date using the RTC on the LCD.
After a week I noticed that the time displayed in the LCD and the time in my PC have a difference of a few minutes.
For example: PC time --> 11:04:17 and my RTC -->11:01:41
My RTC is not keeping the time as it should be but stays day by day a little behind from the "actual" time.
Do you have any ideas on how I can synchronize my RTC with my PC system time?

Many Thanks!
19  Using Arduino / Displays / Re: LCD Time and Date stop working when Ethernet code used on: July 26, 2012, 08:01:00 am
Hi Don,

Thank you very much for your help. I changed "LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);" with "LiquidCrystal lcd(8, 7, 5, 4, 3, 2);" and it worked.

Regards,
Steve

20  Using Arduino / Displays / LCD Time and Date stop working when Ethernet code used on: July 25, 2012, 08:16:43 am
Hi,

I am trying to display the Time and the Date from DS1307 on a Hitachi HD44780 and in the same time to control a LED from a Web page using the Ethernet shield of arduino. I can display the Time and the Date using a simple program but when i add the Ethernet function on the program I can only control the LED through the Ethernet but I do not see anything on the LCD. I attach my program to have a look. Please any ideas will be much appreciated.

Many Thanks!
21  Community / Workshops and Events / Any workshops, trainning, courses in UK? on: July 25, 2012, 08:02:48 am
Any workshops, trainning, courses in UK?
22  Using Arduino / Project Guidance / Arduino RTC on a web server on: June 16, 2012, 07:39:30 am
Hi all,

I am trying to have a real time clock on a web page but without using a DS1307 RTC. I want to use the Time library from Arduino. Do you have any ideas on how I can do that?

Many Thanks!!!
Pages: 1 [2]