How to Set/Get time of day, Uno

This may be a silly question, but I'm planning a project that will involve firing an event once (or twice) each day.

Looking at a limited number of examples using the TimeAlarm library, ie: http://answers.oreilly.com/topic/2704-how-to-create-an-arduino-alarm-that-calls-a-function/

I can't see/understand how the time/date is set into the Uno. I understand it can't be reset once started and set, without loosing time. Examples seem to have a display, but no input buttons to set. If the Uno project is in a shack 20 miles from nowhere, and gets restarted, how can it know the time? From AT commands of a GSM shield or attached GSM phone?

Ashton: This may be a silly question, but I'm planning a project that will involve firing an event once (or twice) each day.

Looking at a limited number of examples using the TimeAlarm library, ie: http://answers.oreilly.com/topic/2704-how-to-create-an-arduino-alarm-that-calls-a-function/

I can't see/understand how the time/date is set into the Uno. I understand it can't be reset once started and set, without loosing time. Examples seem to have a display, but no input buttons to set. If the Uno project is in a shack 20 miles from nowhere, and gets restarted, how can it know the time? From AT commands of a GSM shield or attached GSM phone?

In that example sketch the time is set when you place the values into the early command shown below and upload the sketch.

setTime(8,29,40,1,1,10); // set time to 8:29:40am Jan 1 2010

So just edit that line to your time and date and upload the sketch to the board.

If you every power off the board then you will lose the present time and it will revert to the time and date of that command statement. So you will then have to edit the sketch and down load it once again with the current date and time.

An alternative is to buy a real time clock module that has a battery back up that once you set data/time it will hold it even if powered off.

http://www.adafruit.com/products/264

Lefty

If it's that critical, the best method is probably to use something like a Dallas 1307 real time clock chip. You supply a backup battery (coin cell) and a 32.768kHz crystal to keep accurate time. Otherwise, if you have a GPS source available, then that would be a good candidate.

Hey, that's a pretty slick clock module from adafruit. Only thing I don't like is the crystal case not grounded, but it is DIY after all so that can be fixed. That can help with accuracy in noisy environment. If the clock is gaining ten or twenty minutes/day then you can bet that noise pickup is likely the problem. I can't tell if they used a guard ring on the board either, but that's getting pretty picky. Still, it's a good deal and would work fine for most people. On the other hand allot of people are doing robotics and nothing makes a mess of a power supply rail like a brushed motor.

How reliable would it be to use (with a GSM modem/shield) in this project: AT+CCLK?

if it returns: +CCLK: "12/02/28,10:49:53+08" OK

I just need to learn how to parse/filter to get the time. I can add a delay or way to monitor when the network is connected.

I would assume that as long as it has access to the GSM cellular network that it would be an extremely reliable source.

afremont:
Hey, that’s a pretty slick clock module from adafruit. Only thing I don’t like is the crystal case not grounded, but it is DIY after all so that can be fixed. That can help with accuracy in noisy environment. If the clock is gaining ten or twenty minutes/day then you can bet that noise pickup is likely the problem. I can’t tell if they used a guard ring on the board either, but that’s getting pretty picky. Still, it’s a good deal and would work fine for most people. On the other hand allot of people are doing robotics and nothing makes a mess of a power supply rail like a brushed motor.

Well you buy to the application specification you require. They sell a more precise RTC for more dollars of course. :wink:

Lefty