Can't time sync to save my life!

I have been working for 3 nights and I can’t figure out how to sync my Arduino Mega with my PC. I also have a, I2C/SPI/Onewire Shield that I have use or not used while trying to get this working.

I want to get a synced time and store it in the I2C/SPI. Then I want to start a program at set times throughout the day. ie. 1:00, 2:00; 3:00 etc. but it might be changed to 1:21, 2:15, 2:22, 10:05 ... That would be closer to the alarm function.

I have tried the libraries Processing, TimeSerial, TimeSerialDateString, TimeRTC, SoftSerial, on and on.

I thought that Process SyncArduinoClock should do it but I can’t compile it because:

import processing.serial.*; is not filed out.

It says: // portIndex must be set to the port connected to the Arduino

But I don’t know what that means. I am using com port 5 to upload to the Arduino.

I also read about not being about to get the time through the serial port at the same time as and having the serial monitor open. That is all a little over my head.

Please help me by spelling out what I need to type in, where.

Add a RTC e.g. the DS1307 to your hardware and sync this with NTP - http://www.arduino.cc/playground/Main/DS1307OfTheLogshieldByMeansOfNTP - once per day Then you will have a quite accurate time (within a few seconds/day)

I want to get a synced time and store it in the I2C/SPI.

Start simple and build up to more complex functionality.

I want to get a synced time

There, that’s easier.

The Arduino sends a message to the PC, asking for the time. A Processing sketch running on the PC hears the request, and responds with the time.

This means that you have to have the correct code running on the Arduino, AND the correct code running on the PC.

I thought that Process SyncArduinoClock should do it but I can’t compile it because:

import processing.serial.*; is not filed out.

It says:
// portIndex must be set to the port connected to the Arduino

But I don’t know what that means.

Where are you trying to compile this code? What does “is not filed out” mean? What is “It”?

If you are trying to compile that in Processing on the PC, it should compile. The Serial.list() function returns a list of port names that Processing would be able to talk to. Print that list, using:

println(Serial.list());

in the Processing sketch.
Then, find where the port name that your Arduino is using (“COM5”) is in the list. The position in the list (0 is the first position, 1 is the second position, etc.) is the value that needs to be assigned to portIndex.

I'm at work now and haven't been able to try anything but to answer your question but: On my pc, I looked in examples and loaded processing and compiled it as is. The line:

import processing.serial.*;

gets an error from the compiler. I simply guessed that the "*" character was an invitation to make a change to the right setting at that point. I don't know how th fix that line so it will pass.

If I understand you correctly, I will change the portIndex to 4 to point to com 5. I will reprot my result when I get home. Thank you all,

The line:

import processing.serial.*;

gets an error from the compiler.

What error?

I simply guessed that the "*" character was an invitation to make a change to the right setting at that point.

It was not.

If I understand you correctly, I will change the portIndex to 4 to point to com 5.

No. If the Arduino is connected to COM5, the list might consist of COM1 and COM5, COM5 and COM9, just COM5, or COM5 might not be in the list at all. You need to print the list, and see where COM5 appears in the list. The index for that entry needs to be stored in portIndex.

This is part of the errors when I run SyncArduinoClock SyncArduinoClock:13: error: 'import' does not name a type SyncArduinoClock:15: error: expected unqualified-id before 'public' SyncArduinoClock.cpp: In function 'void setup()': SyncArduinoClock:23: error: 'size' was not declared in this scope SyncArduinoClock:24: error: 'class HardwareSerial' has no member named 'list' SyncArduinoClock:24: error: 'println' was not declared in this scope SyncArduinoClock:25: error: 'class HardwareSerial' has no member named 'list' SyncArduinoClock:25: error: 'portIndex' was not declared in this scope SyncArduinoClock:26: error: 'myPort' was not declared in this scope SyncArduinoClock:26: error: expected type-specifier before 'Serial' SyncArduinoClock:26: error: expected `;' before 'Serial'

When I run TimeRTC.pde, I get this. RTC has set the system time 0:00:00 31 12 1999 0:00:01 31 12 1999 0:00:02 31 12 1999

When I run softrtc.pde, I do get actual the time. It don't matter whether the I2C/SPI shield is plugged in or not. 2011/4/14 23:52:32 seconds since 2000: 356140352 now + 7d + 30s: 2011/4/21 23:53:2

2011/4/14 23:52:35 seconds since 2000: 356140355 now + 7d + 30s: 2011/4/21 23:53:5

This is part of the errors when I run SyncArduinoClock SyncArduinoClock:13: error: 'import' does not name a type SyncArduinoClock:15: error: expected unqualified-id before 'public' SyncArduinoClock.cpp: In function 'void setup()':

Are you trying to compile Processing in the Arduino IDE?

I'm sorry what is an IDE? I am opening the arduino program (0022) and loading the example.

I am opening the arduino program (0022) and loading the example.

The IDE (Integrated Development Environment) is the thing you develop Arduino code (C/C++) in. The one for Processing (Java) is a separate one.

Ok I guees that I am in the C/C++ IDE.

So does anyone have an idea why I can't compile SyncArduinoClock?

Have you tried Processing?

Yes That is were I am. I went to Examples/Time/Examples/Processing/SyncArduinoClock

Under Processing, the only thing that is available is SyncArduinoClock. Do I have something installed wrong?

Can't help at the moment - I'm parked at 0021.

Any 0022 users care to chip in?

Yes That is were I am. I went to Examples/Time/Examples/Processing/SyncArduinoClock

The only place that menu structure shows up is in the Arduino IDE. The code you are trying to compile is a Processing application. Copy that code, paste it into Processing, and it will compile.

[quote author=Asa Herring link=topic=58446.msg422686#msg422686 date=1303066265] Yes That is were I am. I went to Examples/Time/Examples/Processing/SyncArduinoClock

Under Processing, the only thing that is available is SyncArduinoClock. Do I have something installed wrong? [/quote]

SyncArduinoClock is not an Arduino sketch. It will not compile or run if you are in the Arduino environment. SyncArduinoClock is a Processing sketch. It will compile within the Processing environment. Processing is the name of a separate program; it is not part of Arduino.

Do you have the Processing program installed on your system?

Now, before we get too involved here, I will tell you my take on it:

The Processing sketch, SyncArduinoClock is set up like this: It owns the serial port. It listens for stuff on the serial port and prints it out (in the message window below the Processing edit window.) When you are running the SyncArduinoClock sketch, Processing sends a "synchronization" message over the serial port that contains information about current time on the PC. It sends the message when it first starts and it sends a message every time you do a mouse-click in the little gray box that Processing creates whenever the SyncArduinoClock sketch is running.

If the Arduino is running a sketch like TimeRTCSet, it can use the message from Processing to set the time on an I2C Real Time Clock on the Arduino. There is no way (no way) that the Arduino can query the Processing sketch from time to time to maintain synchronization. Furthermore, if that Processing sketch is running, the Arduino can't use the serial port for normal Arduino reading and writing.

Maybe you can concentrate on learning Arduino first. Write an Arduino sketch that lets you enter date/time in some convenient-for-humans form from the Serial port and set the RTC from that. Stuff like that.

Anyhow, once the RTC is set (by whatever means) you can use it as a reference for (alarms or whatever) and it will maintain its time when you power cycle or otherwise reset your Arduino.

Regards,

Dave

Thank you,

I was pulling my hair out, trying to figure out why everything else ran eventually and this didn't. I will back up and take the approach that you suggest.