Merge branch 'master' of github.com:pimoroni/enviroplus-python
[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
10b73e18
CM
11import logging
12
13logging.basicConfig(
14 format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
15 level=logging.INFO,
16 datefmt='%Y-%m-%d %H:%M:%S')
17
18logging.info("""weather.py - Print readings from the BME280 weather sensor.
a155e335
SM
19
20Press Ctrl+C to exit!
21
22""")
23
24bus = SMBus(1)
25bme280 = BME280(i2c_dev=bus)
26
27while True:
28 temperature = bme280.get_temperature()
29 pressure = bme280.get_pressure()
30 humidity = bme280.get_humidity()
10b73e18 31 logging.info("""Temperature: {:05.2f} *C
a155e335
SM
32Pressure: {:05.2f} hPa
33Relative humidity: {:05.2f} %
34""".format(temperature, pressure, humidity))
35 time.sleep(1)