Hi All, I just received a couple of these very cheap, neat DS3231 based real time clock modules from China (ebay specials) and have spent a good while getting them configured with the latest (mid-2016) Jessie based Raspbian. The current info on the internet is mostly out of date, so by piecing together nuggets from here and there, I've established the minimum amount of work necessary to configure latest Raspbian (lite) to get the RTC module working. It's very simple

There are only two edits you need to do:
1. put the below line into the /boot/config.txt file: (edit it with your favourite editor and type the line in - or copy and paste it from here )

dtoverlay=i2c-rtc,ds3231

2. edit the /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines ("comment out" means put a # at the beginning of each of the lines, so they become comments and are ignored by the system)

if [ -e /run/systemd/system ] ; then
exit 0
fi

so they become:

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

...and that's it - that's all you need to do. Shut down your system, connect the rtc module, then power up and test with the command:

sudo hwclock -r

this will read the time directly from the rtc module. If a sensible time string comes back, then you're cooking! Fully test by powering off the pi, disconnecting network cable (if you're running wireless, you may need to turn your router off for a bit), plug a screen into the hdmi output of the pi, wait 10 mins, then power it up. Once it's up, using a locally connected keyboard, log in and type "date" - if the time is correct and not 10 mins slow (or however long you had the pi powered down for) then the system has read the time correctly from the rtc module!!

Some posts have recommended de-installing the fake-hwclock package, or the ntp package - there's no need to do that - just do the above.

Before settling on the above steps, I tried lots of things from several web posts, including removing packages, downloading stuff, modifying the /etc/init.d/hwclock.sh file etc. I saw some of the rtc corruption that others have seen. But in the end (after re-flashing a new Jessie lite image several times ) the above was all that was needed. I've done this on a couple of different pis now, and the above seems to work consistently. So, all good.

Following on from the above, here's a picture of the modules I used (the connector simply plugs onto the first 5 pins of the pi) - here are some useful hwclock commands to test and play. They all need to be run as the root user, so precede with "sudo" if you're not running as root:

read time directly from rtc module
hwclock -r

update rtc module time from system time (system time should be regularly updated by ntp from the internet if your pi is networked):
hwclock -w

update system time from the rtc module (this should happen on startup):
hwclock -s

and the most fun of all - monitor the "drift" between your system clock and the rtc module:
hwclock -c

the above command will not return to the prompt, it will run continuously, printing the clock drift every 10 seconds, until you interrupt it (with Cntl-C).

I'm presuming that the shape and construction of the module would be irrelevant to it's operation, if it's using the same chip (DS3231). So the above instructions should work regardless of the origin of the device itself. Let us know if your experience is different (with a picture if possible) as it would be good to know if certain modules labelled DS3231 behave differently. It may be that there are clone chips or mis-labelled modules out there...

Sorry to be a pain but you said you installed it on the first five pins, as a total newbie and having got one of those modules please can you confirm the pins used, I want to use it on a Pi that is run offline.

I've installed a DS3231 RTC into a Pi and I have it working nicely, and what I'd like to be able to do is have the RTC automatically updated by NTP every, say, 15 minutes. Should I use a cron task with hwclock -w or is there a better way to do this?

I've recently come across an interesting "gotcha" with the otherwise very nice modules. That yellow rimmed object on the bottom isn't a battery. It's supercapacitor. This means that if you have a stock of spare RTC modules or you have a module on a Pi which is used sporadically, you are rather likely to find that the RTC module doesn't work, at least until the cap recharges. I have yet to see any data on how long it takes to recharge the cap or how long the charge on it will keep the RTC running if no other power is available.

So...does anyone know of a "Pi ready" DS3231 RTC module that takes a replaceable battery? (Note all the qualifications...the Adafruit DS3231 module has a replaceable battery, but it comes with male header pins and the pinout doesn't match the Pi.)

I have several Adafruit RTC breakout boards in use. One DS1307 is plugged into a solderless bread board. And wired to my Pi via jumpers and a GPIO breakout board. Adafruit calls them cobblers. That Pi is dedicated to bread boarding circuits so I don't mind the RTC being hoked up with jumpers.

The other DS3231 is soldered to a Proto Hat. The proto hat is plugged into the GPIO header of my Pi and has a sense hat on top of it. An Astro Pi I guess. https://www.adafruit.com/products/2310 I used a stacking header instead of the one that comes with it.

W. H. Heydt wrote:I've recently come across an interesting "gotcha" with the otherwise very nice modules. That yellow rimmed object on the bottom isn't a battery. It's supercapacitor. This means that if you have a stock of spare RTC modules or you have a module on a Pi which is used sporadically, you are rather likely to find that the RTC module doesn't work, at least until the cap recharges. I have yet to see any data on how long it takes to recharge the cap or how long the charge on it will keep the RTC running if no other power is available.

Just checked through my little pile of these (bought for $1 each in a lot of 5 ) I can see different parts of the text depending on how the cell landed when they welded the connector on. Looks like the battery is a Lithium CR1025.

The PCF8523 is simple and inexpensive but not a high precision device. It may lose or gain a second or two per day. For a high-precision, temperature compensated alternative, please check out the DS3231 precision RTC.

I have several Adafruit RTC breakout boards in use. One DS1307 is plugged into a solderless bread board. And wired to my Pi via jumpers and a GPIO breakout board. Adafruit calls them cobblers. That Pi is dedicated to bread boarding circuits so I don't mind the RTC being hoked up with jumpers.

The other DS3231 is soldered to a Proto Hat. The proto hat is plugged into the GPIO header of my Pi and has a sense hat on top of it. An Astro Pi I guess. https://www.adafruit.com/products/2310 I used a stacking header instead of the one that comes with it.

Both solutions I'm trying to avoid as most of my Pis with RTCs get moved around quite a bit. One, for instance, is my "travel alarm".

2. Not a "just plug it in and use it". Indeed...note that it is using a 40-pin MALE header, so not compatible with anything other than a Pi Zero on which one has installed a female header, and the marked connections on the end of the board that start with 5V then ground aren't compatible with a direct connection to any Pi.

Sorry to nitpick, but I did list what I consider requirements for what I want and this completely misses two of them just at first glance.

So shrink it down to just the size needed to hold everything, switch to a DS3231, give it a female header, and put the pins in an order that matches a Pi and I'd buy at least 3 or 4 of them even at the price this one is offered at.

Look at the pictures more closely, its a stacking header, male on one side female on the other. Or just use a normal female header, assuming the header isn't already soldered in. In which case just clip the excess off with wire cutters. What's the big deal with being a second off a day? And won't it just sync to the correct time when you get an Internet connection? Not meaning to be sarcastic or anything, just honestly wondering?

@WHH If your Pi is left hooked up to the 5V adapter after doing a sudo poweroff, the RTC will still be getting 3V3 on it VCC and the backup battery won't be used. Have you experienced one of these module's backup cell fail?

Lastly, it's safe to leave new ones unused in a drawer. Those clever folk at Maxim designed them so that the backup cell isn't employed until after the DS3231's first I2C communication.

alphanumeric wrote:Look at the pictures more closely, its a stacking header, male on one side female on the other. Or just use a normal female header, assuming the header isn't already soldered in. In which case just clip the excess off with wire cutters. What's the big deal with being a second off a day? And won't it just sync to the correct time when you get an Internet connection? Not meaning to be sarcastic or anything, just honestly wondering?

For the Pis I want the RTCs for, they may stay unpowered for 6 months or more at a time, and when powered up, they won't have a net connection. A few seconds off, I'd probably agree with you, but we're talking possibly 3 minutes or more and I'd prefer to be closer than that. If there were to be a net connection, I wouldn't bother with an RTC at all.

gregeric wrote:@WHH If your Pi is left hooked up to the 5V adapter after doing a sudo poweroff, the RTC will still be getting 3V3 on it VCC and the backup battery won't be used. Have you experienced one of these module's backup cell fail?

Define "fail". I've had previously unused units fail to work properly (set one up, set the time, unplug to check, wait a few minutes, add power...and time is at unpowered default). So I suppose you could call that a "failure". Once connected to a Pi with power, set and left running, it will keep time just fine.

Lastly, it's safe to leave new ones unused in a drawer. Those clever folk at Maxim designed them so that the backup cell isn't employed until after the DS3231's first I2C communication.

See above.

What I'm sort of vaguely toying with is the idea of creating a board with a parallel series of 5 pin connectors and a 3.3v supply to plug unused and intermittently used modules onto. I could set the time in the modules and store them with power until I need to go somewhere that I need an RTC, at which point I'd grab one and put it on the Pi that needs it. All of this is why I'd prefer units with replaceable batteries even though I think the idea of using a supercap to maintain the clock is exceedingly clever. I just wish I could find a statement somewhere about discharge and recharge times. I.e. How long can I leave a unit with no external power and expect to have the time correct (to within its accuracy limits) when powered up again, and how long will it take to recharge the cap to the point that the discharge time is valid again. The recharge time *ought* to be fairly short. Minutes? Hours? Can't pull too much power off the 3v3 rail. Discharge time? Months?

Are you still thinking that yellow thing is a supercap? It cannot be - those things require a charging circuit, and there plain isn't one on the module, and certainly not one inside the DS3231. It's a CR1025 lithium primary (no-rechargable) cell, the best for long backup time according to the app note I linked up above. If you want longer backup cell life, fit a bigger cell.

gregeric wrote:Are you still thinking that yellow thing is a supercap? It cannot be - those things require a charging circuit, and there plain isn't one on the module, and certainly not one inside the DS3231. It's a CR1025 lithium primary (no-rechargable) cell, the best for long backup time according to the app note I linked up above. If you want longer backup cell life, fit a bigger cell.

This is a Mini Super Capacitor Real-Time Clock module, designed for the Raspberry Pi. It can be used with an Arduino though!
This accessory plugs on top of your Pi's GPIO pins and contains a clock chip and a super-cap that allows your Raspberry Pi to remember the time!

Aside from not being able to see the underside of the module, it looks identical to the Chinese versions. So, yes, so far as I know, they're using supercaps. I agree that there is no charging circuit. This would be expected with a supercap. All the cap would need is a current limiting resistor. It's rechargeable batteries that need charging circuits.

As soon as Pi Hut has bare Pi Zeros back in, I'll get one of their modules (it's cheap enough) and get a look underneath.