Go Down

Topic: Arduino Clock: Setting Time (Read 10774 times) previous topic - next topic

bugzy4real

Is it possible to set the arduino time clock? If yes, how can you allow the user to enter the time so it can be set? Pls help!!!

mem

#1
Apr 06, 2009, 08:41 pm Last Edit: Apr 06, 2009, 08:49 pm by mem Reason: 1
There is a library here that provides time functions on Arduino: http://www.arduino.cc/playground/Code/DateTime
Also included is a Processing sketch to set the time from a PC or Mac.

What is it you want to do?

bugzy4real

#2
Apr 06, 2009, 08:50 pm Last Edit: Apr 06, 2009, 08:51 pm by bugzy4real Reason: 1
I wanna design a GUI that allows the user to set a time when an LED should light up without changing the actual time (think of it as an alarm clock). For example, say at 4:00 pm. How would you do that?

mem

#3
Apr 06, 2009, 09:10 pm Last Edit: Apr 06, 2009, 09:12 pm by mem Reason: 1
You need to say more about what you would like to do.

What kind of gui would you like to have?

Would you like the gui on a display device connected to Arduino or running on application running on a computer connected to the serial port?  (or whichever is easer to impliment?)

bugzy4real

I'd like to use processing to develop the GUI. The GUI should take input maybe as  a text field that allows the user to enter time in integer form and that input should be used to determine when the LED should light up

darudude

Is you arduino going to always be connected to the computer? Or are you just using the computer to program the Arduino, and then unplugging the Arduino and leaving it running as a stand alone, through a wallwart or battery?

If you are going to leave it connected to the computer, this is fairly easy. Your computer can do the counting and when the alarm is hit it can send a message over serial to the arduino, the arduino can then parse this message and set the LED accordingly.

If you are going to be unpluggin the arduino it gets a little complicated. I would use an external timing IC and battery back it up. I would use one that has some sort of memory like the DS1307

mem

Quote
If you are going to be unpluggin the arduino it gets a little complicated.
not if the Arduino is battery operated or remains powered when disconnected from the seial port.

Quote
I'd like to use processing to develop the GUI. The GUI should take input maybe as  a text field that allows the user to enter time in integer form and that input should be used to determine when the LED should light up


There is a processing application supplied with the download that sets the clock. You can add functionality to that Processing sketch to get an alarm time.


The DateTime library has a function to return the number of seconds that have elapsed since that start of the day. So to light an led at 8:30 in the morning for one hour you would do something like this:

Code: [Select]
time_t  alarmOnTime =  (8 * SECS_PER_HOUR) + (30 * SECS_PER_MIN);
time_t  alarmOffTime =  alarmOnTime  + (60 * SECS_PER_MIN);
time_t nextAlarm;


nextAlarm =  previousMidnight(DateTime.now())+ alarmOnTime;

if( DateTime.now() >= nextAlarm  && DateTime.now()  < nextAlarm + alarmOffTime )
   digitalWrite(ledPin), HIGH);
else
  digitalWrite(ledPin), LOW);

bugzy4real

#7
Apr 07, 2009, 08:37 pm Last Edit: Apr 07, 2009, 09:01 pm by bugzy4real Reason: 1
mem: Thanks a lot! your code worked to perfection!
darudude: thanks for your suggestion too!

But guys, how can i create a text box or anything at all to allow the user input the time the LED should light up

AlphaBeta

Buy a LCD, or a led display.

You could write a program that runs on your computer, querying the user, and sending the data over serial.

Interfacing With Software

mem

#9
Apr 07, 2009, 09:09 pm Last Edit: Apr 07, 2009, 09:12 pm by mem Reason: 1
Quote
But guys, how can i create a text box or anything at all to allow the user input the time the LED should light up


can you clarify your question? are you asking how to add it to the setArduinoClock Processing sketch? can you say more about your level of programming skill?

bugzy4real

#10
Apr 09, 2009, 12:36 am Last Edit: Apr 09, 2009, 12:37 am by bugzy4real Reason: 1
All i'm saying is i wanna create a GUI or something interactive where the user can actually enter the time he wants the LED to light up. So that, the user would be able to determine the values (8,30) in the example you gave me below:

time_t  alarmOnTime =  (8 * SECS_PER_HOUR) + (30 * SECS_PER_MIN);
time_t  alarmOffTime =  alarmOnTime  + (60 * SECS_PER_MIN);

P.S: I'm new to Arduino. i could have done this GUI easily in C#

FusiveResonance

Quote
P.S: I'm new to Arduino. i could have done this GUI easily in C#


Look here for interfacing with c#
http://www.arduino.cc/playground/Main/InterfacingWithSoftware

bugzy4real

Interfacing with C# is good but i'd rather not mix C# with arduino+processing except i have no other choice

mem

If you are more comfortable with C# than Processing, there is no reason not to use it.

It should be quite easy to replace the Processing code to set the time with a C# app. it just gets the current time, converts that into the number if seconds since jan 1 1970, and sends that as as string of digits preceeded by some unique header (255 in the published version).

Write whatever gui you want in whatever language your prefer. you just need to send your alarm time as a string with some identifying header byte followed by a string of digits indicating the time_t for the alarm you want. Have a look at the Arduino example source to see how it handles this string and add you code that identifies and uses the alarm on and off times.

I hope that helps

FusiveResonance

Quote
Interfacing with C# is good but i'd rather not mix C# with arduino+processing except i have no other choice


Why not? Let the micro controller do what it does best, and let it interface with your pc for everything else. This usually results in an efficient implementation.

Go Up