Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Keeping time


  • Please log in to reply
5 replies to this topic

#1 JonnyBoats

JonnyBoats

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts
  • LocationPhillips, ME

Posted 05 March 2011 - 04:14 PM

I know I can wire up an external clock/timer chip to a Netduino to keep track of the date and time, but I am wondering is there a way to have the Netduino keep track of the date and time by itself assuming one properly initializes the values. For the old timers like myself, you may remember that the initial IBM PC did not have a built in clock, so when one booted the PC the first thing it did was ask for the date and time from the user and then it kept track of it until you powered the PC off. Just guessing that the Netduino has as much processing power as the original PC ;-)

#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 05 March 2011 - 05:07 PM

Just guessing that the Netduino has as much processing power as the original PC ;-)

Off topic but the ZX81, probably the first cheap usable home computer is 30 years old today.

This had me thinking about how times have moved on looking at my hobbies then and now. At the time I had an amateur interest in electonics. This lasted about 4 years and then lapsed as I could not find the money to support the hobby and go through university at the same time. 30 years on and I now find myself playing with hardware once again.

Looking back to 1981 we had the ZX81
  • Z80 based system based on the MK14 computer kit (worked on by Chris Curry)
  • 64 KBytes RAM
  • Video output to TV
  • No real keyboard
  • Programs written in BASIC, stored as byte codes and interpreted
In 2011 I find myself playing with the Netduino
  • ARM based processor (ARM was born from Acorn Computers which in turn was founded by Chris Curry)
  • 60 KBytes RAM
  • No video output
  • No keyboard at all
  • Programmed in C#, stored as byte codes which are interpreted
Sorry about this being off topic...

Regards,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 Joe Griffith

Joe Griffith

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 05 March 2011 - 06:00 PM

The Netduino does have a clock: Microsoft.SPOT.Hardware.Utility.SetLocalTime(SomeDateTime);

#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 February 2014 - 02:31 PM

OK, I give up.

 

I know its going to be really obvious to someone who does C# for their day job:

 - How do I read the "local" time back after using SetLocalTime() ???

 

Paul - ever so slightly frustrated after spending an hour searching the forums and the web. :(



#5 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 February 2014 - 02:43 PM

OK found it.

 

Needed to take a deep breath and try a new search.

DateTime theTime = DateTime.Now;

or

DateTime theUtcTime = DateTime.UtcNow;

and if you want the date

DateTime theDate = DateTime.Today;

which returns the date and time, with the time part set to all zeros. Not sure if thats the local date or UTC date!

 

Too obvious for me to find.



#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 15 February 2014 - 03:04 PM

Simple test/demo program:

using System;using Microsoft.SPOT;namespace Clock_TestHarness{	public class Program	{		public static void DisplayTime()		{			// Read current times			TimeSpan machineTimeNow = Microsoft.SPOT.Hardware.Utility.GetMachineTime();			DateTime localTimeNow   = DateTime.Now;			DateTime utcTimeNow     = DateTime.UtcNow;			DateTime dateTimeNow    = DateTime.Today;              		  // Display current times			Debug.Print("Machine time = " + machineTimeNow.ToString());			Debug.Print("Local time   = " + localTimeNow.ToString());			Debug.Print("UTC time     = " + utcTimeNow.ToString());			Debug.Print("Today        = " + dateTimeNow.ToString());		}		public static void Main()		{			// Display current times			DisplayTime();			// Set the local time			System.DateTime dt = new System.DateTime(2014, 02, 16, 13, 50, 30);			Debug.Print("Setting local time with: " + dt.ToString());			Microsoft.SPOT.Hardware.Utility.SetLocalTime(dt);			// Display current times			DisplayTime();			Debug.Print("Done");  // Set breakpoint here to hold output window open		}	}}

Gives following output:

Machine time = 01:02:23.9064746Local time   = 06/01/2011 01:02:23UTC time     = 06/01/2011 01:02:23Today        = 06/01/2011 00:00:00Setting local time with: 02/16/2014 13:50:30Machine time = 01:02:23.9760426Local time   = 02/16/2014 13:50:30UTC time     = 02/16/2014 13:50:30Today        = 02/16/2014 00:00:00

Hope this saves someone some time searching!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.