Simple timestamp in serial window?

I'm looking for a way to get arduino to print the current time in the serial window. I ran the date time code with processing and I got it to work but I'm not sure if the Arduino is sending time to processing or if processing is sending data to Arduino

Anyway, I want to be able to set up a PIR motion sensor and have it dump the time (date and time optimally) when it detects motion.

I've gotten a PIR sketch to work as there are plenty of examples but timestamps seem to be something not really discussed around here as searching for timestamp yields 1 post. Can someone help me out?

Wouldn't it be easier if Processing timestamped the received data instead?

I am not sure, but I think you would need either a circuit with a realtime clock (on the Arduino) or have a variable in your sketch that syncs with the current time retrieved from a computer or application as the Arduino don't have a 'clock' in itself keeping the time (except for millis() keeping the millisecs from the start of the sketch).

I hope someone could chime in whether or not the above is true.

Hi. Have you looked at macetech.com. He has a nice looking RTC board that is compatible with the Arduino, even some sample code for you. I hope this helps :slight_smile:

I'm looking for a way to get arduino to print the current time in the serial window. I ran the date time code with processing and I got it to work but I'm not sure if the Arduino is sending time to processing or if processing is sending data to Arduino

The example sketch waits for a single time sync message from Processing and then keeps the time for as long as the arduino board has power. But you could use processing to time stamp the display – when a message comes in from arduino it prints that data plus the local time (you can see example Processing code for getting the time in the dateTime Processing sketch)

If you would like to do it hardware checkout my NB1A board at Loading... I use a DS1337 that runs on a coin-cell battery so time is maintained when the power is off. I have an RTC library and a couple of example programs that dump a localtime string to the USB port. One example demos the alarm interrupts.

I will be adding an epoch time routine and the code for alarm2 and the square wave output.

(* jcl *)

www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

Wow, for such a simple function like time, this seems pretty complex. I guess everything is kinda complex under the hood. What if I did use milli's? Could I set that to equal the current time or something at the start of the sketch assuming that I kicked off my sensor trace at 10:00PM? I'm not really looking for a 24 hour a day clock, just a way to set the current time at the start of the sketch and maybe just print out an artificial time...

I bought one of those RTC chips but you need an engineering degree to get it working. Plus, I didn't realize you need crystal to get it to work. I think I did manage to salvage a crystal of the correct type off of an old mobo. I guess I'll try this route this weekend as a project.

Be careful of the crystal you use. You need to make sure the crystal capacitance and
series resistance match the clock.

There is a parts list in my NB1A datasheet.

(* jcl *)

I got it working with the crystal I extracted from my dead motherboard and I also snagged a coin cell batter holder from the mother board as well. Got a sketch running with the clock and temp sensor and it seems to be working just fine.

I wanted to place the clock components on their own little board so I was curious if there's something else I need. Do I need resistors or capacitors? Seems to be working fine all night and the time seems accurate. I have a 1 minute delay in the sketch and the latest timestamp after running all night landed on the same second as the first time stamp.

You mentioned capacitors or what not. Do I need it? The crystal says 32768 on it which is the correct crystal but I dont know much about it.

If it is reliably and is accurate it is unlikely that you need anything else.

On some RTC IC + XTAL combinations you may need a capacitor in parallel with each XTAL pin but that is usually not the case. The resistance I mention is a series resistance that is internal to the XTAL. Too high a resistance and the oscillator will not start.
Since your circuit is working accurately I do not believe you have either problem.

(* jcl *)

So under what circumstances would I start getting incorrect time? Is not having the correct crystal enough? Browsing Jameco.com for 32.768 crystals yields lots of different components to choose from with the same name.

If the capacitance is incorrect the oscillator will run too slow or too fast and time will drift..

The correct choice of crystal is dependent on the RTC IC you are using. The RTC datasheet will tell you the correct capacitance and will probably have some specific recommendations.

If you happen to be using a DS1337+ (or possible the DS1307) you could use the
same XTAL that I use. Check the NB1A datasheet at
http://www.wiblocks.com for the part number.

(* jcl *)