Difference between revisions of "Sensors: BME680"

From HiveTool
Jump to: navigation, search
(Test)
Line 112: Line 112:
 
  cp read-all.py bme689.py
 
  cp read-all.py bme689.py
 
  vi bme689.py
 
  vi bme689.py
 +
 +
#!/usr/bin/env python
 +
 +
#  from https://github.com/pimoroni/bme680
 +
#  examples/read_all.py
 +
#
 +
#  https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-bme680-breakout
 +
#
 +
#  NOTE: device address is set in /usr/local/lib/python2.7/dist-packages/bme680/__init__.py
 +
#
 +
#  To list the i2c device addresses:  sudo i2cdetect -y 1
 +
#
 +
 +
import bme680
 +
import time
 +
 +
sensor = bme680.BME680()
 +
 +
# These oversampling settings can be tweaked to
 +
# change the balance between accuracy and noise in
 +
# the data.
 +
 +
sensor.set_humidity_oversample(bme680.OS_2X)
 +
sensor.set_pressure_oversample(bme680.OS_4X)
 +
sensor.set_temperature_oversample(bme680.OS_8X)
 +
sensor.set_filter(bme680.FILTER_SIZE_3)
 +
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
 +
 +
for name in dir(sensor.data):
 +
    value = getattr(sensor.data, name)
 +
 +
sensor.set_gas_heater_temperature(320)
 +
sensor.set_gas_heater_duration(150)
 +
sensor.select_gas_heater_profile(0)
 +
 +
# Up to 10 heater profiles can be configured, each
 +
# with their own temperature and duration.
 +
# sensor.set_gas_heater_profile(200, 150, nb_profile=1)
 +
# sensor.select_gas_heater_profile(1)
 +
 +
i=0
 +
data_bad=True
 +
try:
 +
    while i < 10 :
 +
        if sensor.get_sensor_data():
 +
            output = "{0:.2f} {1:.2f} {2:.2f} ".format(sensor.data.temperature, sensor.data.humidity, sensor.data.pressure)
 +
 +
            if i == 9 and sensor.data.heat_stable:
 +
                print("{0} {1}".format(output, sensor.data.gas_resistance))
 +
                data_bad = False 
 +
 +
            else:
 +
                print("{0} NULL".format(output))
 +
 +
        time.sleep(1)
 +
        i += 1
 +
except KeyboardInterrupt:
 +
    pass

Revision as of 16:33, 6 August 2018

BME680

Bosch Sensortec c routines

Download the drivers

git clone https://github.com/BoschSensortec/BME680_driver.git
git clone https://github.com/twartzek/bme680-raspberry.git


Copy or move the raspberry pi code to the BME69-680_+driver directory.

cp bme680-raspberry/* BME680_driver/

Compile

gcc bme680_main.c bme680.c -o bme680

Wiring Adafruit

Note that this pin out is only for the Hive Interface boards ver 1.0. The wiring will be slightly different for the ver 0.3 boards and earlier.

H2 I2C Bus ver 1.0 Adafruit break out board
Pin Signal BME680
1 +3.3 VIN
2 I2C SDI
3 I2C SCK
4 NC
5 Ground GND


Test

./bme680
**** BME680 start measurements  ****
2018-07-05 13:27:40 T: 25.14 degC, P: 942.12 hPa, H: 74.29 %rH, G: 8029 Ohms
2018-07-05 13:27:43 T: 25.13 degC, P: 942.12 hPa, H: 74.29 %rH, G: 9043 Ohms
2018-07-05 13:27:46 T: 25.11 degC, P: 942.10 hPa, H: 74.38 %rH, G: 9976 Ohms
**** Measurement finished ****

Oops! Looks like we have a problem with the temperature readings going to zero. Notice that the pressure reading shifts about 60 hPa and rH shifts about 4% when the temperature goes to zero. Maybe try the SPI interface?

No. Seems to be a timing problem in reading the temperature sensor. It works fine on a Pi B+. I think the other sensors shift because the temperature is used to compensate them.

These bad reading were run on a Pi3B+:

**** BME680 start measurements  ****
2018-07-05 14:28:38 T: 23.37 degC, P: 942.85 hPa, H: 84.02 %rH, G: 186746 Ohms
2018-07-05 14:28:41 T: 23.37 degC, P: 942.87 hPa, H: 84.05 %rH, G: 211715 Ohms
2018-07-05 14:28:44 T: 23.37 degC, P: 942.85 hPa, H: 84.06 %rH, G: 223194 Ohms
**** Measurement finished ****
**** BME680 start measurements  ****
2018-07-05 14:28:53 T: 0.00 degC, P: 905.57 hPa, H: 80.40 %rH, G: 186007 Ohms
2018-07-05 14:28:56 T: 0.00 degC, P: 905.57 hPa, H: 80.41 %rH, G: 212125 Ohms
2018-07-05 14:28:59 T: 0.00 degC, P: 905.57 hPa, H: 80.41 %rH, G: 223043 Ohms
**** Measurement finished ****
**** BME680 start measurements  ****
2018-07-05 14:29:08 T: 0.00 degC, P: 905.59 hPa, H: 80.46 %rH, G: 185797 Ohms
2018-07-05 14:29:11 T: 0.00 degC, P: 905.61 hPa, H: 80.45 %rH, G: 212261 Ohms
2018-07-05 14:29:14 T: 0.00 degC, P: 905.61 hPa, H: 80.43 %rH, G: 223497 Ohms
**** Measurement finished ****
**** BME680 start measurements  ****
2018-07-05 14:29:23 T: 23.35 degC, P: 942.87 hPa, H: 84.19 %rH, G: 186640 Ohms
2018-07-05 14:29:26 T: 23.35 degC, P: 942.87 hPa, H: 84.20 %rH, G: 213361 Ohms
2018-07-05 14:29:29 T: 23.35 degC, P: 942.87 hPa, H: 84.18 %rH, G: 223497 Ohms
**** Measurement finished ****
**** BME680 start measurements  ****
2018-07-05 14:29:39 T: 23.35 degC, P: 942.87 hPa, H: 84.23 %rH, G: 186428 Ohms
2018-07-05 14:29:42 T: 23.36 degC, P: 942.87 hPa, H: 84.19 %rH, G: 213361 Ohms
2018-07-05 14:29:45 T: 23.36 degC, P: 942.89 hPa, H: 84.03 %rH, G: 223043 Ohms
**** Measurement finished ****
**** BME680 start measurements  ****
2018-07-05 14:29:54 T: 0.00 degC, P: 905.55 hPa, H: 80.39 %rH, G: 186640 Ohms
2018-07-05 14:29:57 T: 0.00 degC, P: 905.55 hPa, H: 80.46 %rH, G: 211715 Ohms
2018-07-05 14:30:00 T: 0.00 degC, P: 905.53 hPa, H: 80.49 %rH, G: 224105 Ohms
**** Measurement finished ****

These reading were run on a Pi B+:

2018-07-06 18:46:01 T: 22.71 degC, P: 939.45 hPa, H: 87.01 %rH, G: 30935 Ohms
2018-07-06 18:51:02 T: 22.70 degC, P: 939.40 hPa, H: 87.06 %rH, G: 31165 Ohms
2018-07-06 18:56:03 T: 22.70 degC, P: 939.32 hPa, H: 87.12 %rH, G: 31469 Ohms
2018-07-06 19:01:03 T: 22.69 degC, P: 939.30 hPa, H: 86.99 %rH, G: 31398 Ohms
2018-07-06 19:06:04 T: 22.69 degC, P: 939.26 hPa, H: 87.11 %rH, G: 31493 Ohms
2018-07-06 19:11:04 T: 22.68 degC, P: 939.12 hPa, H: 87.02 %rH, G: 31446 Ohms

PiMoroni Python driver

Install

curl https://get.pimoroni.com/bme680 | bash

Test

cd /home/pi/Pimoroni/bme680/examples
cp read-all.py bme689.py
vi bme689.py
#!/usr/bin/env python

#  from https://github.com/pimoroni/bme680
#  examples/read_all.py
#
#  https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-bme680-breakout
#
#  NOTE: device address is set in /usr/local/lib/python2.7/dist-packages/bme680/__init__.py
#
#  To list the i2c device addresses:  sudo i2cdetect -y 1
#

import bme680
import time 

sensor = bme680.BME680()

# These oversampling settings can be tweaked to 
# change the balance between accuracy and noise in
# the data.

sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)

for name in dir(sensor.data):
    value = getattr(sensor.data, name)

sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)

# Up to 10 heater profiles can be configured, each
# with their own temperature and duration.
# sensor.set_gas_heater_profile(200, 150, nb_profile=1)
# sensor.select_gas_heater_profile(1)

i=0
data_bad=True
try:
    while i < 10 :
        if sensor.get_sensor_data():
            output = "{0:.2f} {1:.2f} {2:.2f} ".format(sensor.data.temperature, sensor.data.humidity, sensor.data.pressure)

            if i == 9 and sensor.data.heat_stable:
                print("{0} {1}".format(output, sensor.data.gas_resistance))
                data_bad = False  

            else:
                print("{0} NULL".format(output)) 

        time.sleep(1)
        i += 1
except KeyboardInterrupt:
    pass