1
0
mirror of https://github.com/cmur2/python-bme680.git synced 2025-07-03 13:11:28 +02:00

Tidying up and adding examples

This commit is contained in:
Sandy Macdonald
2019-06-09 13:11:35 +01:00
parent e827e5d622
commit 5a5dd139c3
5 changed files with 72 additions and 10 deletions

View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
import bme680
print("""temperature-pressure-humidity.py - Displays temperature, pressure, and humidity.
If you don't need gas readings, then you can read temperature,
pressure and humidity quickly.
Press Ctrl+C to exit
""")
try:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except IOError:
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
# These oversampling settings can be tweaked to
# change the balance between accuracy and noise in
# the data.
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
print('Polling:')
try:
while True:
if sensor.get_sensor_data():
output = '{0:.2f} C,{1:.2f} hPa,{2:.3f} %RH'.format(
sensor.data.temperature,
sensor.data.pressure,
sensor.data.humidity)
print(output)
except KeyboardInterrupt:
pass