Setting up and Real Time Clock (RTC) on a Raspberry Pi
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.
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.
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…