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
 5import board
 6import adafruit_bme680
 7
 8# Create sensor object, communicating over the board's default I2C bus
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
11bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
12
13# change this to match the location's pressure (hPa) at sea level
14bme680.sea_level_pressure = 1013.25
15
16# You will usually have to add an offset to account for the temperature of
17# the sensor. This is usually around 5 degrees but varies by use. Use a
18# separate temperature sensor to calibrate this one.
19temperature_offset = -5
20
21while True:
22    print("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset))
23    print("Gas: %d ohm" % bme680.gas)
24    print("Humidity: %0.1f %%" % bme680.relative_humidity)
25    print("Pressure: %0.3f hPa" % bme680.pressure)
26    print("Altitude = %0.2f meters" % bme680.altitude)
27
28    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
 5import board
 6import digitalio
 7import adafruit_bme680
 8
 9# Create sensor object, communicating over the board's default SPI bus
10cs = digitalio.DigitalInOut(board.D10)
11spi = board.SPI()
12bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)
13
14# change this to match the location's pressure (hPa) at sea level
15bme680.sea_level_pressure = 1013.25
16
17# You will usually have to add an offset to account for the temperature of
18# the sensor. This is usually around 5 degrees but varies by use. Use a
19# separate temperature sensor to calibrate this one.
20temperature_offset = -5
21
22while True:
23    print("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset))
24    print("Gas: %d ohm" % bme680.gas)
25    print("Humidity: %0.1f %%" % bme680.relative_humidity)
26    print("Pressure: %0.3f hPa" % bme680.pressure)
27    print("Altitude = %0.2f meters" % bme680.altitude)
28
29    time.sleep(1)