Pages: 1 ... 5 6 [7] 8 9 10   Go Down
Author Topic: Time Library added to Playground  (Read 28919 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I'm new to this and rusty in C programming...
But after reading the library code, I can't find how you handle millis() overflow !
What will happen if I don't sync for more than 50 days ?
Regards,
Logged

Stockholms utkant
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino e bäst :-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pls, can someone help me with TimeAlarmExample.pde ?

I can not compile without errors, and then I can not Upload the code to the Arduino.

I downloaded everything today, so it's nothing old and new.

I use 0018.

I can not find DateTimeAlarms.o, DateTimeAlarms.cpp or DateTimeAlarms.h
I find the file TimeAlarms.cpp and TimeAlarms.h
I did not change the TimeAlarms.h file.

Thanks. /// Jojje

Here is the errors:
Code:
o: In function `digitalClockDisplay()':
C:\DO...\Temp\build2109978655735871106.tmp/TimeAlarmExample.cpp:72: undefined reference to `hour()'

C:\DO...\Temp\build2109978655735871106.tmp/TimeAlarmExample.cpp:73: undefined reference to `minute()'

C:\DO...\Temp\build2109978655735871106.tmp/TimeAlarmExample.cpp:74: undefined reference to `second()'

o: In function `setup':
C:\DO...\Temp\build2109978655735871106.tmp/TimeAlarmExample.cpp:34: undefined reference to `setTime(int, int, int, int, int, int)'

C:\DO...\Temp\build2109978655735871106.tmp\TimeAlarms\TimeAlarms.cpp.o: In function `AlarmClass::updateNextTrigger()':

C:\Dev\arduino-0018\libraries\TimeAlarms/TimeAlarms.cpp:47: undefined reference to `now()'

C:\Dev\arduino-0018\libraries\TimeAlarms/TimeAlarms.cpp:54: undefined reference to `now()'

C:\DO...\Temp\build2109978655735871106.tmp\TimeAlarms\TimeAlarms.cpp.o: In function `TimeAlarmsClass::serviceAlarms()':

C:\Dev\arduino-0018\libraries\TimeAlarms/TimeAlarms.cpp:207: undefined reference to `now()'

« Last Edit: July 24, 2010, 09:09:36 am by Jojje » Logged

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

Hello, I am trying to make an alarm clock using the DS1307 RTC and a LCD screen. Using a different sketch than the one provided in the library download I have successfully set the date and time on the RTC.

The problem I am having is that when I use the TimeRTC sketch to read the time from the DS1307, the clock runs very fast. When I use a different sketch to read the time it keeps the right time. I would still like to use this library in my project so is there anything that I can do to fix this problem?

Thanks,
K
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The problem I am having is that when I use the TimeRTC sketch to read the time from the DS1307, the clock runs very fast. When I use a different sketch to read the time it keeps the right time. I would still like to use this library in my project so is there anything that I can do to fix this problem?
This does not sound like a library problem. It sounds more like a sketch issue, and how it uses the library.

Post the sketch that works, and the one that is too fast, and we can help with an explanation (maybe) of the problem.
Logged

Stockholms utkant
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino e bäst :-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I download Time.zip again, and open it up in libraries, same as last time, but now everything works. smiley

I don't know why it works now, but who cares. ;D
Logged

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

Thanks for the quick replay Paul, here is the sketch that I used to successfully set/read the time of the RTC.


Code:
// Maurice Ribble
// 4-17-2008
// http://www.glacialwanderer.com/hobbyrobotics

// This code tests the DS1307 Real Time clock on the Arduino board.
// The ds1307 works in binary coded decimal or BCD.  You can look up
// bcd in google if you aren't familior with it.  There can output
// a square wave, but I don't expose that in this code.  See the
// ds1307 for it's full capabilities.

#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68

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

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

// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*void stopDs1307()
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(0x80);
  Wire.endTransmission();
}*/

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers

// UNCOMMENT THE FOLLOWING TO SET THE DATE/TIME


void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
  
}



// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void setup()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();
  Serial.begin(9600);

  // Change these values to what you want to set your clock to.
  // You probably only want to set your clock once and then remove
  // the setDateDs1307 call.

 // UNCOMMENT THE FOLLOWING TO SET THE DATE/TIME

  second = 0;
  minute = 22;
  hour = 18;
  dayOfWeek = 2;
  dayOfMonth = 26;
  month = 7;
  year = 10;
  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  
}

void loop()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print("  Day_of_week:");
  Serial.println(dayOfWeek, DEC);

  delay(1000);
}


Here is the sketch that runs too quickly, it is the example included in the time library download. It seems that the sketch initially reads the correct time but then gets off as it runs almost twice as fast as it should.

Code:
/*
 * 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);
}
Logged

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

Does anyone know why this error: 'time_t' does not name a type In function 'void loop()': occurs in Arduino 0018?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because it doesn't? What sketch are you compiling? What libraries are you using?
Logged

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

I get the error: 'time_t' does not name a type In function 'void loop()': when opening the example TimeRTCSet.pde in Arduino 0018.

The libraries used are:
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>

I presume that there is more than one DS1307RTC.h library?  Which one is the correct one to use and why does it not come with the Arduino 0018 install?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What board do you have selected? I opened a sketch using Tools + Examples + Time + Examples + TimeRTCSet. I selected Verify. It compiled just fine, with the Duemilanove board selected.
Logged

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

Arduino Duemilanove or Nano w/ ATmega328
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the libraries directory, there should be a file called Time.h. Open that file. The 10th line in mine:
Code:
typedef unsigned long time_t;
Does yours have the same line?
Logged

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

Yes, in /usr/share/arduino/libraries/Time/Time.h that line is present.

How do I know if that is the actual Arduino Library directory in use?

Is there a correct set of time related libraries that I can download?
Logged

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

Hi!

First of all thanks for that brilliant library!

At the moment I'm writing a Light Timer with extra for an Aquarium. It's almost done (LCD-Menu with Settings, Backup-Powersupply, Temperature-Control, Feeding-Countdown) But then i got a Problem:

How can i change an already configured repeated alarm without resetting the atmega?

The Light-Timer will be completly controlled through a Display and an rotary encoder with pushbutton. And through this I also want to change the Light on and off time.
 
And another Question:

Didn't someone try to sync the time with an DCF77 receiver?

Greets
Daniel

Logged

Argentina
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
EPIC n00b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, im trying to di a timer that has an start button but weird things happen to me..

in my loop i have

 Alarm.delay(1000);
and the checkbuttons funcion

then, when i press the button
Alarm.timerRepeat(5, RepeatTask);  
is executed

but for some reason if i have alarm.delay(100( the button press is not received it only works if i press it lots of times, non-stop

is there some kind of locking?
im also not interested in keeping/setting any date
Logged

--

Pages: 1 ... 5 6 [7] 8 9 10   Go Up
Jump to: