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