Time Library added to Playground

I guess I had an older version of Time that didn't have TimeAlarms?

Yes, the TimeAlarms library was only added recently. Perhaps you can report how you get on with the alarms library in the thread linked above.

Hello !

Is it possibe to run the Time-lib with the NPT Internet Time Sync together with a webserver (e.g. Ben Combees Webduino) ?

I didn't tried it already, but maybe there is somebody who have experiences.

Ollie.

I haven't tried it but would expect you could add the relevant code from the NTP example sketch in the download into Bens webduino library.

Bear in mind that NTP uses the UDP protocol so you would need to add the third party UDP library as documented in the NTP example.

If you want to try this, I suggest you get the NTP example sketch running on its own and then consider how you would want to integrate this into webduino.

I would be interested to follow your progress, perhaps create a new thread to cover this specific topic.

I guess I had an older version of Time that didn't have TimeAlarms?

Yes, the TimeAlarms library was only added recently. Perhaps you can report how you get on with the alarms library in the thread linked above.

It was a joy to use!!
your example was simple & thorough enough for me to understand how to use it.

The only confusion I had was timerRepeat is only in seconds and not
formatted like alarmRepeat but it did not take long to figure out time time * 60 to get minutes.

thank you for such a wonderful & versatile library! :wink:

Glasshopper, good to hear you found the library useful

? timerRepeat is only in seconds and not formatted like alarmRepeat ?

You should be able to set timers just like alarms, did you try something like : Alarm.timerRepeat( 1,30,0, TimerTask); // set timer to repeat every 1 hour and 30 minutes

I have created a Visual Basic application based on the code from Moriszen.

Here is the link: http://www.megaupload.com/?d=1A76PJ5F

Nice to see you got it posted .
Does anyone know if the time library will work in idle - low power mode .
I want to have an application that wakes up once or twice a day an logs the time and date (running on batteries) .
any suggestions ?

The time library relies on the Arduino millis timer which services an interrupt every millisecond. This means it will not work in low power mode.

For an application that needs to wake up once or twice a day you would probably need to use a low power Real Time Clock that generated an interrupt that would wake up the Arduino when it needed to log something. Have a look in the playground to see if anyone has published an RTC application that does something like this.

? timerRepeat is only in seconds and not formatted like alarmRepeat ?
You should be able to set timers just like alarms, did you try something like : Alarm.timerRepeat( 1,30,0, TimerTask); // set timer to repeat every 1 hour and 30 minutes

I see..
Alarm.timerRepeat(1, 0, Repeats);
does not work
but
Alarm.timerRepeat( 0, 1, 0, Repeats);
does.

thank you :smiley:

I could add the overloaded versions if that functionality is what most people expect:

timerRepeat(Period, TimerFunction); // Period in seconds
timerRepeat(Minutes, Seconds, TimerFunction); // Period in Minutes & seconds
timerRepeat(Hours, Minutes, Seconds, TimerFunction); // Period in Hours, Minutes & seconds

then Alarm.timerRepeat(1, 0, Repeats) would do the same thing as Alarm.timerRepeat(0, 1, 0, Repeats);

I think you should make overloaded functions in the library. It's more logical.

For example when I say I'm gonna do something in 5 minutes, I don't say I'm gonna do something in 0 hours and 5 minutes :wink:

Btw I have uploaded the sourcecode of the timesync application:

http://www.megaupload.com/?d=YIEMNV9W

I have being having a play with the 1307rtc and alarm code and it works great apart from one thing.

When i have used other 1307 codes the rtc keeps the time when the power is off ( i have a sparkfun rtc with battery ) with the new code it resets the time and i cant find a way to set the rtc time so when i disconect the power the rtc stores the time.

Any ideas around this because apart from that the codes great and a lot less fuss thatn other codes.

Thanks Adam

..with the new code it resets the time and i cant find a way to set the rtc time so when i disconect the power the rtc stores the time.

Adam, can you clarify the problem you are having.

Is it that you can't set the time on the rtc (using the TimeRTCSet.pde sketch in the download)?

Or that once the time is set it does not display correctly when you disconnect and reconnect power with the RTC board connected to the Arduino board? If the latter, check that the battery in the RTC board is ok.

Looks like a dodgy rtc module.

I have a spare and it works fine, im sure i will be back with some more questions later.

Thanks Adam

Hi Guys ,
I am trying to complete my logger project where my Arduino runs on batteries in low power (<1uA) and wakes up every specified time , reads the temperature off a thermal resistor , logs the data in an external SPI SD Flash along with date and time and goes back to sleep .
The problem is that the init of the SD starts logging from the beginning of the file and doesn't append an the sleep libraries don't seems to work so well with it .
Does anyone know of any similar project that was done along this area .
I couldn't find anything in the playground yet it seems very likely other people have done similar projects . ::slight_smile:

moriszen, as I posted in an earlier reply to a question on your project, I would like to keep this thread focused on issues relating to the Time library.

You are more likely to attract relavant replies if you start a new thread with a title relevant to your project.

Sorry (again)

Hi All,

I am trying to use the Time Library on an RFID door project. It's running on an Arduino MEGA. I have a GPS hooked up to it, but when I tried to run it using the GPS code it completely locked up and would not allow any input. Instead, I am manually getting the date and time using gps.crack_datetime() and inputting it into setTime(), then using adjustTime(-18000) for the eastern time zone. It will only run the GPS dump if it has been around an hour or more since the last time. At first turn on, it gets the correct time and displays it on the LCD, and updates the LCD every minute perfectly. But after the door is opened, it waits in an endless loop for the the door to close before re-locking. The time is then way off. The code for the loop is posted below.

Thanks for your help,
Eddie Schnell

if(digitalRead(intopen) == LOW) return;                              // manual lock
  while(digitalRead(trigger) == HIGH) {
    delay(5);                                                          // take a breath
    if(digitalRead(intopen) == LOW) return;                            // manual lock
    Serial.println("Close the Door");                                  // debug
  }
  Serial.println("First Test Door Closed");                            // debug
  delay(50);
  if(digitalRead(intopen) == LOW) return;                              // manual
  delay(50);
  if(digitalRead(intopen) == LOW) return;                              // manual
  delay(50);
  if(digitalRead(intopen) == LOW) return;                              // manual
  if(digitalRead(trigger) == HIGH) {
    Serial.println("Failed Second Test");                              // debug
    while(digitalRead(trigger) == HIGH) {
      delay(5);                                                        // take a breath
      if(digitalRead(intopen) == LOW) return;                          // manual
      Serial.println("Close the Door Again");                          // debug
    }
  }

Lets see if we can find out why you had problems running the example GPS code, perhaps that may be related to the problem you are having in your current sketch.

Was the example code that locked up modified, and if so, can you post the code you ran.

OK, I went back to the original GPS code and put it into my code. It does not lock up everything, but it's stuck in 1970. It does seem to be counting in the loops though.

The code is too long to post, it is viewable at www.schnellnetworks.com/code.html

Thanks,
Eddie