itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields

 
COVID19-SARS2 service info ==> we are 100% up and running!

Order here our IoT product(s) of the week.

RaspberryPI BME280 / BMP280 sensor how to

 

 

About this tutorial

This tutorial address Raspberry PI 4, 3B+, 3B, 3A+, II, B, Zero and Zero W hardware and software integration with s-Sense itbrainpower.net BME280 temperature, humidity and pressure I2C sensor or s-Sense itbrainpower.net BMP280 temperature and pressure I2C sensor.

This BME280 / BMP280 software was tested on Linux Debian using Python 2.7 with python-smbus2 module loaded.

 

 

 

About BME280 - temperature, humidity and pressure sensor / BMP280 - temperature and pressure sensor


Bosch BME280 it's a digital humidity, pressure and temperature sensor. Main measurement characteristics:
- ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
- humidity accuracy +-3%
- absolute temperature (0-65C) accuracy +-1C
- absolute/relative pressure accuracy +-0.6hPa/+-0.12hPa
More info on: BME280 datasheet

Bosch BME280 it's a digital sensor for temperature and pressure. Main measurement characteristics:
- ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
- absolute temperature (0-65C) accuracy +-1C
- absolute/relative pressure accuracy +-0.6hPa/+-0.12hPa
More info on: BMP280 datasheet

In June 2019 we've realeased 6 new environmental and air quality sensors, including BME280 I2C sensor breakout and BMP280 I2C combo sensors breakout, all being part of the s-Sense I2C sensor breakout family.


HINT: Do not be confused! BMP280 sensor (temperature+pressure - no humidity!) and BMP280 sensor (temperature+pressure+humidity) seems to be similar, but: the first one is a little bit smaller and on s-Sense PCB bottom you will find the sensor type marking (see the pictures bellow).


s-Sense BME280 sensor breakout by itbrainpower.net

BME280 sensor breakout - topBME280 sensor breakout - bottom

PN: SS-BME280#I2C   SKU: ITBP-6002   BME280 I2C sensor breakout info

s-Sense BME280 sensor breakout by itbrainpower.net

BMP280 sensor breakout - topBMP280 sensor breakout - bottom

PN: SS-BMP280#I2C   SKU: ITBP-6001   BMP280 I2C sensor breakout info

Next, let's kickstart with BME280 sensor I2C breakout / BMP280 sensor I2C breakout - around 15-20 minutes.

 

 

 

RaspberryPI [Debian based Linux] setup, preamble software and hardware preparation


A. Enable I2C channel 1 on Raspberry PI
  a. sudo raspi-config
       menu F5 => select enable I2C option
       save, exit.
    sudo reboot now

  b. edit /boot/config.txt and add/enable following directives:
      dtparam=i2c_arm=on
      dtparam=i2c_arm_baudrate=10000
    save, then reboot RPI

B. Check i2c is loaded: ls /dev/*i2c*. This command should list something like: /dev/i2c-1

C. Check sensor I2C communication [BME280 / BMP280 should be connected, see wiring in next chapter]. Run: i2cdetect -y 1. In command output you should see listed the s-Sense BME280 or s-Sense BMP280 I2C default address 0x76.

D. Install required python packages
  a. sudo apt-get install python-setuptools
  b. wget https://files.pythonhosted.org/packages/6a/06/80a6928e5cbfd40c77c08e06ae9975c2a50109586ce66435bd8166ce6bb3/smbus2-0.3.0.tar.gz *
  c. Expand downloaded tar.gz archive. tar -xf smbus2-0.3.0.tar.gz will do the job.
  d. chdir smbus2-0.3.0
  e. sudo python setup.py install

  * python-smbus2 package is also available here: https://itbrainpower.net/downloadables/smbus2-0.3.0.tar.gz

 

 

 

RaspberryPI BME280 / BMP280 sensor hardware integration (basic wiring)


s-Sense by itbrainpower.net BME280 sensor and s-Sense by itbrainpower.net BMP280 sensor are compatible with all Raspberry PI versions!

Next, all wiring directives are exemplified for Raspberry PI 4, 3B+, 3B, 3A+, II, B, Zero and Zero W. GPIO naming convention used in wiring description and in software is "GPIO pin number" - GPIO.setmode(GPIO.BOARD). In a nut shell, wire as bellow:

BME280 / BMP280 breakout RaspberryPI GPIO pin number RaspberryPI pin role
Vin PAD GPIO pin no. 01 * RPi 3.3V *
Vdd PAD (3V3) do not connect do not connect
SDA PAD GPIO pin no. 03 SDA
SCL PAD GPIO pin no. 05 SCL
GND PAD GPIO pin no. 09 GND
 

*         sensor power in     --> in order to spare Rpi 3V3 power, read how to power the I2C sensor from RasberryPI 5V pin, but having I2C reference at 3.3V! DO NOT power the sensor at 5V, until you know exactly what you do! You will damage your RaspberryPI board!


Bellow, basic BME280 / BMP280 sensor wiring to RaspberryPI with safe sensor powering from RaspberryPI 3.3V pin :
BME280 or BMP280 sensor breakout RaspberryPI wiring



Python BME280 / BMP280 sensor software


a. download BME280 / BMP280 RaspberryPI Python library from: here.

b. expand tar.gz archive. Go inside new created folder.

c. Copy the code bellow, paste it one new file and save the file as "bmx280_simple.py" in the python library folder download it from here (right click & save as): BME280 / BMP280 - RaspberryPI read sensor data Python code

1"""
2s-Sense BME280 by itbrainpower.net and s-Sense BME280 by itbrainpower.net I2C sensors breakout example - v1.0/20200218. 
3
4Compatible with:
5                s-Sense BME280 I2C temperature, pressure and humidity sensor breakout [PN: SS-BME280#I2C, SKU: ITBP-6002], info https://itbrainpower.net/sensors/BME280-TEMPERATURE-HUMIDITY-PRESSURE-I2C-sensor-breakout 
6                s-Sense BMP280 I2C temperature and pressure sensor breakout [PN: SS-BMP280#I2C, SKU: ITBP-6001], info https://itbrainpower.net/sensors/BMP280-TEMPERATURE-PRESSURE-I2C-sensor-breakout 
7  all Raspberry PI, using Python 2.7
8
9Reading temperature, pressure [and humidity - only for BME6280] values example (pulling at 2sec) - based on Arduino BME280 library, 2016 version, written by Tyler Glenn.
10Thank you Tyler! Great job! 
11 
12We've ported Tyler functions into python, patch them, add some variables, functions and functionalities.                
13
14
15Mandatory wiring [bellow for RPi B/B+/II/3B/3B+/4/Zero/Zero W]:
16        - sensor Vin            <------> RPI pin 1 [3V3 power] *
17        - sensor I2C SDA        <------> RPI pin 3 [i2c-1 SDA]
18        - sensor I2C SCL        <------> RPI pin 5 [i2c-1 SCL]
19        - sensor GND            <------> RPI pin 9 [GND]
20
21Wiring notes:
22        *    to spare 3V3 power - read about RPI I2C sensors 5V powering
23
24WIRING WARNING:
25        Wrong wiring may damage your RaspberryPI or your sensor! Double check what you've done.
26
27
28BME280 / BMP280 definitions are placed in bmx280_param.py
29
30
31Bellow, how to set-up i2c on RPi and install requiered python packages and other utilities.
32
33Enable I2C channel 1
34        a. sudo raspi-config
35                menu F5  =>  enable I2C
36                save, exit and reboot.
37        
38        
39        b. edit /boot/config.txt and add/enable following directives:
40               dtparam=i2c_arm=on
41               dtparam=i2c_arm_baudrate=10000
42
43           save and reboot.
44
45Check i2c is loaded:
46        run: ls /dev/*i2c*
47        should return: /dev/i2c-1
48
49Add i2c-tools packages:
50        sudo apt-get install -y i2c-tools
51
52Check sensor I2C connection:
53        run: i2cdetect -y 1
54        you should see listed the s-Sense BME280 / BMP280 I2C address [0x76]
55
56Install additional python packages:
57        a. sudo apt-get install python-setuptools
58        b. wget https://files.pythonhosted.org/packages/6a/06/80a6928e5cbfd40c77c08e06ae9975c2a50109586ce66435bd8166ce6bb3/smbus2-0.3.0.tar.gz
59        c. expand archive
60        d. chdir smbus2-0.3.0
61        e. sudo python setup.py install
62
63
64You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH s-Sense BME280 or s-Sense BMP280 I2C sensors DEVICES USAGE. Modifications, derivates and
65redistribution of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms 
66of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
67
68This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
69or FITNESS FOR A PARTICULAR PURPOSE.
70
71
72itbrainpower.net invests significant time in design phase of our IoT products and in associated software and support resources.
73Support us by purchasing our environmental and air quality sensors from here https://itbrainpower.net/order#s-Sense
74
75
76Dragos Iosub, Bucharest 2020.
77https://itbrainpower.net
78"""
79
80from time import sleep
81from bmx280 import *
82
83
84#default settings       =>      BMx280_OSR_X1, BMx280_OSR_X1, BMx280_OSR_X1, BMx280_Mode_Forced, BMx280_StandbyTime_1000ms, BMx280_Filter_Off
85bmx280Begin()                                                                   #start BMx280 w. default settings
86
87
88#bmx280Begin()                                                                   #start BMx280 w. default settings
89#bmx280SetSettings(_humOSR, _tempOSR, _presOSR, _mode, _standbyTime, _filter)    #set specific settings
90
91while(1):
92        bmx280ReadData()
93        temperature = bmx280GetTemperature()
94        pressure = bmx280GetPressure()
95        print "Temperature: %.2f C" %temperature
96        print "Pressure: %.2f Pascals" %pressure
97
98        sensorType = bmx280GetSensorType()
99        if(sensorType == DevID_BME280):
100        #if(1):
101                humidity = bmx280GetHumidity()
102                print "Relative Humidity : %.2f %%" %humidity 
103        sleep(2)
104


c'. Above code it's included in BME280 / BMP280 RaspberryPI Python library package.

d. Check BME280 / BMP280 params in "bmx280_param.py" file. Run BME280 / BMP280 code with command "python bmx280_simple.py".


HINTS:
- if you update the code inside "bmx280_param.py" file, before run it, just run "./clean" utility in order to delete Python precompiled files.
- in order to convert measurement units, calculate altitude and more, use s-Sense air quality utils python library.


Enjoy!


TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

 

 

 

 

 

 

Original how to written by Dragos Iosub & itbrainpower.net team

 

 

 

 

document version 1.031 / 2020-04-09 © R&D Software Solutions srl