Pages: 1 [2] 3 4 ... 17   Go Down
Author Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions  (Read 59485 times)
0 Members and 1 Guest are viewing this topic.
Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest your create a new thread and post a link  here so I and others interested in your application can help.


mem,here is my next question about my project, hope you can help
http://arduino.cc/forum/index.php/topic,67289.msg494141.html#msg494141
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No errors were reported with the the beta code so the playground download has been updated.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check my project at http://arduino.cc/forum/index.php/topic,67127.0.html

I javel thé sketch and à sérial interface also have a jquery web interface
Logged

Rio de Janeiro, Brazil
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
Software developer, free software activist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Time and TimeAlarms are libraries for handling time and time based tasks on Arduino. The code can be found here

This thread is for help on how to use these libraries and suggestions for future improvements.

A thread specifically for discussing issues relating to updates in the beta test version can be found here (that thread will be closed after the beta testing is completed.


Hello mem,
I needed to use DS1307 Real-Time Clock on a project and saw the Time library, but I thought it was too big for what I needed (just to know day, month, year, hour, minute and second from DS1307), so I decided to create a new, simple library to achieve this task and its code is at GitHub:

https://github.com/turicas/DS1307

I think we should integrate it, maybe creating a "driver interface" (just some conventions) so we can create drivers for many RTC chips and use the same code. What do you think?

Other thing I think that should be changed in Time library is the namespace of functions. Maybe using Time.hour(), Time.day() etc. instead of directly hour(), day() etc.
Logged

Blog pt_BR: http://blog.justen.eng.br/
Curso de Arduino (Arduino Course, in Brazil) - http://www.CursoDeArduino.com.br/

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hello mem,
I needed to use DS1307 Real-Time Clock on a project and saw the Time library, but I thought it was too big for what I needed (just to know day, month, year, hour, minute and second from DS1307), so I decided to create a new, simple library to achieve this task and its code is at GitHub:

https://github.com/turicas/DS1307

I think we should integrate it, maybe creating a "driver interface" (just some conventions) so we can create drivers for many RTC chips and use the same code. What do you think?

Other thing I think that should be changed in Time library is the namespace of functions. Maybe using Time.hour(), Time.day() etc. instead of directly hour(), day() etc.


Hi alvarojusten

Thank you for sharing your library. I have seen many  DS1037 Arduino libraries and yours is one of the simplest (that’s  a compliment).  It does use less flash memory than the Time library but it actually seems to use more data (your sketch  uses 540 bytes of RAM, the Time library code posted below uses 482 bytes of RAM).

Code:
/*
 *  A simple sketch to display time from a DS1307 RTC
 *
 */

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

char dateTime[20];

void setup()  {
  Serial.begin(9600);     
}

void loop()
{
   setTime(RTC.get());
   sprintf(dateTime, "%4d-%02d-%02d %02d:%02d:%02d", year(),
            month(), day(), hour(),minute(), second()) ;
    Serial.print(dateTime);
    Serial.print(" - day of week: ");
    Serial.println(dayStr(weekday()));

   delay(1000);
}

Here are some advantage of using the Time library version:
-   You can easily calculate the difference between two times
-   The time format is based on a standard that almost every programming platform can handle
-   The same sketch code can be used with a selection of time sources such as RTC, NTP( internet time standards), Radio Clocks, GPS …
-   You can use the TimeAlarms library to add timers and time of day alarms.
Logged

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi [again], Mem.

how to convert now() function (=>unixtime) to character array (char[11])?Is it possible to do?
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many C compilers have a function named ctime that produces a date string but I don't think its available with the arduino tools. I have always used multiple print statements to display the data, is there a reason you can't do that for your application?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


ctime is not found in - http://www.nongnu.org/avr-libc/user-manual/index.html -

maybe this link helps - http://www.jbox.dk/sanos/source/lib/time.c.html -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob, did you try to use it in the Arduino IDE?
If so, a brief example would be useful.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No,

however I did use the RTC lib for the DS1307 - - https://github.com/adafruit/RTClib -  It includes a DateTime Class that has all needed to implement a  time2string(...) function
Note DateTime is year 2000 based, the essential code is in the DateTime constructor that can be transformend quite easily, see below:

Code:
void setup()
{
  Serial.begin(115200);
  Serial.println("UnixTime simulator :) ");
}

void loop()
{
  char buffer[20];
  time2string(millis(), buffer);
  Serial.print(millis());
  Serial.print(" ==>  ");
  Serial.println(buffer);
}

uint8_t daysInMonth [] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

void time2string(unsigned long t, char *buf)
{
  uint8_t yOff, m, d, hh, mm, ss;

  ss = t % 60;
  t /= 60;
  mm = t % 60;
  t /= 60;
  hh = t % 24;
  uint16_t days = t / 24;
  uint8_t leap;
  for (yOff = 0; ; ++yOff) {
        leap = yOff % 4 == 0;
        if (days < 365 + leap)
            break;
        days -= 365 + leap;
  }
  for (m = 1; ; ++m) {
    uint8_t daysPerMonth = daysInMonth[ m - 1];
    if (leap && m == 2)
      ++daysPerMonth;
    if (days < daysPerMonth)
        break;
    days -= daysPerMonth;
  }
  d = days + 1;
  sprintf(buf,"%4d-%02d-%02d %02d:%02d:%02d", 1970+yOff, m,d, hh,mm,ss);
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks Rob, Mem..

Quote
Many C compilers have a function named ctime that produces a date string but I don't think its available with the arduino tools. I have always used multiple print statements to display the data, is there a reason you can't do that for your application?
My Goal is sending unixtime via Wireless, then I have data in char array (char[11])
so when i try to send data unixtime which it is unsigned long, the compiler give error message:
Code:
incompatible types in assignment of 'time_t' to 'char [11]'

Rob, I use Mem's library (Time, TimeAlarm, DS1307RTC)..Any suggestion how to do it for DS1307RTC library?thanks anyway for the help.

thanks a lot.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you mean some thing like this?

Code:
#include "stdlib.h"

void setup()
{
  Serial.begin(115200);
  char buffer[11];
  unsigned long unixtime=1234567890L;  // L for long
  ltoa(unixtime, buffer, 10);
  Serial.println(buffer);
}

void loop(){}
(code not tested)

see - http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html - search for ltoa

UPDATE
-- added void before loop()
« Last Edit: August 06, 2011, 05:50:57 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


do you mean some thing like this?

Code:
#include "stdlib.h"

void setup()
{
  Serial.begin(115200);
  char buffer[11];
  unsigned long unixtime=1234567890L;  // L for long
  ltoa(unixtime, buffer, 10);
  Serial.println(buffer);
}

loop(){}
(code not tested)

see - http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html - search for ltoa

FOOL me, i tried it, but i didn't print the buffer..
Thanks, a lot..i'll try tomorrow. now, 3.05am..here..need a sleep..aha!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need to add void before loop(){}

allready patched in posting above.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you need to add void before loop(){}

allready patched in posting above.

the code just works..thanks, rob..
ltoa and atol will be my new friends..LOL..
Logged

Pages: 1 [2] 3 4 ... 17   Go Up
Jump to: