I've been working on a time Triggered Servo. My question is will the code in the file I attached or as viewed in the link be able to keep track of the time once I set it with my PC and unplug it and then power it with a power supply?
I thought it was supposed to as I'm using Time library 1.5 by Michael Margolis.
When I set the time with the serial monitor and unplug the arduino, I then plug it into a powersupply it doesn't seem to keep the time
Also in the code at about line 95 I thought it is supposed to start with the time I programmed in. I updated the epoch time instead of Jan 2013 and it doesn't seem to take it. Any ideas?
void processSyncMessage() {
unsigned long pctime;
const unsigned long DEFAULT_TIME = 1543092290; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013)
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
I've been working on a time Triggered Servo. My question is will the code in the file I attached or as viewed in the link be able to keep track of the time once I set it with my PC and unplug it and then power it with a power supply?
I thought it was supposed to as I'm using Time library 1.5 by Michael Margolis.
When I set the time with the serial monitor and unplug the arduino, I then plug it into a powersupply it doesn't seem to keep the time
Also in the code at about line 95 I thought it is supposed to start with the time I programmed in. I updated the epoch time instead of Jan 2013 and it doesn't seem to take it. Any ideas?
void processSyncMessage() {
unsigned long pctime;
const unsigned long DEFAULT_TIME = 1543092290; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013)
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
When you unplug the Arduino, all the contents of variables is lost. This includes the time. This is why RTC boards usually include a battery or storage capacitor. The memory of the time must be maintained, as well as a way of periodically updating it.
An Arduino that is off, has no concept of the passage of time.
Also an Arduino without some means of periodically correcting its internal clock from an external source like an RTC, PC, NTP will drift. The speed of drift will depend on the Arduino clock reference accuracy and temperature.
SquirrelFX:
That's what I'm wanting is a hard coded time. The problem is,
Is that it doesn't seem to be going off my hard coded time?
Could someone review my code that I attached and see if I'm missing something?
A hard coded time isn't really the time, is it? The only thing you can use it for, like this, is to measure intervals such as an hour, a day, a week etc. And if that's all you want to do, there is no need for a time library at all. Just use millis().
There seems little point reviewing your code (which you have not posted according to the forum guide, by the way) when you have been working under a complete misunderstanding about the time library and what it should be used for.
SquirrelFX:
... Could someone review my code that I attached and see if I'm missing something?
It is procedurally difficult to use code that has been attached as an .ino file. The IDE wants to create a folder for it, and this leads to problems on just about every system. Fortunately .ino files contain plain text, you you can just copy the code from the IDE's window. Then in the forum, type [code], paste your code, then type [/code]. You can skip the [code][/code] part, but then nobody will help you.
You know how, after a power outage, your microwave oven loses the time and you have to reset it?
Why do you have to reset it? Why doesn't it just keep time through the power outage?
It doesn't keep time through the power outage because it can't. (To the best of my knowledge, electronics can't do much of anything without power.)
The microwave oven has buttons which allow you to set the time at will. Perhaps in your project you should include some way to set the time manually, such as with buttons.