I have a Chronodot connected to the Uno and I'm able to read the time, but I can't figure out how to set it. I have a very basic knowedge of C, I don't yet fully understand scope and variable definitions. I thought that setTime() returns the time in time_t or t, and calling RTC.set() would set the RTC, but it's not working. Below is a code sample. Thanks in advance for help and advice.
Mitch
setTime(hSet,mSet,sSet,dSet,tSet,ySet);
RTC.set(t); // set the RTC and the system time to the received value
setTime(t); /added this, but still doesn't set
Thanks for the reply. I thought that passing the values to setTime() will set t, which is then passed to RTC.set(). If not, I'm not sure how to do it. I'm just starting with this.
I thought that passing the values to setTime() will set t, which is then passed to RTC.set(). If not, I'm not sure how to do it. I'm just starting with this.
You need to show the setTime function. Perhaps it sets a global variable. Perhaps it returns a value that you are supposed to save in a variable. The snippet you posted is far from enough to tell whet your problem is. Post ALL of your code.
Yes, it is from the Time library. The code that I posted is called from the loop function. There isn't much more, just some assignment statements that set variables passed to setTime(). Am I correct in assuming that I just need to get that data into t? If so, how is that done?
If I'm looking at this correctly, and that's probably in doubt, in Time.h, setTime() calls makeTime(), which puts the time into time_t. At that point I don't understand enough about C to know what to do.
The code that I posted is called from the loop function. There isn't much more, just some assignment statements that set variables passed to setTime(). Am I correct in assuming that I just need to get that data into t? If so, how is that done?
Hard to say. You won't post your code.
If I'm looking at this correctly, and that's probably in doubt, in Time.h, setTime() calls makeTime(), which puts the time into time_t. At that point I don't understand enough about C to know what to do.
time_t is a variable type like int or char, not an instance of a variable of that type.
It's hard to say what you need to do, because you won't post your code.
If setTime(t) does set the Arduino time to t, shouldn't RTC.set(t), set the RTC time?
That's hard to say, because you won't post your code.
Here's an example, less the working code from my sketch. I'm sure this is a problem with my understanding of how to make it work, not a problem with the libraries.
It appears that setTime() sets the time in t, so passing it to RTC.set() should set the Chronodot, but it does not.
So how can the RTC be set to the time passed to setTime()?
Change the order of operations. Call setTime first, then call now(), then call RTC.set().
The setTime() function tells the Arduino what time it is, relative to how long it has been running. Then, now() converts the current time (relative to how long the Arduino has been running) to a time_t type value. Finally, RTC.set() takes that time_t variable and sets the time on the RTC.
You probably want to move the code to set the clock to setup(). Otherwise, the RTC will keep getting reset.