I am trying to make a clock in Arduino which I can watch only from the Serial Monitoring
I have the program ready, but when i go to monitoring, all it says is "Waiting for sync message"
I also downloaded the Processing Sketch and Gobetweno, but I don't know how they work, so it's a little hard for me.
I typed in this command "TZ_adjust=-5;" in the serial monitoring when I got the error message "Waiting for sync message" and it started the clock from 1 january 1970.
example code illustrating Time library set through serial port messages.
Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2013
T1357041600
A Processing example sketch to automatically send the messages is inclided in the download
On Linux, you can use "date +T%s\n > /dev/ttyACM0" (UTC time zone)
*/
#include <Time.h>
#define TIME_HEADER "T" // Header tag for serial time sync message #define TIME_REQUEST 7 // ASCII bell character requests a time sync message
void setup() {
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
pinMode(13, OUTPUT);
setSyncProvider( requestSync); //set function to call when sync required
Serial.println("Waiting for sync message");
}
void loop(){
if (Serial.available()) {
processSyncMessage();
}
if (timeStatus()!= timeNotSet) {
digitalClockDisplay();
}
if (timeStatus() == timeSet) {
digitalWrite(13, HIGH); // LED on if synced
} else {
digitalWrite(13, LOW); // LED off if needs refresh
}
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() {
unsigned long pctime;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013)
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
}
time_t requestSync()
{
Serial.write(TIME_REQUEST);
return 0; // the time will be sent later in response to serial mesg
}
Your time synchronizing function always returns a Unix timestamp of 0.
time_t requestSync()
{
Serial.write(TIME_REQUEST);
return 0; // the time will be sent later in response to serial mesg
}
Unix timestamp 0 is 1st January 1970, 00:00:00 UTC time.
That's what your function returns to synchronize date and time.
0 is used all the time to synchronize time, never any other value.
Even not "later".
Your time synchronizing function always returns a Unix timestamp of 0.
But that function is only called when a sync needs to be done, and the return value is not used.
The loop() function calls processSyncMessage() is there is serial data. That function is going to read the serial data, and do something if the serial data is meaningful.
OP: Look at the TX and RX lights on the Arduino. Do they ever flash, indicating that the Arduino is sending the request and getting a response?
You do not have the Serial Monitor application open at the same time, do you?
You know that Processing is talking to the correct serial port, right?