Pages: 1 2 3 [4] 5 6 7   Go Down
Author Topic: Who needs a Software Real Time Clock?  (Read 11023 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mem:
After an absence I got back to this project and this time was able to get it working on a different mac with no problem on arduino 11. It runs for days with no problems. Now I cannot get it to compile on arduino 12 as it consistently is giving stdlib.h errors. I have tried the newest playground files. Anything you could point me to would be appreciated.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi hotcarrier, the code in the playground compiles without problem under 0012 on my machine. Have you tried to compile the playground example sketch? If that compiles ok then perhaps post your sketch, it maybe something there causing the problem.

Good Luck!
Logged

Denver, CO - USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
! <3 Atmega328
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sure that I am doing something dumb here... but I am running into a mental block or some such craziness trying to get the hour component to show up in 12hr increments rather than the 24hr setup.
The Date Time code is working quite well - so I know it is something I am not doing right - I have tried to assign the DateTime.hour like so:

  hours = (DateTime.Hour);
  if (hours > 12) {hours = hours - 12;}

So... I am pretty sure it is something dumb I am doing, but at this point I cant figure it out.

I have the minutes and seconds working well - I am breaking out the tens and ones of each one, and displaying on a 7 segment LED setup.  

Help is greatly appreciated!  smiley-grin
Thanks
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

to convert to 12 hour format you do the following:
between 0000 and 0059, add 12 hours
between 0100 and 1159, straight conversion to AM
between 1200 and 1259, straight conversion to PM
between 1300 and 2359, subtract 12 hours

Here is a function you can put in your sketch that will convert the 24 hour format from the library to 12 hour format

Code:
byte hours24To12(byte hours){
  if( hours == 0 )
    return 12; // 12 midnight
  else if( hours  > 12)
    return hours - 12 ;
  else
    return hours ;
}
Determining AM/PM is easier, if the 24 hour value is < 12 its AM , otherwise its PM

I will add these functions to the next release of the library, let me know how you get on.
« Last Edit: December 22, 2008, 09:34:04 am by mem » Logged

Denver, CO - USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
! &lt;3 Atmega328
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the code  smiley

edit - fixed my code, and it works great now!  smiley-grin
« Last Edit: December 22, 2008, 02:19:49 pm by b94cast » Logged

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

Greetings! I'm just starting to mess around with the Arduino and I ran into a problem with the SetArduinoClock example from the DateTime library. Specifically, the Processing part of the example that reads a time code back from the Arduino to display a small analog clock on screen seems to be mangling the timecode header byte. The byte is sent from the board as 255 but ends up getting mangled by the call to myPort.readStringUntil(LF);

I came up with some alternate code that works and I wanted to share it.

void serialEvent(Serial p) {
  byte[] inBuffer = myPort.readBytesUntil(LF);
  if(inBuffer == null || inBuffer.length == 0) {
   return;
  }
  if(inBuffer[0] == byte(TIME_HEADER)) {
    int val = 0;
    long time = 0;
    for(int i = 1; i <= 10; i++)        
      time = time * 10 + (inBuffer - '0');
    UpdateClock(time);
  } else {
    print(new String(inBuffer));
  }        
}


I'm running Processing V. 1.03 on a Mac. I'm posing this here as the DateTime wiki page linked to this forum. I also couldn't send a direct message to the PM contact as I have a posting count of 0...until I click Post in 3, 2 , 1.... smiley
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Dave, what symptoms are you seeing? I am running processing 1.01 (on windows) and the playground code works fine for me.  But I am happy to make the change from strings to a char array if it fixes the problem for you. I am curious however to know what exactly is the problem.
Logged

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

i'm working on arduino severino
it have serial input, so i changed baud rate to 9600
i'm able to upload successfully, but no output from serial port is coming
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't say if you get output with other sketches.

Try adding a print statement in setup to see if you can get that output
  Serial.println("Setup Complete");

If you see that but nothing else then your Arduino is detecting the message to set the time. Make sure both sides are using 9600 baud and that you have selected the correct com port in Processing
Logged

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

I'm still waiting for my first Arduino in the post, so excuse my ignorance...

I'm looking to use the software real time clock in my first project as I need to trigger a function twice a day at certain times. I'm also looking at using the watchdog timer and sleep functions to save energy (http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/).

Are the two compatible, or is there some way to make them compatible? I realise that I might need to use a different sleep mode than that used in the example linked to above (maybe "power save" mode instead of "power down" mode).

Any help would be appreciated!
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had some free time today so I finally got around to allowing my Arduino to sync the DateTime over the internet using the wiznet module.  It grabs the time from the NIST server which gives a response like this:

Code:
54964 09-05-13 21:01:33 50 0 0  14.3 UTC(NIST) *

From that it was a little bit of work figuring how to convert to unix time, but I got it sorted.  The nice thing about using NIST is that it also indicates if it is daylight savings or standard time so the time will always be correct.  No adjustment needed or watching for specific dates.  I currently update the time every twelve hours.  With the price of the wiznet module around $16 I think this trumps having a RTC because of the other things you can do with ethernet.

Currently, this is in a pretty large program on my Sanguino.  If there's interest I could put together an example sketch that simply updates the time from NIST.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12773
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Are the two compatible, or is there some way to make them compatible?

The majority of the sleep modes on the AT90USB162 processor seem to shut off all the timers (except the watchdog timer).  This means millis stops running.

Hopefully this will help...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240918097

Good luck,
Brian
Logged

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

Thanks Brian,
I've worked out a new control algorithm that doesn't require date/time, so now I just need to put the arduino to sleep and wake it every few minutes to conserve energy. Looks like the thread you've linked to will do the trick.

Cheers,
Todd
Logged

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

I've been looking at this code and there are two general questions I have about it, one technical and one non-technical.

The technical issue is that unless I'm missing something there doesn't seem to be any support for time zones, even implicitly.

The most simple solution to this would be to simply add an offset field in the structure which would be used when calculating the more calendar friendly time structure.

A more complete but complex solution would be to add a simplified time zone function per zone. This wouldn't have the historical time zone information (ie it wouldn't work for past times) but would be "good enough" and relatively small.

Thoughts on either?

The non-technical question is that the code itself has a copyright with all rights reserved, and then no subsequent license that I could find. Is that an oversight or by design?

Thanks
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi emacsen,

The lack of license statement is oversight. It is licensed under the GNU LGPL and I will add that into the source files when I upload the next version.

In my own code  I handle time zone offset when needed by adding the offset value to calls to DateTime.sync.  But usually I don't need it because the clock on the computer that sets the time is already compensated for the local time zone.

If you think it would be useful to have a timezone property that contained the offset in hours from UTC then I can easily add that.

If you are thinking about displaying multiple time zones, I wonder if it would help if I added something like the following  method:

boolean SetTimeZone(int offsetFromUTC)
// set the time zone offset to the given value
// if time has been synced, refresh time properties and return true
// else return false


This would result in calls to DateTime.hour, DateTime.Day etc reflecting the given time zone offset.
Logged

Pages: 1 2 3 [4] 5 6 7   Go Up
Jump to: