RaspberryPi_with_RTC.jpg

Works Like a Charm!

Yes, I know there are many tutorials on how to configure a real time clock (RTC) module with the Raspberry Pi, but they all seem to be using a commercially-built module. I'm using my homebrewed DS1307-compatible RTC module, built from parts purchased from Philippine-based Alexan Commercial, which includes the VS1307. The VS1307 IC is from Vossel Electronic Design Co. in Beijing, China, which is compatible to the one built by Dallas Semiconductor (as in DS1307). Here is the Fritzing drawing of how I connected my homebrewed RTC module with my Raspberry Pi:

DS1307_RPI.jpg

The Configuration

Since I'm focused on simplicity, rather than the otherwise, here is my quick way of getting it right the first time around. This configuration presumes you have an operational RTC module and it is set to the correct time. Enter the following commands:

  1. $ sudo apt-get update
  2. $ sudo apt-get install i2c-tools
  3. $ sudo nano /etc/modules

modules.jpg

Enter i2c-bcm2708, i2c-dev, and rtc-ds1307 modules as shown in the picture. Next, do a WriteOut and Exit.

  • $ sudo shutdown -r now

After rebooting, log back in. Enter the following commands:

i2c_routines.jpg

  1. $ ls_mod | grep c_
  2. $ sudo su -
  3. # i2cdetect -y 1
  4. # echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
  5. # hwclock -r

These commands will only be successful if the wiring is done correctly (check continuity) and verify the RTC module is working as it should. Keeping that in mind, configuring the RTC module for other SD Card configurations will be a no-brainer. Visit hwclock man page to know how to use the hwclock function. If my method doesn't work for you, here are your other options:

Why I Chose This Method

As you probably notice, I prefer simple methods. When working with verified kernel modules, I prefer having kernel modules load during a reboot rather than doing the modprobe method that are seen in other tutorials. (Reminder: That's only my preference.) The method above will soon be attached to my default Raspbian "Wheezy" building script; that's the basis for many, if not most of my Raspberry Pi-based projects. Since I don't plan on having my RTC module permanently attached to my Raspberry Pi, I decided not to automate the reading and setting routines. For those that don't already know, I have been working with the Linux operating system for almost 16 years. Yes, time flies by too quickly!

Thanks for Reading!

Normally, I don't make tutorials (since other people are already doing that), but when I make something close to a tutorial, it's mostly for skilled persons. That's why I don't explain what a command does to accomplish a task (usually the topic of the post) at hand. Other than simplicity, I also focus on getting the task at hand, done as quickly as possible. Typically, one combo-step of mine is usually an advanced-bypass method of mine. (If it works, move on!) Other than that, thanks for reading my latest blog entry and have a nice day!

 

Marcos "Kuya Marc" Miranda