When I try to compile the code for the whole system I get this error:
Arduino: 1.5.4 (Mac OS X), Board: "Arduino Uno"
sketch_aug26b.ino: In function 'void setup()':
sketch_aug26b:45: error: 'DateTime' was not declared in this scope
sketch_aug26b.ino: In function 'void loop()':
sketch_aug26b:94: error: 'DateTime' was not declared in this scope
After doing a little research I thought maybe the problem had to do with the installation of the datetime library.
I checked that it was definitely installed, and it was present (on my mac) under sketch>import library, all the way at the bottom of the list
I then tried running the example code that came with the library and got this error:
Arduino: 1.5.4 (Mac OS X), Board: "Arduino Uno"
DateTime.pde: In function 'void loop()':
DateTime:19: error: 'DateTime' was not declared in this scope
DateTime:21: error: 'DateTime' was not declared in this scope
DateTime:30: error: 'BYTE' was not declared in this scope
As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.
DateTime.pde: In function 'boolean getPCtime()':
DateTime:41: error: 'time_t' was not declared in this scope
DateTime:41: error: expected `;' before 'pctime'
DateTime:45: error: 'pctime' was not declared in this scope
DateTime:48: error: 'DateTime' was not declared in this scope
DateTime:48: error: 'pctime' was not declared in this scope
DateTime.pde: In function 'void digitalClockDisplay()':
DateTime:57: error: 'DateTime' was not declared in this scope
DateTime:61: error: 'DateTimeStrings' was not declared in this scope
I've tried searching for a solution on my own but I'm at a total loss. Any help would be appreciated
Please do us and yourself a favour by posting the program copied from your IDE. When doing so please note the advice in the stickies at the top of this forum, particularly the advice to use code tags.
Well the compiler isn't finding the library by the look of it. You
haven't said which DateTime library nor posted your code though, so its guesswork
for now.
I'm a novice right now and didn't know that there was more than one DateTime library, the one I downloaded I found here:Arduino Playground - HomePage
As for the code, the example sketch code is:
// DateTime.pde
// example sketch for the DateTime library
#include <DateTime.h>
#include <DateTimeStrings.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message
void setup(){
Serial.begin(19200);
pinMode(13,OUTPUT); // we flash the LED each second
}
void loop(){
unsigned long prevtime;
if( getPCtime()) { // try to get time sync from pc
Serial.print("Clock synced at: ");
Serial.println(DateTime.now(),DEC);
}
if(DateTime.available()) { // update clocks if time has been synced
digitalWrite(13,LOW); // first flash the LED
prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock
// send our time to any app at the other end of the serial port
Serial.print( TIME_HEADER,BYTE); // this is the header for the current time
Serial.println(DateTime.now());
digitalWrite(13,HIGH);
}
delay(100);
}
boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c= Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port
return true; // return true if time message received on the serial port
}
}
return false; //if no message return false
}
void digitalClockDisplay(){
// digital clock display of current date and time
Serial.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
Serial.print(" ");
Serial.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
Serial.print(" ");
Serial.print(DateTimeStrings.monthStr(DateTime.Month));
Serial.print(" ");
Serial.println(DateTime.Day,DEC);
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits,DEC);
}
I hope this sheds a little more light on the problem for those more knowledgable than me. Also, I hope I posted more correctly this time. Again, any help is appreciated
I have a mac and the sketchbook folder doesnt show up in my finder. I tried manually placing the .zip file in the library folder and still got the same error. Does anybody know where I could place the file on my mac to help the compiler find the library?
I apologize for how new I am at this, this is one of my first projects. When I stick that at the beginning of the code, it still won't compile. Could you explain to me exactly where I should put it?
when you have DateTime.h installed in the correct library location what is the date of the .h & .cpp files? mine are 18/09/2008 so I'm thinking we may be using old libraries.
When you try to compile do you get as error as follows:
The 'BYTE' keyword is no longer supported
which relates to the line of code as follows:
Serial.print( TIME_HEADER,BYTE); // this is the header for the current time