Sunday, April 28, 2013

Reading Temperature from a TMP102 Thermometer with pcDuino (Python Version)

The TMP102 temperature sensor breakout from Sparkfun is an easy to use thermometer that connects via I2C.   This quick example shows how to use a TMP102 with a pcDuino and some simple Python 2 code to get the current temperature.


Run the following commands to install required packages:

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


TMP102  pcDuino
V+      3.3V

When connected as above, the TMP102 uses the I2C address 0x48. To confirm this, run the following at the command line:

  i2cdetect -y 2

The resulting diagram should show the device at 0x48 by printing 48 in the corresponding cell.

Note that the SCL and SDA pins on the pcDuino are connected to I2C bus 2.

The TMP102 breakout board has built-in 1k pull-up resistors on the SDA and SCL lines; it works without external pull-up resistors.


import smbus
import time

bus = smbus.SMBus(2)
data = bus.read_i2c_block_data(0x48, 0)
msb = data[0]
lsb = data[1]
# Print degrees Celsius
print (((msb << 8) | lsb) >> 4) * 0.0625


  1. Replies
    1. Hi Ahmet -

      I'm glad you found it useful.


  2. Very usefull tutorial. We forward your post to If you have any other new post about pcDuino( or any other LinkSprite's( products, please feel free to let us know. If you have a new post, could you please give us a backlink?

  3. Getting ready to start an RPi project using TMP102s. Couple of quick questions:

    1 - Why did you go from Pi to Duino to TMP102 instead of Pi to TMP102? Was it just for hack purposes or were you having issues with Pi to TMP102?

    2 - with the TMP102 components, rather than a breakout board, do you think I could build a H2O-proof sensor with the '102 inside some sort of stainless or copper tube?


    1. Hi Justin -

      I was just fiddling around with different boards. I've tried the TMP102 breakout from Sparkfun with a number of different boards and it has worked well with all of them. (Well, actually I'm having trouble getting the TMP102 to work hooked up to the um-FPU64 coprocessor, but that is almost certainly my programming, not the component!)

      I've only used it to measure air temperature. Take a look at page 5 of the datasheet ( where they mention the thermal paths for the chip itself.

  4. This comment has been removed by a blog administrator.