Simple test
Ensure your device works with this simple test.
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("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset))
25 print("Gas: %d ohm" % bme680.gas)
26 print("Humidity: %0.1f %%" % bme680.relative_humidity)
27 print("Pressure: %0.3f hPa" % bme680.pressure)
28 print("Altitude = %0.2f meters" % bme680.altitude)
29
30 time.sleep(1)
SPI Example
Showcase the use of the SPI bus to read the sensor data.
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("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset))
26 print("Gas: %d ohm" % bme680.gas)
27 print("Humidity: %0.1f %%" % bme680.relative_humidity)
28 print("Pressure: %0.3f hPa" % bme680.pressure)
29 print("Altitude = %0.2f meters" % bme680.altitude)
30
31 time.sleep(1)