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
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
10bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
11
12# change this to match the location's pressure (hPa) at sea level
13bme680.sea_level_pressure = 1013.25
14
15# You will usually have to add an offset to account for the temperature of
16# the sensor. This is usually around 5 degrees but varies by use. Use a
17# separate temperature sensor to calibrate this one.
18temperature_offset = -5
19
20while True:
21 print("\nTemperature: %0.1f C" % (bme680.temperature + temperature_offset))
22 print("Gas: %d ohm" % bme680.gas)
23 print("Humidity: %0.1f %%" % bme680.relative_humidity)
24 print("Pressure: %0.3f hPa" % bme680.pressure)
25 print("Altitude = %0.2f meters" % bme680.altitude)
26
27 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
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)