A library called Time that provides timekeeping functionality for Arduino has been added to the playground.

This library is derived from the playground DateTime code but has a different API that is intended to be more flexible and easier to use.

This is the first full release of the Library. The API and examples have changed slightly from prototype code posted at the end of December and anyone using the prototype code is encouraged to download the playground version.

Such as elapsedDays, this might be a function name in a sketch that wats to use you Time library, but it's functionality might differ from your macro (so a userdefined function is necessary).

On a more pickyer (is that even a word?) note, I'd also like your tmElements_t to be renamed to a more Arduinoesque TimeElements and that all of its member fields start lowercase.This could sure be of use for the users of your library.

Prefixing the macros does reduce the likelihood of name collision but it makes them less Arduino like.

I could change them to inline functions so the compiler will warn if the user provides a function with a similar name. Lets see if there other opinions on how best to address this.

The name tmElements_t was chosen because this structure was really intended for programmers writing time provider code rather than use in a sketch (I wanted to keep the tm prefix to remind programmers that its derived from the C tm structure). But I can certainly change the name if it looks like TimeElements could be useful in a sketch.

AlphaBeta

Prefixing the macros does reduce the likelihood of name collision but it makes them less Arduino like.

I could change them to inline functions so the compiler will warn if the user provides a function with a similar name. Lets see if there other opinions on how best to address this.

I did not think that the macros might be useful for the library user, then I think your inline function suggestion is the way to go

Quote

The name tmElements_t was chosen because this structure was really intended for programmers writing time provider code rather than use in a sketch (I wanted to keep the tm prefix to remind programmers that its derived from the C tm structure). But I can certainly change the name if it looks like TimeElements could be useful in a sketch.

Well, all ideas I can think of (beyond the helloworldlike clock use-case) would've used such a TimeElements structure.

Maybe a timelapse photo that follows a predetermined 'most traffic of the day' time. Then a day of week, and a time of day datarepresentation would be useful. Your tmElements_t would be a perfect storage container.

Or a simple alarm/eventgenerator with alarms/events triggering each year, each month, each day of week, each hour etc etc..

I can think of many more use-cases, but now. Enough from me, I'll let someone else speak their mind

moriszen

Hi Guys ,I just got second place in the Arduino contents on instructables - yet I am such a noob (you could all win easy) .In any case I just did two small projects and want to make a general purpose logger . It will need to run on a bat so it will need to be low power (my second challenge) yet I want it to log time correctly .I DL the library and got it running but cant get it to sync with my pc (I user the serial port version to sync) .Do I need to compile some C file and run it so it takes the time from the PC and sends it to Arduino .I sent it "T111111111" and it did get something what is the acts format ? T [day][month][year]etc' ?Thanks guys - I hope to contribute too soon (when I get good enough).

The example sketch expects the time in raw format - it's the number of seconds since Jan 1 1970. This format may seem odd but it is very widely used in computer software (its sometimes called Unix time). There are many web sites that will generate the a value you can use to set the time, for example: http://www.epochconverter.com/

If you past the value into the Serial monitor preceeded by the letter T you will set Arduino time to this value.

For example, pasting the following will set the clock to the time a wrote this reply. T1262972083

There is also a Processing application in the download that you can run on your computer that will read your computers time and send this to the Arduino example sketch

moriszen

Thanks for the reply.I couldn't use the example you added (can't compile in VB.net or C#).I wrote a simple program in Vb.Net that does it and also tracks the time drift and enables manual sync .I will try to post it here .. not sure how to ...Moris

too bad I cant add an image or the exe for the program so others can use it ...

when I press "add image icon" I only get /img ... I guess I am to dumb to use it ...

Here is the source for the VB.Net for it

Add two buttons and two listboxes and this code and you should get what you need:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Show all available COM ports. For Each sp As String In My.Computer.Ports.SerialPortNames ListBox2.Items.Add(sp) Next End Sub

This forum only allows links to images and code, you need to upload the item in the link to some other public web site. If you do that I will put a link to your VB app in the playground.

A suggestion for your VB app, if you read a character at time from the serial port you can check for the character 7 which is what Arduino sends when it wants the time. This will set the time without you having to press a button if you send the Time string whenever you received the character 7

Also, you can strip off the Carriage Return / Line Feed at the end of the clock display so you don't get that funny character at the end of the line in the list box.

Your earlier post inspired be to create a new example sketch that allows setting of explicit times from the serial port.

The time can also be set as follows: S[hh:mm:ss dd mm yy]

Values must be given in order starting from hhFor example: S[14] sets the hour to 2pm, S[14:10] sets 2:10 pm S[14:10:00 09 01 10] sets the time to 14:10:00 9th Jan 2010

Values must be two digits with preceeding 0 if necessary (eg 05 to set the value 5) Year must be two digits, 2010 is entered as 10

Opening and closing square brackest are required, colon and spaces are optional.

/* * NewTimeSerial.pde * example code illustrating Time library date strings * * Time can be set using an 11 character message consisiting of the letter 'T' * followed by the ten digit number of seconds since Jan 1 1970 (Unix time) * * The time can also be set as follows: * S[hh:mm:ss dd mm yy] * Values must be given in order starting from hh * S[14] sets the hour to 2pm, S[14:10] sets 2:10 pm * values must be two digits with preceeding 0 if necessary (eg 05 to set the value 5) * year must be two digits, 2010 is entered as 10 * opening and closing square brackest are required, colon and spaces are optional * * */

#include <Time.h> #include <ctype.h>

#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits#define TIME_HEADER 'T' // Header tag for serial time sync message#define TIME_SET_TAG 'S' // Indicates start of time set string#define TIME_SET_StrLen 15 // the maximum length of a time set string [hhmmssddmmyyyy]#define TIME_REQUEST 7 // ASCII bell character requests a time sync message

moriszen

mem - Thanks for the reply and new time set function.Is there a common external site you guys use here to link to ?I am thinking of building some king of general purpose logger which I want to run on batteries (1 li-ion bat) but I am afraid if I reduce the clock speed I will loose the functionality of the RTC .AN example would be loging my body temperature along the day and having the Atmega wake up every min or so and sample the temperature place in flash with current time and go back to sleep . Other examples would be to wake up on external events (open door etc'). B.T.W this is a link to the project I posted on INSTRUCTABLES http://www.instructables.com/id/Arduino-True-Battery-Capacity-Tester-Li-IonNiMH/