Decode fix for #3
[EVA-2020-02-2.git] / examples / weather.py
CommitLineData
a155e335
SM
1#!/usr/bin/env python
2
3import time
4from bme280 import BME280
5
6try:
7 from smbus2 import SMBus
8except ImportError:
9 from smbus import SMBus
10
11print("""weather.py - Print readings from the BME280 weather sensor.
12
13Press Ctrl+C to exit!
14
15""")
16
17bus = SMBus(1)
18bme280 = BME280(i2c_dev=bus)
19
20while True:
21 temperature = bme280.get_temperature()
22 pressure = bme280.get_pressure()
23 humidity = bme280.get_humidity()
24 print("""Temperature: {:05.2f} *C
25Pressure: {:05.2f} hPa
26Relative humidity: {:05.2f} %
27""".format(temperature, pressure, humidity))
28 time.sleep(1)