After a lot of trial and error, I've figured out how to set up a Raspberry Pi (in my case, I tested with a 2B and 3B+, this may not work on a Pi 4B). This involves using the i2c0 bus (which normally isn't recommended), but this is what I was able to get working as re-mapping would communicate with the RTC via i2c, but the overlay for the RTC wouldn't adjust its configuration when told to use i2c3 or higher.
Required hardware
- Power button (this should be a momentary switch type)
- Power LED (for me, this was actually built into the power button)
- 330K Ohm resistor (this is connected between the LED and the 3.3v header
- A Real Time Clock (RTC) Module (preferably, one with built-in pull up resistors)
- Jumper wires
- Depending on what you're planning, you may need a soldering iron and related tools
Below are the steps to configure the Raspberry Pi OS (the assumption is that you're using Raspberry Pi OS).
-
Install the i2c tools
sudo apt-get update && sudo apt-get install -y i2c-tools
-
Execute
sudo raspi-config nonint do_i2c 0
to enable i2c -
Update your
/boot/config.txt
with the lines from the2-boot-config.txt
file in this gist -
Shutdown your Pi and disconnect power
-
Connect your power button via jumper wires to board pins 5 and 6
-
You will need to attach a 330K Ohm resister to the Anode of your LED between it and the board
-
Connect the anode of the LED to board pin 8 (GPIO pin 14)
-
Connected the cathode of the LED via jumper wire to board pin 14 (ground)
-
Now, you will need to wire up the RTC module
-
Using jumper wires
-
Connect the positive header on the RTC to board pin 1 (3.3v Power)
-
Connect the D header on the RTC to board pin 27 (GPIO pin 0)
-
Connect the C header on the RTC to board pin 28 (GPIO pin 1)
-
Connect the negative header on the RTC to board pin 20 (Ground)
-
Connect power to your pi once again
-
Press your power button, the Pi should now power on
-
Log into your OS and confirm that the RTC is working by running the command
sudo i2cdetect -y 0
, to which you should see output that showsUU
on row 60 column 8. This confirms that your RTC is working and detected properly -
Disable the fake hardware clock by running the following commands
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclock
-
Next up, open
/lib/udev/hwclock-set
in your favorite text editor as root and comment out the following statementsif [ -e /run/systemd/system ] ; then exit 0 fi /sbin/hwclock --rtc=$dev --systz
-
Check the time set on the RTC by running
sudo hwclock -r
-
Once you've verified that it is reading the time from the hardware clock, sync the hardware clock by running
sudo hwclock -w
-
To test that it worked, shutdown your Pi by pressing the power button (wait for the green LED beside the red power LED to stop flashing), then disconnect the network, unplug the power wait a few seconds and re-connect the power
-
Sign into the Pi and run
timedatectl status
to confirm that the date and time were properly set via the RTC module -
That's it!