# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries
# SPDX-License-Identifier: MIT

import time

import board
import digitalio

import adafruit_bme680

# Create sensor object, communicating over the board's default SPI bus
cs = digitalio.DigitalInOut(board.D10)
spi = board.SPI()
bme680 = adafruit_bme680.Adafruit_BME680_SPI(spi, cs)

# change this to match the location's pressure (hPa) at sea level
bme680.sea_level_pressure = 1013.25

# You will usually have to add an offset to account for the temperature of
# the sensor. This is usually around 5 degrees but varies by use. Use a
# separate temperature sensor to calibrate this one.
temperature_offset = -5

while True:
    print(f"\nTemperature: {bme680.temperature + temperature_offset:0.1f} C")
    print(f"Gas: {bme680.gas:d} ohm")
    print(f"Humidity: {bme680.relative_humidity:0.1f} %")
    print(f"Pressure: {bme680.pressure:0.3f} hPa")
    print(f"Altitude = {bme680.altitude:0.2f} meters")

    time.sleep(1)
