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 BME680 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 BME680 temperature, humidity, pressure and gas I2C sensor or s-Sense itbrainpower.net BMP280 temperature and pressure I2C sensor.

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

 

 

 

About BME680 - temperature, humidity, pressure and gas sensor


Bosch BME680 it's 4-in-1 sensor with gas, humidity, pressure and temperature measurement based on proven sensing principles and having very low power consumption. Main measurement characteristics:
- ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
- resolution of gas sensor resistance measurement 0.05-0.11%
- bVOC tolerance/certified accuracy 10-20% / 2-5%
- humidity accuracy +-3%
- absolute temperature (0-65C) accuracy +-1C
- absolute/relative pressure accuracy +-0.6hPa/+-0.12hPa

More info on: BME680 datasheet

s-Sense BME680 sensor breakout by itbrainpower.net

BME680 sensor breakout - topBME680 sensor breakout - bottom

PN: SS-BME680#I2C   SKU: ITBP-6003   BME680 I2C sensor breakout info

Next, let's kickstart with BME680 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 [BME680 should be connected, see wiring in next chapter]. Run: i2cdetect -y 1. In command output you should see listed the s-Sense BME680 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 BME680 sensor hardware integration (basic wiring)


s-Sense by itbrainpower.net BME680 sensor is 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:

BME680 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 BME680 sensor wiring to RaspberryPI with safe sensor powering from RaspberryPI 3.3V pin :
BME680 sensor breakout RaspberryPI wiring



Python BME680 sensor software


a. download BME680 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 "bme680_simple.py" in the python library folder download it from here (right click & save as): BME680 - RaspberryPI read sensor data Python code

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


c'. Above code it's included in BME680 RaspberryPI Python library package.

d. Check BME680 params in "bme680_param.py" file. Run BME680 code with command "python bme680_simple.py".


HINTS:
- if you update the code inside "bme680_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-10 © R&D Software Solutions srl