Pages: [1] 2 3   Go Down
Author Topic: Arduino Clock: Setting Time  (Read 8779 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!!
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: April 06, 2009, 01:49:59 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: April 06, 2009, 01:51:52 pm by bugzy4real » Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?)
« Last Edit: April 06, 2009, 02:12:28 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 07, 2009, 02:01:29 pm by bugzy4real » Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: April 07, 2009, 02:12:41 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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#
« Last Edit: April 08, 2009, 05:37:15 pm by bugzy4real » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 175
---
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 175
---
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2 3   Go Up
Jump to: