Pages: 1 ... 5 6 [7] 8 9 ... 18   Go Down
Author Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions  (Read 70954 times)
0 Members and 1 Guest are viewing this topic.
jersey
Offline Offline
Newbie
*
Karma: 0
Posts: 46
hack freely my friends
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the exact code i am running is the processing sketch from the time library and my port index is 3 because the arduino is on port 3
but even if i made no modifications to this code it still gives me an error
is there a way to just tell it what port number and do away with the serial list because i know the port and this is unnecissary
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
my port index is 3 because the arduino is on port 3
The portIndex value and the COM port number bear no relationship to each other.

Add 3 statements to the Processing sketch, before the println(" Connecting to -> " + Serial.list()[portIndex]); statement:
Code:
println("Serial ports");
println("=================");
println(Serial.list());
println("=================");
The list of serial ports that Processing knows about will be between the two rows of equal signs. Show us the output.

Logged

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

Arduino 1 can not play TimeSerial.pde

I tested TimeSerial.pde after install Time llibrary in /home/carles/ARDUINO/arduino-1.0/libraries/Time but Arduino show me this error:

TimeSerial.cpp:12:20: error: Time.h: El fitxer o directori no existeix (File not found)
TimeSerial.cpp:24: erreur: ‘time_t’ does not name a type
TimeSerial.cpp: In function ‘void setup()’:
TimeSerial.cpp:27: erreur: ‘requestSync’ was not declared in this scope
TimeSerial.cpp:27: erreur: ‘setSyncProvider’ was not declared in this scope
TimeSerial.cpp: In function ‘void loop()’:
TimeSerial.cpp:36: erreur: ‘timeStatus’ was not declared in this scope
TimeSerial.cpp:36: erreur: ‘timeNotSet’ was not declared in this scope
TimeSerial.cpp:38: erreur: ‘timeSet’ was not declared in this scope
TimeSerial.cpp: In function ‘void digitalClockDisplay()’:
TimeSerial.cpp:46: erreur: ‘hour’ was not declared in this scope
TimeSerial.cpp:47: erreur: ‘minute’ was not declared in this scope
TimeSerial.cpp:48: erreur: ‘second’ was not declared in this scope
TimeSerial.cpp:50: erreur: ‘day’ was not declared in this scope
TimeSerial.cpp:52: erreur: ‘month’ was not declared in this scope
TimeSerial.cpp:54: erreur: ‘year’ was not declared in this scope
TimeSerial.cpp: In function ‘void processSyncMessage()’:
TimeSerial.cpp:72: erreur: ‘time_t’ was not declared in this scope
TimeSerial.cpp:72: erreur: expected `;' before ‘pctime’
TimeSerial.cpp:76: erreur: ‘pctime’ was not declared in this scope
TimeSerial.cpp:79: erreur: ‘pctime’ was not declared in this scope
TimeSerial.cpp:79: erreur: ‘setTime’ was not declared in this scope
TimeSerial.cpp: At global scope:
TimeSerial.cpp:84: erreur: ‘time_t’ does not name a type

Can somebody  help me ?
Thanks.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I tested TimeSerial.pde after install Time llibrary in /home/carles/ARDUINO/arduino-1.0/libraries/Time
That was the wrong place. The Time library is not a core library.

Did you restart the IDE afterwards?

Code:
TimeSerial.cpp:12:20: error: Time.h: El fitxer o directori no existeix (File not found)
This means that either you didn't restart the IDE or you didn't install the library correctly.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am running the example code from the Time library page here: http://www.arduino.cc/playground/Code/Time
I am sure that it is a stupid rookie mistake but I can't get it to work right. The code itself is this:
#include <Time.h> 

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix time_t as ten ASCII digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message

// T1262347200  //noon Jan 1 2010

void setup()  {
  Serial.begin(9600);
}

void loop(){   
  if(Serial.available() )
  {
    processSyncMessage();
  }
  if(timeStatus()!= timeNotSet)
    Serial.println("waiting for sync message");
  else     
      digitalClockDisplay(); 
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of header & 10 ASCII digits
    char c = Serial.read() ;
    Serial.print(c); 
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();         
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number   
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    } 
  }
}

And the serial monitor output is this:

0:00:00 0 0 1970
0:00:01 1 1 1970
0:00:02 1 1 1970
0:00:03 1 1 1970
0:00:04 1 1 1970
0:00:05 1 1 1970
0:00:06 1 1 1970
0:00:07 1 1 1970
0:00:08 1 1 1970
0:00:09 1 1 1970
0:00:10 1 1 1970
0:00:11 1 1 1970
So how do I get to the right time?

I have read through maybe 4 forums and didn't see the answer. Like I said, I am a rookie and I'm sure its a silly, stupid mistake but what do I do to get the right time? Please help.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output from the PC should look like "T1262347200". The numeric portion will change. The leading T will not.

The output that you show is the (incorrect) date and time, suggesting that there is no communication happening between the Arduino and the PC.

You did start the Processing application that runs on the PC, didn't you?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did not start any Processing application on the PC. I just downloaded both the libraries and the example code, uploaded the code to our Mega. Is that not right? I'm sorry for being so ignorant on this subject, I tried reading up, this library just isn't clicking with me. Sorry again and thanks for the help.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forget about any Processing application. In order to run it, you will have to download some 200-megabyte piece of software... just forget it. Instead, use my method:

1) Curse the author of the library.
2) Go to http://unixtime.info/ and look at the 10-digit number shown near the top right hand corner of the page.
3) Repeat step #1 as you adjust this number for your time zone. You will have to do some mental arithmetic.

US time zones:
Pacific Daylight Time: subtract 25200
Mountain Daylight Time: subtract 21600
Central Daylight Time: subtract 18000
Eastern Daylight Time: subtract 14400

European time zones:
Western European Summer Time: add 3600
Central European Summer Time: add 7200
Eastern European Summer Time: add 10800

4) Now, take that example code you got from the Time library page, and run it.
5) Now since the number on the unixtime.info page has changed, you will have to repeat step #3. Also repeat step #1.
6) Using the Serial Monitor feature of the Arduino software, type in something like "T1000000000". The T has to be capital, and in place of 1000000000, use the result of Step #5.
7) Send that command (the T with the 10-digit number) to the Arduino.

Note: When Daylight Saving Time / Summer Time ends, you will have to repeat the above, but with a different number to subtract / add for the time zone.

US time zones:
Pacific Standard Time: subtract 28800
Mountain Standard Time: subtract 25200
Central Standard Time: subtract 21600
Eastern Standard Time: subtract 18000

European time zones:
Western European (Standard) Time: don't add or subtract anything
Central European (Standard) Time: add 3600
Eastern European (Standard) Time: add 7200
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just downloaded both the libraries and the example code, uploaded the code to our Mega.
Some of the code was for the Arduino. Some was a Processing application. It is the Processing application that responds to the request for the time. If you are not running the application that is supposed to supply the time information, expecting a response is not a realistic expectation.

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49016
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1) Curse the author of the library.
How about we all curse you for choosing a different method of getting the time, that does not expand well to other data that the PC has that might be interesting to the Arduino?

Idiot.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1) Curse the author of the library.
How about we all curse you for choosing a different method of getting the time, that does not expand well to other data that the PC has that might be interesting to the Arduino?

Idiot.

If you just want to set the time, my method is perhaps the most straightforward for doing so.
Or now that you mention it, maybe not.

All right. Here's another method for computing the 10-digit number for setting the time:
This is all client-side, no internet access needed.
Open a spreadsheet program.
In cell A1 goes: =NOW()
In cell A2 goes: 1970-01-01 00:00
In cell A3 goes: =(A1-A2)*86400
Now, look at the number in A3. The part before the decimal point is the number you need.
To update the time, just recalculate the data.

As for "other data the PC has that might be interesting to the Arduino": in what form is this data stored? How you communicate this data to the Arduino, as well as how you have the Arduino handle the data once received, depends very heavily on the format in which you have the data.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might also want to see the code I have posted here:
http://arduino.cc/forum/index.php/topic,101401.0.html
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for the help. Our group could not figure out this Time library and we discovered that we there were better libraries for our purposes. I.e. we need to run a function every five minutes. We originally thought we needed to use a date and time system but have recently discovered the timer library. Thank you again for your help, it is greatly appreciated.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13663
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


In the category suggestions

this thread provides an interesting proposol to correct internal timing, think it is food for thought for the Time lib

- http://arduino.cc/forum/index.php/topic,106517.0.html -

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an idea for accurately tracking fractional seconds, here:
http://arduino.cc/forum/index.php/topic,107254.0.html

I believe that my idea will run rather efficiently, but the main advantage is that it handles slight inaccuracies of the oscillator in a very natural (for a microprocessor) way.
Logged

Pages: 1 ... 5 6 [7] 8 9 ... 18   Go Up
Jump to: