Setting time on a RTC from the ethernet

Please can anyone help a real newby. I want to set the Time and date on a DS3231 RTC using an ethernet connection only once on startup. From then on in the sketch I will use the RTC for timing. I have been using just the RTC but the RTC does loose time after a while possibly because it is switched off for a week or 2 at a time.

TIA.

Look at the NTP example in the Ethernet library.

I'm assuming you have an Uno or Mega with an Ethernet shield. Correct?

That should not happen. It indicates a weak battery or defective RTC.

When you say, "loose (sic) time", do you mean lose a few seconds, or complete loss of time?

Yes I'm using a Mega with an ethernet shield.

It generally looses about 2 minutes per month but recently it lost 6 hours in 2 weeks.

You definitely have a chip or battery problem. I have lost seconds after having the board powered down for months. (A river water monitor that spends the winter in storage.)

Thanks for that, I'll change both of them, and thanks for taking the time to look at my question.

Loses it. What kind of RTC is it? Do you have a link or spec?

I ran some DS3231 RTC modules with CR2023 for over a year just to see what would happen. They were about 30 seconds off at the end.

If you have an internet connection for something else, then it makes sense to update the time with NTP. Why not? That is how my clocks work. Mostly, they have RTC as a backup for NTP in case network is not available. They are refreshed via NTP every time power is cycled.

Thanks aarg, that's exactly what I want to do but I have managed to get the time from the NTP but failed to write it to the RTC. I think it's a bit advanced for me at the present time.

I'm not sure what you're asking for now.

You forgot to tell us exactly which RTC you have. Also post links to all the libraries that you are using.

The DS321 compensated version is pretty good at keeping accurate time and date.
I've been running one for years now and check the time daily against an MSF radio clock.
There might be a small deviation at the second level per day, but it seems random and the overall long term error is at the 1 to 2 seconds per 6-months or so.
Running on back up battery is not so good but I suspect that is down to poor batteries.
I would use something larger than the usual CR coin cells.

Dunno if you are aware of it, but you can fine-tune the oscillator in DS3231 modules and thereby make it very accurate:

Oooh another thing about DS3231... If you are running it from a 5V processor and a 3V battery, it runs on a different supply voltage when the main device is on, and when it is off. I haven't measured, but you could expect some variation from that. Also the infamous battery charging circuit (when using non-rechargeable Lithium) on the most popular DS module, is only a big problem on 5V. When Vcc is 3.3V, the charging current is nearly zero. So there are two reasons to prefer running the DS3231 on 3.3V if you can.

I did some calculations on the expected battery standby life of a CR2023 with the DS3231. It came out to about 10 years.

It's true that you can fine tune the DS oscillator. But the default register value for the trim, should not produce the errors on a scale like the OP describes.

The one I'm testing is a module and a cheapo at that.
I'm never happy with these cheap modules and would rather use the better ones like Sparkfun or Adafruit offerings, but as always, it's the dosh.
The module is getting a hammering thanks to the electricity supply company who once a month discover a new fault and off goes the power.
While they tinker around the power can go off and on in a second or less. The record stands at 8 outages in one day.
I got hold of a comparator module thinking it might save some time, but it never worked well and after some faffing about, it turned out not to have any hysteresis resistors.
So a lot of time wasted.
Would have done better right from the start to have got the chip, and put it together as recommended in the datasheet.
One lesson I did learn was not to use the phone clock for checking and so far, the MSF time has produced better results

Would it hurt to tell us which one? Maybe provide a link? After all the questions you have about it? See reply #8.

Frequent power outages shouldn't "hammer" an RTC module. I'm not sure exactly in what sense you mean that. I know of no power fluctuation situation that could disturb a DS3231.

I checked at the weekend. I'm using a diymore DS3231. I've connected it to the Youmile IC2 LCD module which runs on 5v. Could this be a problem?

The libraries I'm using are
Wire.h
DS3231.h
LiquidCrystal_I2C.h

aarg

Can't help you with the module specifically.
It's blue, unbranded, has headers both ends, chip on one side, CR2032 the other side, probably came from ebay.
Not sure what you mean about my questions and post #8.
All the problems with the module have been at the times of power outages.
It can drop or gain seconds or so each time.
The power cuts we get here are not clean off for 30-minutes, then back on cleanly.
These are short, sometimes less than a second, like someone touching two wires together.
Often they are high voltage faults and take out half the town.
It damaged so much of my equipment one day, they paid out compensation.
I have four UPS's running just to protect stuff.
It's just a feeling that it's no way to treat electronic equipment.
A homemade RTC, DS3231 from RS has run for 4-years and has never had to be adjusted.
I doubt that it is anything like as much as a minute out over that period, which is more than I can say for commercial stuff like programmable room thermostats from the likes of Honeywell.

This one?

I've connected it to the Youmile IC2 LCD module which runs on 5v. Could this be a problem?

The only possible answer: post a wiring diagram

Have you followed up with basic checks? Battery voltage?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.