fbpx

CYBRNODE

How To: Configure RTC with Raspberry Pi

The raspberry pi seemingly has everything built right into it. It’s almost the perfect single-board computer. Almost. For some projects, I desperately needed a Real-Time Clock (RTC). So I set out to find an external RTC for my Raspberry Pi. Going in I didn’t know what to expect and with the little knowledge I had about the hardware I attached the RTC with the Raspberry Pi using jumpers (expecting it to work right out of the box, but it didn’t). So here I am writing about my learnings as a rookie hobbyist.

What you’ll need

  1. Raspberry Pi x 1
  2. Real-Time Clock (DS3231) x1
  3. F-F Jumpers x 4

Step 1: Connecting the RTC

Take the jumpers and connect them as shown in the image below.

Step 2: Enabling i2c interface

Turn on the Raspberry Pi and in your terminal type in the following command:

sudo raspi-config

This will open up the Raspberry Pi configuration screen. You now need to go into Interface options > I2C > Enable I2C interface (as shown below)

Step 3: Installing some tools

Connect the Raspberry Pi to the internet (Make sure the Time zone is correct). Run the following commands in your terminal to install i2c-tools:

sudo apt-get update
sudo apt-get install i2c-tools

After successfully installing the i2c-tools you should reboot the Raspberry Pi.

Step 4: Configuring the RTC

We are now ready to rock. Let’s go ahead and run the following command in the terminal:

wget https://raw.githubusercontent.com/km4ack/pi-scripts/master/rtc && bash rtc

This will automagically download and run a script that will guide you through the configuration process. This script has been written by KM4ACK. Thank you for making our lives easier! Below is a step by step guide by KM4ACK, you can check it out.

Step 5: Did it work?

Here’s how you can check to see if everything is working as required. Type in the following to see the time in the RTC:

sudo hwclock -r

Then type in the following to see the current system time:
date
You’ll see that the time is relatively close, the only difference is the time it took to type in and fetch the values.

We are Done! ?

That’s it, you now have a functional clock for your next project. Use it well my fellow Makers.

Happy Building!