Pages: 1 ... 12 13 [14] 15 16 17   Go Down
Author Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions  (Read 67875 times)
0 Members and 2 Guests are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The only time my alarms trigger is if setTime() is in my setup. 
Do you mean that the only way that the alarms trigger is if they are defined after the time is set? If so, you'll need to re-define when the alarms should happen each time you set the time.

I still think that your approach to determining when to reset the time is fundamentally flawed.
Logged

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

Hello all and HAPPY NEW YEAR!

I have a problem with time library (or maybe i can not find the correct solution) if i can tell like this.
I use next code:

void setup()
{
setSyncProvider(RTC.get);  // it set clock with 12:19:43-5/10/2010 but the real value setted by me is (20,21,0,31,12,13);
}

in loop function i set the time with real time and date
example : setTime(20,21,0,31,12,13);

if i restart (don't power on/off) arduino the rtc works fine with setted values
if i restart the arduino  the clock it set up again from setSyncProvider(RTC.get) to a bad value 12:19:43-5/10/2010
what happend?

if i don't use setSyncProvider(RTC.get) i don't have value for time and date
can i use other function or not for read after restart (power of / on)  the values of rtc who i setted in it manualy?

MANY THANKS TO ALL!
Logged

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

Code:
setSyncProvider(RTC.get);  // it set clock with 12:19:43-5/10/2010 but the real value setted by me is (20,21,0,31,12,13);
The code does NOT do what the comment says. Not even close.

Quote
if i restart the arduino  the clock it set up again from setSyncProvider(RTC.get) to a bad value 12:19:43-5/10/2010
what happend?
You have a completely incorrect understanding of what setSyncProvider() is doing. All it does is register a function to call when the time that the Arduino understands needs to be synced with the time from another source. It does NOT set the time of the external source.

Quote
if i don't use setSyncProvider(RTC.get) i don't have value for time and date
You would if you called RTC.get() yourself.

Quote
can i use other function or not for read after restart (power of / on)  the values of rtc who i setted in it manualy?

You could post all of your code. The only thing wrong with your snippet is the comment. Therefore, the problem MUST be in code you didn't bother to post.
Logged

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

Many thanks for your answer.

I understand now.
I use for set rtc
rtc.write(tm);
and for read
rtc.read(tm).

I understand that rtc time is different what is set for time/timealarm with setime(....).

If I want to use the alarm I must put this in code?

loop()
{
  rtc.read(tm);
  setTime( "this parse rtc values ");
}

must I put in setup:
setSyncProvider(rtc.get()); ???

Many thanks again for all of your support.
HAPPY NEW YEAR.
« Last Edit: January 01, 2014, 08:27:01 am by tao13 » Logged

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

Where in that second code have you connected the Time library to the time that the RTC returned? If you have an RTC, why is it necessary to use the Time library?

All of the Time functions (hour(), minute(), second(), etc.) call now(), which determines whether the function defined by the setSyncProvider() call needs to be called to update the Time library's idea of what time it is.

Since your second code does not call setSyncProvider, now() has no way of knowing what time it really is, despite there being a RTC that it could get the time from.

You would need to use setTime(RTC.get()) to tell the Time library what time the RTC thinks it is.

But, before you bother with that, you need to make sure that your RTC is working. There were examples that came with your RTC that you should be using to verify that the RTC IS functioning.
Logged

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

Hi and thanks again.
Yes , I have a rtc ds1307 module.
I read the rtc time and it is ok works fine.
I need to use alarm function from timealarm library so like you said
in setup function I must put :
setTime(RTC.get()) without any setSyncProvider
is it right?

another question , if I put want to use one of next functions (web page push a button and define one of them)
Alarm.alarmRepeat
Alarm.timerRepeat
Alarm.timerOnce
I have how delete/deselect/unrun them in one moment without reset arduino?

Many thanks again for your support
« Last Edit: January 01, 2014, 01:56:48 pm by tao13 » Logged

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

Quote
in setup function I must put :
setTime(RTC.get()) without any setSyncProvider
is it right?
You can use the setTime(RTC.get()); call if you are not interested in having the Arduino access the RTC periodically. The Arduino is a lousy time keeper, over any length of time. Having it access an accurate time keeper, like the RTC, periodically is generally a good idea.

The setSyncProvider() function is how you tell the Arduino to get a new time from the accurate source. That is, it is how you tell the Time class what function to call to get a new time.

Quote
if I put want to use one of next functions (web page push a button and define one of them)
A web page can't push a button. A web page can display a button. The user can press the button, which will cause the browser displaying the page to make a new GET request of the server that served the original page (usually, the request is to the same server, though, in theory, it doesn't need to be). The server then interprets the new GET request, and sees that it needs to do something, based on the added information in the GET request.

Are you planning on having the Arduino wear an ethernet shield, and be a server?

Quote
I have how delete/deselect/unrun them in one moment without reset arduino?
I don't understand this question. The functions listed return the ID of the alarm that is set. You can store that ID, and later remove the alarm, reset the alarm, etc.
Logged

Offline Offline
Edison Member
*
Karma: 63
Posts: 2476
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The setSyncProvider() function is how you tell the Arduino to get a new time from the accurate source. That is, it is how you tell the Time class what function to call to get a new time.
As Pauls says.
Add this line to the setup() function:
    setSyncProvider(RTC.get);    //Use the RTC to synchronize the Arduinop clock.   Use the RTC.get() function  to do this.

Also you can add this line, however it does default to 300 seconds if you don't:
    setSyncInterval(600);           //Sync the clock every 600 seconds (10 minutes)
                                                     //So, every 10 minutes the Arduino clock is set to what is in the external RTC.
 
Logged

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

Hi all and many thanks for your answers.

I understand now and it works fine.
I use an rtc and arduino mega and Ethernet shield.
I know  about" push button" but my English is not very good and maybe I can explain very well.
The button works and send a command and parse it and setime.
Understood setSyncProvider now.

All are cleare now without one thing : disarm an alarm
if I have an alarm set in setup or whatever
in one moment I need to delete it / remove it from memory or loop function , rest it
what function I can use.
example:
in setup I set Alarm.alarmRepeat( time , functionname)
and after a time in loop I need to disabled alarm who setted in setup
how I do this.

thanks again for all of your support.


Logged

Offline Offline
Edison Member
*
Karma: 63
Posts: 2476
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and after a time in loop I need to disabled alarm who setted in setup
how I do this.
I don't know any way of deleting it and then recovering the memory (RAM) it uses, but if you want to disable
the alarm function that it Calls you might try the following idea:
Code: (NOT TESTED)
void setup()
{
  Alarm.alarmRepeat(11,00,0, AlarmAMpills);   
  //Other stuff
}

void loop()
{
  //do stuff

  if (a_condition == true)
  {
    disabled = true;
  }
}
 
//========================================== 
  void AlarmAMpills()
{
  if (disabled == true)
    {
    return;  // don't take any further action since this function is disabled
    }
  Serial.print("Take your morning pills");
  // Process some more stuff as needed

}
//==========================================
Logged

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

Thanks for your idea but it doesn't remove or disabled alarm from memory.
it is o way with ALARMID but it doesn;'t support very much alarm.
I need to run 70 alarms in memory (10 programs on 7 days).
Thanks.
Logged

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

Quote
I need to run 70 alarms in memory (10 programs on 7 days).
By default, the TimeAlarm class supports 6 alarms.

It's time for you to put your tap dancing shoes away. You keep saying "That didn't work" without saying what "that" is. Post your code, or solve your problem yourself.
Logged

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

Thanks again anyway for your answer.
I solved my problem without timealarm and time library for next reasons:
1 - Alarm.repeate doesn't work I have all libraries in my code (not trigger it)
#include <DS1307RTC.h>
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>

2. timealarm doesn't have a function to execute a code between 2 times/date some like
Start 20:00:00 06/jan/2014
Stop 21:10:00 07/jan/2014

Thanks again to all.
Logged

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

Quote
Is there anyway to "set" the UNIX time from a variable?
Yes. HTH.
Logged

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

How do I do that?
Write the proper code.

When you stop playing what if games, and post some code that defines the context of your question, we can actually help.
Logged

Pages: 1 ... 12 13 [14] 15 16 17   Go Up
Jump to: