I've been trying to set up the DS1302 RTC but I can't figure out how to set the date & time. I've been using this tutorial https://www.instructables.com/id/Arduino-Chicken-Coop-Controller/ (as it is similar to the project I am doing) however I can't figure out how to set up the clock from his code. Any advice would be appreciated.
a quick (less than one minute) google search returned this example:
// Make a new time object to set the date and time.
// Sunday, September 22, 2013 at 01:38:50.
Time t(2014, 10, 6, 12, 57, 50, Time::kMonday);
// Set the time and date on the chip.
rtc.time(t);
I have always played with the ds1307 which uses a similar code to set the time:
In both cases you only want to run the "set time" code once so enter the correct time into the code and run it, then comment out the code and run it again.
Always worth simply googling something like "arduino set ds1302 time" and reading the results. Also look in your Arduino IDE, if you have installed a library for ds1302 then there will most likely be an example to follow in the examples tab.
Having opened and read the FULL project code I notice you didn't include this in your post:
//----------------------------------------------
// Setting the Real Time Clock (RTC)
//----------------------------------------------
void set_time()
{
rtc.write_protect(false);
rtc.halt(false);
Time t(2012, 3, 26, 12, 40, 48, 2);
// Yr Mth Day Hr Min Sec Mon
rtc.time(t);
}
This line "set_time()" calls the above code and allows you to enter the correct time.
I've been trying to use a DS1302 real time clock, I've been using this tutorial https://www.instructables.com/id/Arduino-Chicken-Coop-Controller/ (as it is a similar project to the one I am doing) but I can't figure out how to set the clock. Any help would appreciated.
Plasterboard:
I've been trying to use a DS1302 real time clock, I've been using this tutorial https://www.instructables.com/id/Arduino-Chicken-Coop-Controller/ (as it is a similar project to the one I am doing) but I can't figure out how to set the clock. Any help would appreciated.
set_time();
GlobTime = 0;
Included in that tutorial code is this function:
void set_time()
{
rtc.write_protect(false);
rtc.halt(false);
Time t(2012, 3, 26, 12, 40, 48, 2);
// Yr Mth Day Hr Min Sec Mon
rtc.time(t);
}
If you are going to use "borrowed code" please read ALL the code and understand how it works..
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a suspension from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
As was stated the key is to alter the date and time in the define area before setup.
Make the time a minute in the future.
Load the shetch.
Watcj you browser time
At the time you picked . Reset.
The reset will set the time you picked.
Now the important part.
Do not turn off your arduino
In your IDE comment out the lines that set the time.
Then upload that code.