Saturday, March 2, 2013

Beaglebone & TMP102 Temperature Sensor

The notes and sample below show how to get the Sparkfun TMP102 breakout board working with the Beaglebone. The TMP102 connects to the beaglebone using I2C, and the breakout board includes pull-up resistors on the SDA and SCL lines.

This example is in Python.

The Ångström Linux distribution that comes with the Beaglebone includes the I2C tools (such as i2cdetect). You will, however, need to install the python-smbus module. Be sure to run opkg update first, and then  run the following command to install the python-smbus package: opkg install python-smbus.

Connections:


TMP102 Breakout Beaglebone
V+              P9 Pin 3
SDA             P9 Pin 20
SCL             P9 Pin 19
GND             P9 Pin 1
ADD0            Connect to GND on breadboard for I2C addr. 0x48 

Connecting ADD0 to V+ sets the I2C address to 0x49. Connecting it to SDA sets the board's address to 0x4a and connecting it to SCL results in setting the address to 0x4b. Adjust the code below accordingly.

Code:


# Read temp in degrees C from tmp102 breakout board by Sparkfun
import smbus
import time

# Beaglebone uses I2C bus 3
bus = smbus.SMBus(3)
# Read block of I2C data
data = bus.read_i2c_block_data(0x48, 0)
msb = data[0]
lsb = data[1]
print (((msb << 8) | lsb) >> 4) * 0.0625

No comments:

Post a Comment