Accurate timer/clock

Great - unfortunately I've not been able to google anything that makens sense to me on how to do just that. That's why I'm asking in the first time on any pointers on how to do it...

The first thing to do is set up the DS3231, following any of the countless tutorials on line describing how to connect it, and set/read the time. Come back to the forum when that is done.

Can I ask you to either read my posts or stop commenting as this is getting stupid. I've already said that I have a DS3231 and telling me to read on of the countless toturials on how to connect it (I've already done that and so far none of them have mentioned pulling 1 Hz from SQW) isn't any help. You really dont have to reply if you don't want to...

Why have you not posted the code, as required by the forum guidelines?

That way, forum members can answer specific questions, with specific suggestions.

Be sure to include a link to the specific DS3231 library you have chosen to use.

What code would you like to see, the excact copy of one of the toturials on how to connect the dS3231? What possible would the bring to the discussion that's not already here in the first place?

I fail to see how my question asking for pointers on how to implement the solution suggested in the first place isn't extremely specific??

For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

Good luck with your project.

Well aren't you fun at parties, just because you don't want to be bothered reading my posts and understanding the question at hand doesn't mean that it's not specific...

You could use any DS3231 clock program. Set the hour/minute/second all to zero (in the setup function). Set day to 1 and substract 1. Start the Arduino when the race begins.

Why not try to read the spec sheet like everyone else has to do instead of wanting others to do your work for you?

Here, I'll make it easier for you....... https://www.analog.com/media/en/technical-documentation/data-sheets/ds3231.pdf

@bluejets

I have never asked anybody to do the work for me? If I knew how to do everything there's hardly any point in being in a forum asking for help? That's also why I was asking for pointers on how to do what was suggested, which i have yet to find in a form that's somewhat understandable for me.

Take a look at post #5 in this link:

1HZ SQW

@yamdaka

Thank you!

Install the Adafruit DS3231 library, find the ds3231 example sketch, replace this

void setup () {
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

with this

void setup () {
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
   // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
   rtc.adjust(DateTime(2014, 1, 1, 0, 0, 0));
}

You're quite welcome, that should be all you need. If you have
further problems please post your code and we will help.

There's also - https://www.youtube.com/watch?v=2xZ15ntJy20

1 second in 4 days is about 3ppm, which is a pretty high bar.

You could get one of the Arduino clones that has a crystal instead of a resonator for the main clock, and it would be "better" than the standard Uno (but probably not 3ppm!)

First of all, sorry for late response. I feel little bit responsible for this discussion over DS3231 use and accuracy to a second or under second.

Second thing, it seems to me little harsh against to @jremington. I mean this:

In his defense, it is easy to lose a track in the topic especially with its growth and number of topics the one is currently following. I do not know him personally, but in my eyes, he is one of the most valuable people here on the forum for years. We help voluntarily. Reward monetary is thank you or little heart icon under the post. So please, be kind.

Back to the problem. If the requirement is just 1 second, there is a different solution which seems to me simpler on the UNO side. DS3231 has possibility to use !INT!/SQW as 1Hz output, @GolamMostafa's tutorial posted by @yamdaka. Is is easy use this 1Hz output from DS3231 with HW interrupt on UNO e.g. INT0 - UNO pin #2.
ISR will be just updating time about 1s at each call. There are plenty Unix like time libraries, just google for it. There is time keeping 4 byte variable, the value is in seconds.
All you need is DS3231 and UNO to start with experiments.

Just note at the end. I mentioned use of the default 32768Hz default square signal to obtain a resolution under 1s. It is possible but using the timer/counter in this case.

The Uno clock source is a resonator, affected by temperature.

You can get or build a board with a crystal, it will be crystal watch accurate. No RTC required except if you want the features.

In case he decide to use the 32k output, it is more feasible use the 16-bit. Timer/Counter1 (pin #5) in case of UNO. Let say go down to 1024 by prescaler and deal with residuals similarly like in case of original Arduino micros/millis, already pointed out by @JCA34F (post#16).

There are many possibilities how to solve the problem.

And of course, problem with UNO is that the Timer/Counter2 input is occupied by main resonator.
I struggled with this years ago. Arduino portfolio wasn't as wide as now. I tried to use Mega2560. TOSC1,2 for the Timer/Counter2 are not pinned out so I decided to pin out TOSC1 to the unused pin on Arduino Mega2560 next to IOREF. Good enough to feed it with 32k square signal from DS3231.
Finally, I built my own Arduino board.
http://forum.arduino.cc/index.php?topic=277260.0

image
It is based on ATmega1284P. It has 32k input on the header and also pads for 32k crystal.

Thank you for taking time to reply :slight_smile:

I'm all for helping and I really do appriciate all the help you guys provide, but there's a difference between reading and genuinely wanting/trying to understand the topic and offer a possible solution (like you did, and again I appriciate that a lot) and basically not reading the posts and "answereing" in a super demeaning tone without actually offering any solutions at all (as nothing was done to try to understand the question and situation).

But back to the topic at hand :slight_smile:
1 second is acceptable, but less drift in time the better. So given I now have a DS3231 at hand would you suggest the approach you initially suggested or the one @yamdaka posted yesterday? :slight_smile: