I have added an RTC to the I2C bus of the Raspberry Pi. If I follow the steps mentioned here (I am using the DS1307 RTC IC), I can run hwclock and read the time.

root@raspberrypi:~# modprobe rtc-ds1307
root@raspberrypi:~# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

Once, I run this, I cannot access the RTC from my python script any more. However, I have to do this at each boot. Is there a way I can specify my RTC address on the I2C so than the system recognizes it at boot time?

  • Did my answer help?
    – Munkeh
    Dec 20, 2012 at 17:02

2 Answers 2


Add the commands to /etc/rc.local for the module to be loaded on each boot.

Depending on your distrobution, the path to rc.local may vary. On Arch ARM it is /etc/rc.d/rc.local

You may want to add an echo command before the module is loaded for some visual feedback, for example:


echo Loading RTC module
modprobe rtc-ds1307
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
echo Done

Keep in mind that rc.local runs last - after all other init scripts have run, so if you have anything else at boot that depends on the hwclock being set, be sure to run those after rc.local has run, ideally append it after the last echo command above.

If you really need to have the hwclock set earlier, you'll need to edit one of the init scripts in /etc/rc.d (or wherever they are located on your distro) to load your module and echo commands.


Not really an answer, but too long for a comment, and I will point it to the answer if/when I find one... Have spent hours on this today.

The OP approach appears to be obsolete due to this change : https://www.raspberrypi.org/forums/viewtopic.php?t=97314 which means that a large amount of advice on forums about the RTC doesn't apply any more.

I've been able to get 'hwclock' working by enabling I2C and drivers using raspi-config (turn on I2C and drivers, in 'advanced settings') and then add dtoverlay=i2c-rtc,ds1307 to the bottom of /boot/config.txt

So great, hwclock appears to then work and read and write the clock. But you then need to make changes so that 'fake-hwclock' is removed and replaced by proper reading of the hwclock at startup.

This is a good guide on that - although details for a different RTC. https://www.raspberrypi.org/forums/viewtopic.php?p=842661#p842661

But it doesn't seem to apply to 2015-05-05-raspian-wheezy, the lines to be commented out in /lib/udev/hwclock-set are not there. For me, by the time /etc/rc.local is executed, one of the existing startup scripts has already corrupted the RTC somehow.

This is the kind of issue that conventional forums are really bad for - there's lots of good advice that applied in 2012, and then a long series of ifs and buts and you may collect the updated truth eventually. I can't find a direct question to this issue - how to install an RTC for raspian - on this SE, so I'll ask it, and end up pointing this there.

UPDATE: See How to install Real Time Clock (RTC) on Raspbian?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.