Skip to content

Commit af79444

Browse files
authored
Merge pull request #38 from caternuson/iss37_spi_example
Add SPI example
2 parents 0fc4f48 + bfaba13 commit af79444

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/bme680_spi.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import board
3+
import digitalio
4+
from busio import SPI
5+
import adafruit_bme680
6+
7+
# Create library object using our Bus SPI port
8+
cs = digitalio.DigitalInOut(board.D10)
9+
spi = SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
10+
bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)
11+
12+
# change this to match the location's pressure (hPa) at sea level
13+
bme680.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.
18+
temperature_offset = -5
19+
20+
while 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)

0 commit comments

Comments
 (0)