Hello,
Has any body idea how do i get time from pc to my arduino uno microcontroller. I have my hall effect sensor from I can read my sensor data. I need to add time stamp from current pc time.
Any idea ??
Hello,
Has any body idea how do i get time from pc to my arduino uno microcontroller. I have my hall effect sensor from I can read my sensor data. I need to add time stamp from current pc time.
Any idea ??
Has any body idea how do i get time from pc to my arduino uno microcontroller.
The Arduino needs to send a message to the PC "Hey, what time is it?". There needs to be some application running on the PC that is listening to the Arduino and that understands the message. That application needs to return the time to the Arduino, in a form that it can use.
The Time library provides an example.
A real time clock is a lot easier to deal with, and doesn't require a full time connection to the PC.
What does the Arduino do with the data that it cares what time it is on another computer?
I'm doing exactly what PaulS suggests. I send the host computer ?T as a request for the current time, and the host computer sends back a message that looks like T1329511483!, where the numeric digits are the unix date/time in seconds:
/*----------------------------------------------------------------------------*/
/* Get a single character from the host */
/*----------------------------------------------------------------------------*/
static int getb(void)
{ while (!(Serial.available() > 0)); /* Wait for data to arrive */
return Serial.read(); /* Return next character */
} /* end: getb() */
/*----------------------------------------------------------------------------*/
/* Get current date/time and set the system reset time */
/*----------------------------------------------------------------------------*/
void get_time(void)
{ time_t t; /* Current system time */
int c; /* Input character */
do /* Until end of message */
{ Serial.println("?T"); /* Send time query to host via USB */
t = 0; /* Initialize time value */
while ('T' != getb()) ; /* Watch for start of time response */
while (('0' <= (c = getb())) && (c <= '9')) /* Is this a decimal digit? */
{ t = 10 * t + (c & 0x0F); /* If so, build time value */
} /* end: building time value */
} while (c != '!'); /* Until a valid time is received */
set_time(ss(t)); /* Calculate and save reset time */
} /* end: set_time() */
/*----------------------------------------------------------------------------*/
Dear Morris,
I know I am kinda digging graves but I really need a clear understanding of the code which u wrote above.. Or really wonderful would be to have a sight of the complete code of the thing you tried to do..
In reference to the following thread:
http://forum.arduino.cc/index.php?topic=407330.0
I also need to command the arduino to ask real time date and time from PC in form of unix time stamp..
Any help would be greatly and deeply appreciated!
Regards
Pramit
OK, if you can get a UNIX time stamp, you can use Time library to manipulate it into real time (yyyy/mm/dd etc.). As PaulS said, you need a program on the PC side to tell Arduino time, on demand from Arduino.
Now tell us what PC operating system you are running and what programming languages you know of. I can provide a solution in Python if you need one.
sood:
I also need to command the arduino to ask real time date and time from PC in form of unix time stamp..
I wonder why you need to do this.
Thank you so much for retaining interest in the thread!!
Though I am comfortable more in C/C++ but I would be looking forward to any help possible..
I would be glad to have a solution in Python.. Looking forward!
Thank you again!!
Cheers
Pramit
Works nicely on my win7 PC. Send a single character to serial port and the PC sends EPOCH.
You need to install Python 3.5 and pyserial. What operating system are you running?
Hi Liudr!
Well I am also running Win 7!
I will try to look at it.. hope it works for me as well!!
Thanks a lot!!!
I will keep u updated!
Cheers!
Pramit
OK in that case, check out my python install tutorial:
I meant to write it, right after I wrote how to do it on linux and raspberry pi so now it's finally done.
liudr:
Online Programming CompilersWorks nicely on my win7 PC. Send a single character to serial port and the PC sends EPOCH.
You need to install Python 3.5 and pyserial. What operating system are you running?
Is the forum software not letting you attach it?
I'm just trying different ways to post code. This may give me a way to find/modify/update the code in case it needs to be posted on multiple threads as answers. Unfortunately the website wants FULL access to my dropbox in order to save the code.
Now to think about it, arduino.cc should have a paste bin to show code. You can have some neat sample code that everyone can say, "read this code" to solve that problem.
liudr:
I'm just trying different ways to post code. This may give me a way to find/modify/update the code in case it needs to be posted on multiple threads as answers. Unfortunately the website wants FULL access to my dropbox in order to save the code.Now to think about it, arduino.cc should have a paste bin to show code. You can have some neat sample code that everyone can say, "read this code" to solve that problem.
Mmmm... can't you just post it in code tags?
hello, friends i having trouble with dateTime library while using it.....
when i compile scratch it give following text....
Arduino: 1.7.11 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Build options changed, rebuilding all
In file included from DateTime.pde:10:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: conflicting declaration 'typedef bool boolean'
typedef bool boolean;
^
In file included from DateTime.pde:4:0:
C:\Users\Documents\Arduino\libraries\DateTime/DateTime.h:17:17: error: 'boolean' has a previous declaration as 'typedef uint8_t boolean'
typedef uint8_t boolean;
^
DateTime.pde: In function 'void loop()':
DateTime.pde:30:31: error: 'BYTE' was not declared in this scope
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Has google completely failed you? Delete the typedef statement from DateTime.h (the one on line 17).
Google the other error yourself.
Haii liuzengqiang
I really need time on pc to send to arduino A connected on pc. But I am confused to get the time. Can you help me. If i can please i ask arduino code also to read data from python.
liuzengqiang:
Online Programming CompilersWorks nicely on my win7 PC. Send a single character to serial port and the PC sends EPOCH.
You need to install Python 3.5 and pyserial. What operating system are you running?
I use python27. Can it?
ahmat:
Haii liuzengqiangI really need time on pc to send to arduino A connected on pc. But I am confused to get the time. Can you help me. If i can please i ask arduino code also to read data from python.
I use python27. Can it?
Do a search for python get pc time
Next do a search for python send data over serial port
Note: I have no python experience but more than you ever wanted to know should be available on the web.
And for the Arduino side, read Robin2's Serial Input Basics.