Using the BMP280 Temp/Press Sensor on the Raspberry Pi

I recently discovered that the BMP180 sensor has been discontinued, which is kind of a bummer.  I always found it to be a good little sensor for temperature and pressure.  So I picked up its replacement, and I found that I didn’t have a lot of good directions on making it work.  So, I pieced a few things together, and it seems to work.  These instructions will take you through it.


Enable I2C

You will need to turn on I2C for the Raspberry Pi if you haven’t already.  I am working with a July-2017 release of Raspian-Pixel with a desktop.  Previously, you could do this through raspi-config, but that doesn’t seem to be the case any more.  I found the easiest way to do this was through the actual desktop.  Everything else we do can be done through an SSH connection.

Simply click on the Start Menu and to Preferences and Raspberry Pi Configuration.

Enable SPI and I2C.  Also, you may want to enable SSH, so you can use a program like Putty to control the Pi. Click OK.  Then reboot, for the changes to go through.

Connect the Sensor

When you buy the BMP280 sensor, it comes with some pins that you will need to solder on.  There are six pins but you will only make 4 connections.  The connections are below.

BMP280 Raspberry Pi
VIN Pin 1 (3.3V)
Ground Pin 6
SCK Pin 5 (SCL1)
SDI Pin 3 (SDA1)

Test the Sensor

If you have connected the sensor, and everything is working you should be able to detect it.  Use the command below, and you will see this result.

sudo i2cdetect -y 1

Load the Libraries

This is where I ran into some problems.  There were no libraries specifically for the BMP280 that I could find.  There is, however, a BME sensor sold by Adafruit and it comes with a humidity sensor.  It turns out that the BME library will work for this sensor.  Yeah!

From your home directory

apt-get install build-essential python-pip python-dev python-smbus git
git clone

In the folder that was just created

sudo python install
git clone

Everything is loaded now.  From the Adafruit_Python_BME280 folder run the example file.

python ./

You should see the temperature, pressure, and humidity (which will be 0).

The python code for that file is below:

from Adafruit_BME280 import *

sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)

degrees = sensor.read_temperature()
pascals = sensor.read_pressure()
hectopascals = pascals / 100
humidity = sensor.read_humidity()

print 'Temp      = {0:0.3f} deg C'.format(degrees)
print 'Pressure  = {0:0.2f} hPa'.format(hectopascals)
print 'Humidity  = {0:0.2f} %'.format(humidity)

With this, you can make all kinds of changes, like uploading to Thingspeak, Google Sheets, or making a CSV file. Happy sensing!

UPDATE:  If you are interested in making an online dashboard for the output from this sensor, check out my other tutorial here.  It uses Highcharts and MySQL.

Leave a Reply

Your email address will not be published. Required fields are marked *