Serial monitoring clock in Arduino without any components

Hey

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.

Anyone help? :slight_smile:

Anyone help?

Without seeing your code? No.

/*

  • TimeSerial.pde
  • 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
}

It’s basically a library…

I found that I can use the SyncArduinoClock program from arduino in the Processing program.

I followed this tutorial and got the processing sketch program to work, and it displays the time in that program.

But I want it to show in Arduino, I've tried to reupload the program after I got the processing program to work.

tommaking:
It's basically a library...

So what are you complaining about?

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".

So... how can I fix this?
I'm kind of new to this Arduino and processing stuff..

tommaking:
So... how can I fix this?
I'm kind of new to this Arduino and processing stuff..

Describe the programming logic that you want to establish!

Setting a callback function (" setSyncProvider(callBackfunc)") is intended for

  • automatic synchronizing from RTC (or other time source)
  • in equal time intervals

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?

Describe the programming logic that you want to establish!

It’s an example from the Time library. It is relatively well understood here.

PaulS:
You know that Processing is talking to the correct serial port, right?

Screenshot - 56a030618e1a1295fc3dbc9e2b1f8e19 - Gyazo When I use the portIndex 0 it works, but I can't upload the program to arduino at the same time, that's what it says i should do here: How To Get the Arduino Time Library up and going | Oops Oh No

Screenshot - f9b457d88d8f184a524412fca1657dea - Gyazo When I use port 3 the program stops working.

Screenshot - 56a030618e1a1295fc3dbc9e2b1f8e19 - Gyazo When I use the portIndex 0 it works

So, you know which port the Arduino is connected to, and where it is positioned in the list Processing knows about.

but I can’t upload the program to arduino at the same time

Well, of course not.

Perhaps you should sell the Arduino and get a PIC.