Connecting your Raspberry Pi with a real-time clock

Pull-Ups on the I2C Bus

One import thing to consider for your I2C bus are pull-up resistors. The Raspberry Pi has 1.8kohm (1k8) resistors already attached to the SDA and SCL lines, so you really shouldn't need any additional pull-up resistors. However, you do need to look at your I2C boards to find out whether they have pull-up resistors. If you have too many devices on the I2C bus with their own pull-ups, your bus will stop working. The rule of thumb from Phillips is not to let the total pull-up resistors in parallel be less than 1kohms (1k0).

Setting Up the I2C Bus on the Raspberry Pi

The DS1307 RTC board uses the I2C bus to talk to the Raspberry Pi. Before you can use the I2C bus, you will need to set it up.

I'll assume you are using the Raspbian Wheezy distribution – the process for other systems is similar. The I2C drivers are already installed, but they are disabled by default. To enable the drivers, you need to edit the raspi-blacklist.conf file,

sudo nano /etc/modprobe.d/raspi-blacklist.conf

add a hash mark (#) in front of the following line to comment it out,

#blacklist i2c-bcm

and add:

blacklist snd_soc_wm8804  # this removes i2c address 0x3B

Next, edit the modules file,

sudo nano /etc/modules

and add i2c-dev to a new line.

Next, you need to install the Python development software:

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

After the reboot, test to see if the I2C software is working (see Listing 1).

Listing 1

Detecting the I2C Bus

01 sudo i2cdetect -y 1
02
03      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
04 00:          -- -- -- -- -- -- -- -- -- -- -- -- --
05 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
06 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
07 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
08 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
09 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
11 70: -- -- -- -- -- -- -- --

As you can see in Listing 1, the DS1307 was already installed, and it showed up at address 0x68 as expected.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content