Simple test
Ensure your device works with this simple test.
examples/bme680_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7
8import adafruit_bme680
9
10# Create sensor object, communicating over the board's default I2C bus
11i2c = board.I2C() # uses board.SCL and board.SDA
12# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
13bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
14
15# change this to match the location's pressure (hPa) at sea level
16bme680.sea_level_pressure = 1013.25
17
18# You will usually have to add an offset to account for the temperature of
19# the sensor. This is usually around 5 degrees but varies by use. Use a
20# separate temperature sensor to calibrate this one.
21temperature_offset = -5
22
23while True:
24 print(f"\nTemperature: {bme680.temperature + temperature_offset:0.1f} C")
25 print(f"Gas: {bme680.gas:d} ohm")
26 print(f"Humidity: {bme680.relative_humidity:0.1f} %")
27 print(f"Pressure: {bme680.pressure:0.3f} hPa")
28 print(f"Altitude = {bme680.altitude:0.2f} meters")
29
30 time.sleep(1)
SPI Example
Showcase the use of the SPI bus to read the sensor data.
examples/bme680_spi.py
1# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7import digitalio
8
9import adafruit_bme680
10
11# Create sensor object, communicating over the board's default SPI bus
12cs = digitalio.DigitalInOut(board.D10)
13spi = board.SPI()
14bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)
15
16# change this to match the location's pressure (hPa) at sea level
17bme680.sea_level_pressure = 1013.25
18
19# You will usually have to add an offset to account for the temperature of
20# the sensor. This is usually around 5 degrees but varies by use. Use a
21# separate temperature sensor to calibrate this one.
22temperature_offset = -5
23
24while True:
25 print(f"\nTemperature: {bme680.temperature + temperature_offset:0.1f} C")
26 print(f"Gas: {bme680.gas:d} ohm")
27 print(f"Humidity: {bme680.relative_humidity:0.1f} %")
28 print(f"Pressure: {bme680.pressure:0.3f} hPa")
29 print(f"Altitude = {bme680.altitude:0.2f} meters")
30
31 time.sleep(1)