Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Howto: jessie, RTC, hwclock

Tue Nov 03, 2015 11:05 am

I hope there is room here for yet another RTC thread, this one should get it right from the start - typos excepted!

The method used is different under raspbian jessie to that used with wheezy

I was lucky enough to stumble across early in my searches and it provided me with the final clues I needed.

Your RTC module may have come with instructions, if so read them but bear in mind it is possible they were written for installation under wheezy as jessie is quite new to the official raspbian release.

NB. Where you need to alter files it is always a good idea to save the original as a backup with a command similar to this

Code: Select all

sudo cp /etc/default/hwclock /etc/default/hwclock.BAK
First we need to enable i2c. Do this from raspi-config, see ... if you don't know how.

At the end of this step, instead of rebooting now select later.

Now take a look at /boot/overlays/README, scroll to the i2c-rtc section, find your RTC and make a note of the parameter required.

Code: Select all

less /boot/overlays/README
may be useful, scroll keys to navigate, q to quit.

My RTC is a ds1307 so its parameter is ds1307 so I need to add dtoverlay=i2c-rtc,ds1307 to config.txt, yours will likely require a different parameter but the syntax is the same (see ... if you are not sure how to edit this file).
Once edited, save the file and exit your editor.
See ... for dtoverlays docs.

To make sure relevant modules are loaded at boot time we will now look at /etc/modules. I suggest doing this with

Code: Select all

sudo nano /etc/modules
You may see some modules listed already, leave them but you need
i2c-dev, i2c-bcm2708 and the relevant module for your RTC, the module for mine is rtc-ds1307 so I add rtc-ds1307 yours may be different, add it on a new line and make sure you have an empty line at the end of your new added lines. (nano keys are at the bottom of the editor, Crtl-x to exit, y to save.)

Now reboot. Hopefully all will come back with no nasty messages.

Install i2c-tools

Code: Select all

sudo apt-get install i2c-tools

and whilst we are here purge fake-hwclock

Code: Select all

sudo dpkg --purge fake-hwclock

Note that I have struck out the above line as it seems that if fake-hwclock is removed then 1 Jan 1970 timestamps will appear in /var/logs/syslog early in the boot sequence - try it and see :)

Now we'll check that the RTC is available with

Code: Select all

sudo i2cdetect -y 1
You should see output similar to

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 
Note that I have UU in position 68, this is my RTC device and it is in use. You may see 68 instead. All being well you have something in this position.

We can now edit /lib/udev/hwclock-set with

Code: Select all

sudo nano /lib/udev/hwclock-set
locate the lines and edit

Code: Select all

if [ -e /run/systemd/system ] ; then
    exit 0
so that section looks like

Code: Select all

#if [ -e /run/systemd/system ] ; then
#    exit 0
Important note:
The first mentioned link also suggests that you comment out the closely following two lines containing --systz
There is a link to a bug-list thread to justify this ... bug=764552 , however, if you scroll almost to the bottom of that same page it seems that these two lines are required - particularly if you are running ntp as I do.
My RTC is running fine with them in, others have theirs running fine with them commented out. Take your pick and see if all is working as it should ;)


Code: Select all

should show you the current time.

Code: Select all

sudo hwclock -w
writes the system time to your RTC

Code: Select all

sudo hwclock -r
reads it back - it should be much the same as from the date command.

Code: Select all

sudo hwclock -s
writes RTC back to system time. (There are variations on these commands but the OS should take of everything once we are at this stage).

You may edit/etc/default/hwclock however the defaults here should just work.

Reboot and check /var/log/syslog.
If all is working as it should you will now see correct timestamps after the system restarts.
Last edited by fruit-uk on Tue Nov 10, 2015 9:22 pm, edited 2 times in total.

User avatar
Posts: 453
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Howto: jessie, RTC, hwclock

Tue Nov 03, 2015 12:17 pm

Good job! I just got my DS3231 work via your steps.

I haven't do digging into RTC since my nixie tubes dead. Reading this thread, I remount DS3231 from dust to my router Pi, it looks working well.

Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: Howto: jessie, RTC, hwclock

Tue Nov 03, 2015 1:33 pm

Thanks for the feedback, I'm glad it all worked

Posts: 1
Joined: Wed Feb 25, 2015 7:54 am

Re: Howto: jessie, RTC, hwclock

Fri Nov 06, 2015 6:47 pm

Thanks, this got my RTC working again under Jessie. Since my RPi lives somewhere with no Internet access and reboots frequently, I was getting pretty tired of manually setting the clock! I'd managed to figure out everything except for the change to the /lib/udev/hwclock-set script.

User avatar
Posts: 7
Joined: Sun Jan 31, 2016 9:08 pm
Location: Russian Federation

Re: Howto: jessie, RTC, hwclock

Mon Feb 08, 2016 10:12 pm

Все компактно и понятно, а самое главное DS3231 работает. Отличная инструкция, спасибо!
Raspberry Pi 2 Model B

Posts: 1
Joined: Tue Sep 06, 2016 12:17 pm

Re: Howto: jessie, RTC, hwclock

Tue Sep 06, 2016 12:19 pm


thank you, finally, it is working as it should. This was 6th tutorial I tried.

Posts: 41
Joined: Fri Dec 21, 2012 5:27 pm

Re: Howto: jessie, RTC, hwclock

Tue Sep 27, 2016 12:35 pm

Hi, with the latest Jessie, it's now even simpler to get rtc working. I've posted a description on the forum, but in a nutshell, you only need to make two edits to a standard Jessie raspbian or raspbian lite:

1. add the "dtoverlay=i2c-rtc,<chipset>" line in the /boot/config.txt file, as per your description
2. comment out the if-then statement in the /lib/udev/rwclock-set file, as per your description

that's all - nothing else :-)


Return to “Raspberry Pi OS”