Go Down

Topic: Project Timer with DS1307 - Array of TimeElements; - Is Possible ? (Read 5688 times) previous topic - next topic

gnusso

Good Afternoon :-),

I'd like to implement a timer for schedule operation with arduino using DS1307, well do you know where I can start ?

my intention is store the timer inside arduino eeprom and check each time if the time is equal to or greather than the time set,

my focus is do something easy to do,

Thanks
Andrea

johncc

http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html
http://playground.arduino.cc/Code/time
https://github.com/johnmccombs/arduino-libraries/tree/master/TimeAlarms  (now included in Arduino Time library AFAICT)

Cheers,
John

gnusso


gnusso

Good Morning John, looking the library what I've understood is that is possible set timer during the day,

for example i'd like to set timer for tomoroww or tuesday or in another day choose is possible to do that ?

like this:

start timer: 22/01/2013  15:45
stop  timer: 24/01/2013  20:30

thanks for the information,
gnux

UKHeliBob

Using TimeAlarms you can set an alarm to trigger any date and time.  When that alarm is triggered the the actions that you specify will be carried out.  This could include setting the alarm to trigger again.

From the readme file

"If you want to trigger once at a specified date and time you can use the trigger Once() method:
  Alarm. triggerOnce(time_t value,  explicitAlarm); // value specifies a date and time
(See the makeTime() method in the Time library to convert dates and times into time_t)"
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

gnusso

Thanks, if i not understood bad please correct me if i wrong

Alarm.timerOnce(time_t value,  explicitAlarm);

time_t_value --> is my date 22/01/2013 12:23 --> using the excel conversion is in number 41296.52

well at this point should conver my date in number and how can i do for do it ?

Thanks,
gnux

gnusso

I've looked into the library ...

but Im not able to use an a pratical example for doing the coversion ...

could you help kindly me ?

Thanks,
gnux

gnusso

So i've did several try but i don't undestand boa use the function, can some Give me an example ... Kindly ? :-) thx gnux

gnusso

Hi,
Could be something like that ?
for example :  22/01/2013 17:12:00

  tm.Year = 2013;
  tm.Month = 01;
  tm.Day = 22;
  tm.Hour = 17;
  tm.Minute = 12;
  tm.Second = 00;
  Alarm.timerOnce(makeTime(tm), OnceOnly) ;

Thanks
Gnux



johncc

Yes you are almost there! :)

In fact, instead of typing that into a forum post and hitting "Submit",

You could type it into an empty sketch (surrounded by setup(){...}) and hit "Verify".  Any error messages might guide you the rest of the way.

It is often faster than the forum too! :)

Cheers,
John


gnusso

Yes, I'm completely agree with you :-) but today I was at work without time for try to do it :-) ...

and then I've Im waiting a input for start in right direction ;-) only that :-) ... in the meantime the unique things that I was able to do was looking inside the forum that was another similar topic ...

gnux

gnusso

#11
Jan 22, 2013, 07:59 pm Last Edit: Jan 22, 2013, 08:17 pm by gnusso Reason: 1
For example I've did this simply sketch:

Code: [Select]


#include <Time.h>
#include <TimeAlarms.h>

void setup()
{
 Serial.begin(9600);
 setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011

 tm.Year = 2011;
 tm.Month = 01;
 tm.Day = 01;
 tm.Hour = 8;
 tm.Minute = 31;
 tm.Second = 00;
 Alarm.timerOnce(makeTime(tm), OnceOnly) ;

 // Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds    
              // called once after 10 seconds
}

void  loop(){  
 digitalClockDisplay();
 Alarm.delay(1000); // wait one second between clock display
}

// functions to be called when an alarm triggers:

void OnceOnly(){
 Serial.println("This timer only triggers once");  
}

void digitalClockDisplay()
{
 // digital clock display of the time
 Serial.print(hour());
 printDigits(minute());
 printDigits(second());
 Serial.println();
}

void printDigits(int digits)
{
 Serial.print(":");
 if(digits < 10)
   Serial.print('0');
 Serial.print(digits);
}


I received back the error : 'Tm was not declare in this scope' ... Then I've declared the type of variable looking the library ... but understanding was that tm should be a method of timer library correct and is not necessary to declare but just call ...

So declaring the variable

static tmElements_t tm;

the error during the compile is disappeared but the condition is never verified ...

where i wrong ?

I come back after 10 hours of work thanks for to be patient ...

thx to all for the support,
gnux

johncc


For example I've did this simply sketch:
...
I received back the error : 'Tm was not declare in this scope' ...
...


This is excellent.  The message is telling you very specifically, that you are trying to use a variable which has not been declared, or at least not declared in an appropriate place.  "Declared" means like this:
Code: [Select]


int g;   // variable g is declared here

void loop(){
  int loc;  //variable loc is declared here

  g = g + 1;  // variable g is used here

  loc = 7;  // variable loc is used here
  int i=43;  // variable i is both declared and used here
  i= i - 1;   //
}


So what your message is saying is that you're trying to use a variable called "tm" and there is none.  For your code it is very simple to fix:

Code: [Select]

    ...
    TimeElements tm;    // declare variable tm here
    tm.Year = 2011;      // begin using variable tm here
    tm.Month = 01;
    ...
   
Quote

Than i shouldn't received this kind of issues. ...
where i wrong ?


I can't say that that is the only problem with your sketch, but its a start...

Cheers,
John

gnusso

Ho thx for the advise :-) so i ve see that was miss the declaration infact i ve tried to declare in this way

static tmElements_t tm;

And the compile was ok

But the conditi in was never verified , so ill try your suggest and ill let you know thanks gnux

gnusso

So, also changing the the declaration now i didn't have the errors from the compiler ...

but the condition is never true ...

and I don't understand why ... I've also did a Serial.println of makeTime(tm) but the number that I've tell me nothing if didn't have another function that convert back the value ...

:-( so now I'll let's go to bed because I'm completely fuse ...

thanks for the support,
gnux

Go Up