Raspberry Pi temperature sensor using TMP102

The TMP102 is an I2C temperature sensor from Texas Instruments.It's a perfect sensor for Raspberry Pi as it lacks any onboard ADC and TMP102 eliminates the requirement for analyzing the analog signals.When compared with the analog sensors TMP102 is very accurate and capable of measuring 0.0625ºC changes between -25°C and +85°C.

TMP102 pinout

If you have more than one device on the I2C bus you can modify the address of the sensor using the address pin (ADD0).The sensor's address will be 72(0×48 in hex) when the address pin is grounded.It will be set to 73 (0×49 in hex) if the address pin is tied to VCC.

Pi GPI0        Function
---------------------------
Pin 2            SDA
Pin 3            SCL
Pin 26          5V  

Make sure your system has the latest version of Linux 3.2 kernel and a proper I2C driver.Also you will be requiring two utilities:-
1) "lm-sensors" package, enter "apt-get install lm-sensors"
2) "I2C tools" package, enter "apt-get install i2c-tools"

After installation we can now use the modprobe i2c-tools.Run "i2cdetect" to check whether TMP102 is connected.

root@raspberrypi:~# i2cdetect -y 0

     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: -- -- -- -- -- -- -- --


As we have received the address from i2cdetect, the system has to be updated to get new drivers.

rahul@raspberrypi:~# echo tmp102 0x48 > /sys/class/i2c-adapter/i2c-0/new_device

Run the "sensors" command to get the temperature:-

rahul@raspberrypi:~# sensors
tmp102-i2c-0-48
Adapter: bcm2708_i2c.0
temp1:        +35.7°C  (high = +70.0°C, hyst = +55.0°C)



(Update):- If you have a Raspberry Pi with a revision 2.0 board, you need to use I²C bus 1, not bus 0.You can check that the device is present on the bus by using the i2cdetect program from the i2ctools package:-

i2cdetect 0 -y  or i2cdetect 1 -y 

0 comments