1. I am preparing a tutorial on DS3231 RTC Module (Fig-1); where, time of the day is being shown on the Serial Monitor at 1-sec interval as a test purpose. The 1-sec time delay interval has been implemented using DS3231's own time.
Figure-1:
2. The problem is with the display of "second" on the Serial Monitor (Fig-2); where, the display does not go through 00 when 59 sec arrives. The time is being shown as (for example) 12:00:59 (2-sec delay) 12:01:01 instead of 12:00:59 ---> 12:01:00 ---> 12:01:01.
While I look for the library you are using and an RTC, would it please you to try the scatch you posted with the following change of your Serial.begin(9600)?
Serial.begin(115200);
Be sure to adjust the baud rate in the Serial Monitor window.
I am studying your codes of Post#5 with devotion and will let you know the result tomorrow inshallah. Now, it is 2:50 am (after mid night) in my country. I am nearly an old man and need to go to bed.
The DateTime class has functions that return contents of a structure filled by the (one) call to etc.now();
I also thought it looked fishy. Or was there something else I still miss?
Edit: never mind, I see. He could drop the local variable he further uses and always call the function, or always use the value he gets from one call. In either event, the value will not be different if the DateTime is not changed.
When prSec is 59 and bcdSecond() is 59, 59-59 is not equal to 1 so the loop repeats.
When bcdSecond() rolls over to 0 it sets prSec to 0.
Now prSec is 00 and bcdSecond() is 00, 00-00 is not equal to 1 so the loop repeats.
Eventually, bcdSecond() rolls over to 1.
Now prSec is 00 and bcdSecond() is 01, 01-00 is equal to 1 so the loop finally stops.
You can fix it by changing it to:
while (bcdSecond() == prSec)
And be sure to remove the setting of prSec out to bcdSecond, otherwise, it will continue to skip second 00.
So much gratitude for reposting the complete sketch (Post#13) with the inclusion of the following modified line along with detailed analysis for such modification. Tested and it works.
while (bcdSecond() == prSec) //in place of while (bcdSecond() - prSec !=1){;}
{
}
I would like to remember Leibnitz and Newton (who independently developed the Calculus) in this context of my DS3231 related problem; where, @alto777 and @johnwasser have also independently developed the same solution to my problem of DS3231 time display.
Sixteen posts, and all you want to do is tell the time? how can this be so difficult? Surely Jack Christensen said all that could possibly be said many years ago. I have never heard of this problem, I didn't listen to everything Jack had to say, and I don't even use his libraries, but, if there is a problem, I bet he had the answer. So, what is really going on here?
Nick_Pyner:
[...] I don't even use his libraries, [...]
If it is an engineering project, the engineer can omit the use of Library functions as he is capable enough to write codes of his own to control the device; but, Library functions are proven useful tools for the beginners/trainees.