Files
bme280/Pimoroni/pimoroni-bme280/examples/temperature-forced-mode.py
2023-05-05 16:49:37 +02:00

24 lines
543 B
Python
Executable File

#!/usr/bin/env python
import time
try:
from smbus2 import SMBus
except ImportError:
from smbus import SMBus
from bme280 import BME280
# Initialise the BME280
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
# Set up in "forced" mode
# In this mode `get_temperature` and `get_pressure` will trigger
# a new reading and wait for the result.
# The chip will return to sleep mode when finished.
bme280.setup(mode="forced")
while True:
temperature = bme280.get_temperature()
print('{:05.2f}*C'.format(temperature))
time.sleep(1)