I am tring to create a clock with my arduino. I want the arduino to be loaded with my P.C system houres minutes and date while I am programing it.
I am fimilir with the time.h library, and a tried to initialize some some integers with it in the setup function, this way:
however, the integer wasnt initialized with the desired values.
can you please advice me hou can I do it right (this way, or even with other libraries?
I want the arduino to be loaded with my P.C system houres minutes and date while I am programing it.
Please clarify. how is the PC system time supposed to get to the code? dynamically ? or just by using #defines which captures last compile time (using __DATE__ and __TIME__ is the typical method used in RTC libraries)
i need just by using #defines which captures last compile time. can you give me please some example how can i extract from the DATE 3 integer that i can load into the arduino?
thank you for the help,
but, do i have to be useing a RTC device conneced to the arduino in order to use your code?
also, i cant find the way to add the <TimeLib.h> libraay (with <time.h> i dont have any problam...)
do i have to be useing a RTC device conneced to the arduino in order to use your code?
No.
i cant find the way to add the <TimeLib.h> library
Why are you trying to use a software clock? @Greek Emeritus has pointed out the issues with it.
The AVR macros TIME and DATE make compile time available to you.
If you Arduino is always connected to a PC, there are ways to write code which runs on the PC and will send the time to the Arduino when asked. I'd rather use an RTC.
evyad:
I am tring to create a clock with my arduino. I want the arduino to be loaded with my P.C system houres minutes and date while I am programing it.
The time when a program is compiled has no relevance whatever to the use of an Arduino as a clock.
It would be like the Goon Show script in which the idiot had the time written on a piece of paper.
Robin2:
The time when a program is compiled has no relevance whatever to the use of an Arduino as a clock.
well in practical terms though, if you compile and upload right away through the IDE, that lets you set the current time with a few seconds approximation. then your arduino needs to do the right thing with the info.
J-M-L:
well in practical terms though, if you compile and upload right away through the IDE, that lets you set the current time with a few seconds approximation. then your arduino needs to do the right thing with the info.
It seems to me a very unlikely scenario where the program is uploaded and then allowed to run continuously without ever being reset.
If the Arduino clock is to remain connected to the PC that uploads the program then why not periodically query a program on the PC to get the latest time.
Robin2:
It seems to me a very unlikely scenario where the program is uploaded and then allowed to run continuously without ever being reset.
yes typical use case is you load it once to initialize the RTC with the "right time" then comment out the code and re-upload.
Robin2:
If the Arduino clock is to remain connected to the PC that uploads the program then why not periodically query a program on the PC to get the latest time.
in the grand scheme of things, clocks should stay the same
(but in theory there is no difference between theory and practice. in practice there is )
probably better to add some sort of communication, may be if Wi-Fi and internet is available, then sync on a time server. that's probably also what the PC does
in the grand scheme of things, clocks should stay the same
(but in theory there is no difference between theory and practice. in practice there is )
I use a Raspberry Pi as a workshop computer. I rarely take the cellphone back there, so it never syncs to nist.gov. the clock is essentially a random number generator