Time Library added to Playground

That indeed solves the problem.

Ok, the bug in the setTime function is that it doesn't reset prevMillis to the value of millis(). So the next time you call now(), the difference between the last call to now() and the current value of millis() will be added to the time you just adjusted with setTime(). If now is called often enough, that isn't a visible problem. However if you call now() only every 5 seconds and use setTime() directly, you get that weird offset you saw.

Next step: Finding out who maintains the Time library and where to post a patch...

Korman

Thanks Korman.

I have added the fix and uploaded it to the Playground.
Give it a go and let me know how you get on.

Wow, that is a quick bugfix! :slight_smile:

It's working just fine now.

Mem,

it looks good now. Thank you for the quick response. For completeness here's my test program which fails with the old library and works with the new one:

#include <Time.h>
void setup () {
      Serial.begin (9600);
      delay (10000);
      Serial.println (now());
      delay (10000);
      setTime (123456789);
      Serial.println (now());
}
void loop(){
}

Results with old Time library - highlight is wrong:

10
123456799

Results with new Time library - highlight is ok now:

10
123456789

Korman

loomi, sorry I missed your post about parsing dates. Date strings are supported in the current library so your sketch could use something like this:

// function to return the numeric month from a given 3 character month string
// Jan is returned as 1, December as 12
int getMonth(char *mnthStr)
{
   for( int mo = 1; mo <=12; mo++)
   {    
      if(strcmp( mnthStr, monthShortStr(mo)) == 0)
         return mo;        
   }     
   return 0; 
}

Have a look at Datestrings.cpp in the Time library directory if you want to look at the monthShortStr function

Is there any particular interest in having the DS3231 specific features (such as forcing a temperature conversion, reading the temperature value, toggling the 32KHz pin, etc) added? I've already got the first two there finished, although I can't actually test them.

Hi ccfreak2k, I would be interested to hear the responses to your question. Why not start a new thread for discussion of your library when you have had a chance to get it tested and place a link here so people can find it..

I would be happy to include a DS3231 library with the Time library distribution if this is something people want.

I am trying to use this library, and can't see to get past what appears to be a simple error, using Ard0021 on OS X.

I have unpacked the zip, and so now have

Sketches

  • Libraries
  • Time (dl from playground)
  • TinyGPS (was there already)
  • NewSoftSerial (was there already)

Sketches in the Sketches folder seem to have no problem using header files from the TinyGPS or NewSoftSerial folders, but whenever I try to include Time.h, I get this:

TimeGPS.cpp:7:18: error: Time.h: No such file or directory

The include line looks like this:

#include <Time.h>

I've reviewed the Arduino instructions several times, and can't see what I'm doing wrong. Time.H is shown in the list of available libraries when I select Sketch - Import Library (along with NewSoftSerial and TinyGPS).

I copied the TimeGPS example to the Sketches folder, and it can find the TinyGPS and NewSoftSerial.h no problem (they turn orange in the editor), but can't find the Time.h, even though it's in the same place. Time.h doesn't turn black.

I must be doing something wrong - can anyone point me in the right direction, please?

SeanC, did you try to open the TimeGPS example sketch by navigating: File->Examples->Time->Examples->TimeGps

If you can open and correctly compile that sketch, click File->Save As to your sketchbook directory and after the IDE copies the sketch, see it that also compiles okay.

Thanks for your reply! I unpacked the archive again, opened the

TimeGPS example sketch with : File->Examples->Time->Examples->TimeGps

and it still fails the same way. Interestingly, I can see it's going to fail, because the Time.h in the sample code is all black in the editor, whereas the two found libraries, TinyGPS and NewSoftSerial are orange.

#include <Time.h>
#include <TinyGPS.h>
#include <NewSoftSerial.h>

I closed and re-opened the arduino ide, and still can see Time in the Sketch-Import Libraries menu.

Any help would be appreciated!

I think the coloring is a red herring. Arduino libraries use a syntax coloring file to enble the IDE to highlight keywords. Tinygps and NewSoftSerial are Class names that are used within the sketch so they are in the Syntax coloring file. The Time class name is not explicitly used in a sketch so its in the syntax coloring file and is not highlighted.

Something else is causing your problem. Are you quite sure that the Time library folder location is correct and that all the files are there?

I don't use OS X, perhap someone that does can check if they have any problems compiling the Time library example sketches.

Something else is causing your problem. Are you quite sure that the Time library folder location is correct and that all the files are there?

I don't use OS X, perhap someone that does can check if they have any problems compiling the Time library example sketches.

I also have the same problem as SeanC.
I'm running Mac OS X 10.6.5 and Arduino 0021 on my machine.

I downloaded Time library and unzipped it under my Arduino/libraries directory.

Time library becomes available as example and also importing but I cannot compile the examples.

I get the following errors from TimeSerial example.

TimeSerial.cpp:12:20: error: Time.h: No such file or directory
TimeSerial:16: error: 'time_t' does not name a type
TimeSerial.cpp: In function 'void setup()':
TimeSerial:19: error: 'requestSync' was not declared in this scope
TimeSerial:19: error: 'setSyncProvider' was not declared in this scope
TimeSerial.cpp: In function 'void loop()':
TimeSerial:28: error: 'timeStatus' was not declared in this scope
TimeSerial:28: error: 'timeNotSet' was not declared in this scope
TimeSerial:30: error: 'timeSet' was not declared in this scope
TimeSerial.cpp: In function 'void digitalClockDisplay()':
TimeSerial:38: error: 'hour' was not declared in this scope
TimeSerial:39: error: 'minute' was not declared in this scope
TimeSerial:40: error: 'second' was not declared in this scope
TimeSerial:42: error: 'day' was not declared in this scope
TimeSerial:44: error: 'month' was not declared in this scope
TimeSerial:46: error: 'year' was not declared in this scope
TimeSerial.cpp: In function 'void processSyncMessage()':
TimeSerial:64: error: 'time_t' was not declared in this scope
TimeSerial:64: error: expected `;' before 'pctime'
TimeSerial:68: error: 'pctime' was not declared in this scope
TimeSerial:71: error: 'pctime' was not declared in this scope
TimeSerial:71: error: 'setTime' was not declared in this scope
TimeSerial.cpp: At global scope:
TimeSerial:76: error: 'time_t' does not name a type

Any suggestions on how to get Time library to work?

Actually, I just figured out what I was doing wrong.

When I installed Time library at my libraries directory, I did it like this:

I unzipped Time.zip file at my libraries directory, so it created a new directory, 'Time'.

So the result was like this:

~/Documents/Arduino/libraries/Time/DS1307RTC
~/Documents/Arduino/libraries/Time/Time
~/Documents/Arduino/libraries/Time/TimeAlarms

Instead, what I should have done was to move the contents of top-level 'Time' directory to my libraries directory, like this:

~/Documents/Arduino/libraries//DS1307RTC
~/Documents/Arduino/libraries/Time/
~/Documents/Arduino/libraries/TimeAlarms

After making this adjustment, I am able to compile the examples that came with Time library. Hope other people may find it useful (or has everyone already figured this out?).

Good to hear you have it working.

I hope that information helps others with a similar problem

I am trying to use the Ethernet shield, and NTP but I'm having problems with the examples out of the box, with the following errors:

heating01.cpp.o: In function write_n(int, int)': C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:133: undefined reference to UdpBytewise'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:133: undefined reference to UdpBytewise' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:133: undefined reference to UdpBytewiseClass::write(unsigned char)'
heating01.cpp.o: In function getUlong()': C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:123: undefined reference to UdpBytewise'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:123: undefined reference to UdpBytewise' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:123: undefined reference to UdpBytewiseClass::read()'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:124: undefined reference to UdpBytewiseClass::read()' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:125: undefined reference to UdpBytewiseClass::read()'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:126: undefined reference to UdpBytewiseClass::read()' heating01.cpp.o: In function sendNTPpacket(unsigned char*)':
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:106: undefined reference to UdpBytewise' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:106: undefined reference to UdpBytewise'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:106: undefined reference to UdpBytewiseClass::begin(unsigned int)' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:107: undefined reference to UdpBytewiseClass::beginPacket(unsigned char*, unsigned int)'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:108: undefined reference to UdpBytewiseClass::write(unsigned char)' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:109: undefined reference to UdpBytewiseClass::write(unsigned char)'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:110: undefined reference to UdpBytewiseClass::write(unsigned char)' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:111: undefined reference to UdpBytewiseClass::write(unsigned char)'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:113: undefined reference to UdpBytewiseClass::write(unsigned char)' heating01.cpp.o:C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:114: more undefined references to UdpBytewiseClass::write(unsigned char)' follow
heating01.cpp.o: In function sendNTPpacket(unsigned char*)': C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:118: undefined reference to UdpBytewiseClass::endPacket()'
heating01.cpp.o: In function getNtpTime()': C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:95: undefined reference to UdpBytewise'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:95: undefined reference to UdpBytewise' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:95: undefined reference to UdpBytewiseClass::available()'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:97: undefined reference to UdpBytewise' C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:97: undefined reference to UdpBytewise'
C:\Users\Stuart\AppData\Local\Temp\build8924192961418854666.tmp/heating01.cpp:97: undefined reference to `UdpBytewiseClass::read()'

Having spent most of the day searching I've turned up nout.. Any help appreciated!

Stuart, newbie..

you didn't say if if you installed the UdpBytewise library, you can find a link and some updates in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284070155

Thanks for your reply,
I've re-downloaded all the files shown on http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/

Errors now look like this:
C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp:30:19: error: types.h: No such file or directory
In file included from C:\Users\Stuart\Downloads\arduino-0021\libraries\SPI/SPI.h:15,
from C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\utility/w5100.h:14,
from C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp:31:
C:\Users\Stuart\Downloads\arduino-0021\hardware\arduino\cores\arduino/WProgram.h:17: error: declaration of C function 'uint16_t makeWord(byte, byte)' conflicts with
C:\Users\Stuart\Downloads\arduino-0021\hardware\arduino\cores\arduino/WProgram.h:16: error: previous declaration 'uint16_t makeWord(uint16_t)' here
C:\Users\Stuart\Downloads\arduino-0021\hardware\arduino\cores\arduino/WProgram.h:27: error: declaration of C function 'long int random(long int)' conflicts with
c:/users/stuart/downloads/arduino-0021/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:504: error: previous declaration 'long int random()' here
C:\Users\Stuart\Downloads\arduino-0021\hardware\arduino\cores\arduino/WProgram.h:28: error: declaration of C function 'long int random(long int, long int)' conflicts with
C:\Users\Stuart\Downloads\arduino-0021\hardware\arduino\cores\arduino/WProgram.h:27: error: previous declaration 'long int random(long int)' here
C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp: In member function 'void UdpBytewiseClass::begin(uint16_t)':
C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp:46: error: 'Sn_MR_UDP' was not declared in this scope
C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp: In member function 'int UdpBytewiseClass::available()':
C:\Users\Stuart\Downloads\arduino-0021\libraries\Ethernet\UdpBytewise.cpp:55: error: 'getSn_RX_RSR' was not declared in this scope

So still a little stumped, but learning fast..

Stuart, those messages look similar to the ones in the thread linked in my previous post. Did you try the change suggested in that thread?

As this looks like an issue with the ethernet code and not the time library lets continue the discussion to that thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284070155

This has probably already been mentioned, but after wasting a couple hours i feel its worth saying.

The DS1307 RTC wont work off the usb power (going though arduino's 5v reg which would result in a drop).

I prolly should have realised it was power sooner, but oh well.

@GhostGum, perhaps it was a problem with your wiring, a DS1307 will run fine off 5 volts from USB.