Setting up and Real Time Clock (RTC) on a Raspberry Pi

Daniel Ellis Research
3 min readSep 25, 2022

A simple guide on how to add a timekeeping module to the PI using its I2C ports. NOTE this tutorial is for current release Raspberry Pi OS’s.

Photo by Aron Visuals on Unsplash

1 — Insert the Module

Most Pi compatible RTCs just slot directly onto the GPIO pins. If it is a 2x3 RTC, just plug it in at the very top, similarly with a 1x5 (plug it in on the left rail). Should you have a clock with individual headers, the communication ones go onto the 2nd and 3rd pins on the left rail from the top and the others to a 3/5V pin and a ground.

Source https://cdn.shopify.com/s/files/1/0174/1800/products/3386_1024x1024.jpg?v=1539264393

2 — Determine the Port

We can use the i2cdetect function to determine the id of our real time clock chip.

sudo i2cdetect -y 10  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

If we have UU the device is connected, but most likely you inserted the battery the wrong way around.

5- Setting up RPi

Boot config

We now configure the startup procedure of the pi.

sudo nano /boot/config.txt

And either insert the following or append to the existing dtoverlay command with a comma.

dtoverlay=i2c-rtc,ds1307ordtoverlay=i2c-rtc,pcf8523ordtoverlay=i2c-rtc,ds3231ordtoverlay=i2c-rtc,pcf2127

ctrl+x to exit and save.

If you do not want this, you can always load it manually e.g. by running

dtoverlay i2c-rtc pcf8523=true
Daniel Ellis Research

Research Software Engineer specialising in High-Performance Computing and Data Visualisation. — PhD in Atmospheric Chemistry and Masters in Theoretical Physics.