2017-10-17 17:45:50 +02:00
|
|
|
#!/usr/bin/env python
|
2019-06-09 14:11:35 +02:00
|
|
|
|
2017-10-17 17:45:50 +02:00
|
|
|
import bme680
|
|
|
|
|
2019-06-09 14:11:35 +02:00
|
|
|
print("""temperature-pressure-humidity.py - Displays temperature, pressure, and humidity.
|
2017-10-17 17:45:50 +02:00
|
|
|
|
|
|
|
If you don't need gas readings, then you can read temperature,
|
|
|
|
pressure and humidity quickly.
|
|
|
|
|
|
|
|
Press Ctrl+C to exit
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
2018-09-03 12:13:32 +02:00
|
|
|
try:
|
|
|
|
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
|
|
|
|
except IOError:
|
|
|
|
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
|
2017-10-17 17:45:50 +02:00
|
|
|
|
2017-10-18 11:23:30 +02:00
|
|
|
# These oversampling settings can be tweaked to
|
|
|
|
# change the balance between accuracy and noise in
|
|
|
|
# the data.
|
|
|
|
|
2017-10-17 17:45:50 +02:00
|
|
|
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)
|
|
|
|
|
2018-09-02 12:26:04 +02:00
|
|
|
print('Polling:')
|
2017-10-17 17:45:50 +02:00
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
if sensor.get_sensor_data():
|
2018-09-02 12:26:04 +02:00
|
|
|
output = '{0:.2f} C,{1:.2f} hPa,{2:.3f} %RH'.format(
|
|
|
|
sensor.data.temperature,
|
|
|
|
sensor.data.pressure,
|
|
|
|
sensor.data.humidity)
|
2017-10-17 17:45:50 +02:00
|
|
|
print(output)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|