The BMP085 and BMP180 are no longer made, please check out the BMP280 - we have Python code examples here
Using the BMP sensor with a Raspberry Pi or Beaglebone Black is easy with the Adafruit Python BMP sensor library. First make sure your device is powered on and has access to the internet (through a wired or wireless connection). Then connect to your device in a terminal and navigate to a directory where you want to download the library (like /home/pi on a Raspberry Pi or /root on a Beaglebone Black). Finally execute the following commands to download dependencies and install the library:
sudo apt-get update
sudo apt-get install git build-essential python-dev python-smbus
git clone
cd Adafruit_Python_BMP
sudo python install
If you already have git or python-smbus installed you can ignore the message about the package already being installed.

Once the library is installed it will be accessible to any Python script on your device. You can see a few example scripts included in the library source's examples folder. Try running the example which grabs a single reading from the BMP sensor and displays it by executing:
cd examples
sudo python
If you receive an error message, carefully check that the library was installed correctly in the previous steps and try again. Note that the command needs to be run as root with sudo so that it can access the hardware's I2C bus.

After running the script you should see an output such as:
Temp = 20.20 *C
Pressure = 101667.00 Pa
Altitude = -28.27 m
Sealevel Pressure = 101665.00 Pa

Open the code in a text editor to see how to use the library to read the BMP sensor. First the library is imported with this command:

import Adafruit_BMP.BMP085 as BMP085
Next a BMP085 sensor instance is created with this command:
# Default constructor will pick a default I2C bus.
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
# from the main GPIO header and the library will figure out the bus number based
# on the Pi's revision.
# For the Beaglebone Black the library will assume bus 1 by default, which is
# exposed with SCL = P9_19 and SDA = P9_20.
sensor = BMP085.BMP085()

# Optionally you can override the bus number:
#sensor = BMP085.BMP085(busnum=2)

# You can also optionally change the BMP085 mode to one of BMP085_ULTRALOWPOWER, 
# datasheet for more details on the meanings of each mode (accuracy and power
# consumption are primarily the differences).  The default mode is STANDARD.
#sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)

You can see from the comments there are a few ways to create the sensor instance. By default if you pass no parameters the library will try to find the right I2C bus for your device. For a Raspberry Pi the library will detect the revision number and use the appropriate bus (0 or 1). For a Beaglebone Black there are multiple I2C buses so the library defaults to bus 1, which is exposed with pin P9_19 as SCL clock and P9_20 as SDA data. You can explicitly set the bus number by passing it in the busnum parameter.

Note if you're using a BeagleBone Black with the Ubuntu operating system you might need to change busnum to 2 to use the P9_19 & P9_20 pin I2C connection.  Just change the line to look like: sensor = BMP.BMP085(busnum=2)

The library will also choose by default to use the BMP sensor's standard operation mode. You can override this by passing a mode parameter with an explicit mode value--check the BMP datasheet for more information on its modes.

Once the BMP sensor instance is created, you can read its values by calling the read_temperature, read_pressure, read_altitude, and read_sealevel_pressure functions like below:

print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature())
print 'Pressure = {0:0.2f} Pa'.format(sensor.read_pressure())
print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude())
print 'Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure())
That's all you need to do to read BMP sensor values using the Adafruit Python BMP library!

For another example of using the BMP library, check out the example. This code is similar to the DHT sensor Google Docs spreadsheet logging code, but is modified to use the BMP sensor and write the temperature, pressure, and altitude to a Google Docs spreadsheet. Check out the page on configuring Google Docs to see more details on how to create the spreadsheet and configure the username, password, and spreadsheet name.

This guide was first published on Aug 14, 2012. It was last updated on Aug 14, 2012.

This page (Using the Adafruit BMP Python Library (Updated)) was last updated on Jun 18, 2014.

Text editor powered by tinymce.