This tutorial will show you how to wire and program the BeagleBone Black (BBB) to use SparkFun’s Digital Temperature Sensor BreakoutBoard (TMP102) over I2C. Many thanks to this Arduino example for the inspiration!
First, you might want to see my BBB I2C references if you haven’t used I2C before. It’s simply a two-wire interface that requires SDA and SCL. But you will also need a Vcc wire and a GND (data only communicates on two wires…). Now the TMP102 breakout board is very good at measuring ambient temperature and it’s very sensitive to small changes around it; if I put my hand next to it I can see the temperature rise.
It’s also very simple, so it’s a good, cheap device to get started with I2C. I have my BBB setup to run Debian, but this should work with any distribution.
This wiring example will be using the BBB’s I2C2 bus, which may be reported under linux as i2c-1 (again see my BBB I2C references). This bus uses pins P9_19 and P9_20.
P9_19 -> SLC
P9_20 -> SDA
P9_3 -> VCC 3.3V
P8_2 -> GND
The code is available on GitHub. It’s set up to build on the BeagleBone. So, you need to
apt-get install build-essential. (It should cross compile. Feel free to try it and let me know :p )
Once the code is built, you’ll need to run it as root (unless you’ve added your user to the i2c group). It will loop forever until you
debian@arm:~/repos/tmp102$ sudo ./tmp102 Temp Fahrenheit: 70.250000 Celsius: 21.250000 Temp Fahrenheit: 70.250000 Celsius: 21.250000 Temp Fahrenheit: 70.250000 Celsius: 21.250000 Temp Fahrenheit: 71.037498 Celsius: 21.687500 Temp Fahrenheit: 70.587502 Celsius: 21.437500 Temp Fahrenheit: 70.699997 Celsius: 21.500000 Temp Fahrenheit: 70.699997 Celsius: 21.500000 Temp Fahrenheit: 70.812500 Celsius: 21.562500
I picked up the USB Logic Analyzer from SparkFun as well and now I can see the raw signals on the bus. After the read command, one can see the two bytes returned as the digital temperature.