Connecting a TMP102 to a Raspberry Pi via i2ci

Julian asks:

How do I connect the SparkFun “Digital Temperature Sensor Breakout - TMP102” to a Raspberry Pi?

Thanks for your question Julian!

The TMP102 is a digital temperature sensor that reports it’s temperature readings via I2C (pronounced I-squared-C).

Per Wikipedia:

I2C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers. Alternatively I²C is spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).

The TMP102 is a great fit for the Raspberry Pi, as the Pi lacks the analogue to digital converter you need for resistive temperature sensors. Also, when compared to the cheap and cheerful analog temperature sensors (such as a thermistor) the TMP102 has a far better accuracy, capable of measuring temperature changes in 0.0625ºC steps between -25°C and +85°C.

By default, the TMP102’s I2C address will be 72(0×48 in hex) when the address pin (ADD0) is grounded or 73 (0×49 in hex) when the address pin is tied to the VCC (see the picture below).

Enabling I2C on Raspberry Pi

To enable I2C on the Raspberry Pi (running Raspbian), run the sudo raspi-config command.

Now complete the following steps :

Select: 8 Advanced Options
Select: A7 I2C
Select: Yes

The screen will ask if you want the interface to be enabled :

Select: Yes
Select: Ok

The screen will ask if you want the module to be loaded by default :

Select: Yes

The screen will state the module will be loaded by default :

Select: Ok
Select Finish to return to the command line

When you next reboot your Raspberry Pi, the I2C module will be loaded.

Installing I2C packages

To use the TMP102 on the Pi you’ll need to install some I2C packages.

Update raspbian with:

sudo apt-get update;
sudo apt-get upgrade;

Install the I2C tools with:

sudo apt-get install i2c-tools;
sudo apt-get install python-smbus;

Hooking the TMP102 up to your Pi

Connect the TMP102 up to your Raspberry Pi as follows:

RPi GPI0        Breakout
---------------------------
Pin 2            SDA
Pin 3            SCL
Pin 26           5V  

Looking for the TMP102

You’ll now need to run i2cdetect to see if your TMP102 is connected.

If you’ve got a Model A, B Rev 2 or B+ Pi then type the following command :

sudo i2cdetect -y 1

If you’ve got an original Model B Rev 1 Pi then type the following command :

sudo i2cdetect -y 0

The reason for the different flags is because the Raspberry Pi foundation changed the signals that went to Pin 3 and 5 on the GPIO header when they designed the second revision of the Raspberry Pi. In doing so they changed the device number needed for I2C from 0 to 1.

If your TMP102 is connected correctly you’ll see:

  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --