1
0
mirror of https://github.com/cmur2/python-bme680.git synced 2024-11-13 22:56:21 +01:00

Tidied up examples a little.

This commit is contained in:
sandyjmacdonald 2017-10-18 09:23:30 +00:00
parent 99222746a6
commit bcf3704610
2 changed files with 18 additions and 5 deletions

View File

@ -5,13 +5,21 @@ import time
sensor = bme680.BME680() sensor = bme680.BME680()
# These calibration data can safely be commented
# out, if desired.
print("Calibration data:") print("Calibration data:")
for name in dir(sensor.calibration_data): for name in dir(sensor.calibration_data):
if not name.startswith('_'): if not name.startswith('_'):
value = getattr(sensor.calibration_data, name) value = getattr(sensor.calibration_data, name)
if isinstance(value, int): if isinstance(value, int):
print("{}: {}".format(name, value)) print("{}: {}".format(name, value))
# 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_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X) sensor.set_pressure_oversample(bme680.OS_4X)
@ -22,6 +30,7 @@ sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
print("\n\nInitial reading:") print("\n\nInitial reading:")
for name in dir(sensor.data): for name in dir(sensor.data):
value = getattr(sensor.data, name) value = getattr(sensor.data, name)
if not name.startswith('_'): if not name.startswith('_'):
print("{}: {}".format(name, value)) print("{}: {}".format(name, value))
@ -38,11 +47,11 @@ print("\n\nPolling:")
try: try:
while True: while True:
if sensor.get_sensor_data(): if sensor.get_sensor_data():
output = "{0:.2f} C,{1:.2f} hPa,{2:.2f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
output = "{0:.2f} degC {1:.2f} hPa {2:.3f} %rH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
if sensor.data.heat_stable: if sensor.data.heat_stable:
print("{0} {1} ohms".format(output, sensor.data.gas_resistance)) print("{0},{1} Ohms".format(output, sensor.data.gas_resistance))
else: else:
print(output) print(output)
@ -50,4 +59,3 @@ try:
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass

View File

@ -13,6 +13,10 @@ Press Ctrl+C to exit
sensor = bme680.BME680() sensor = bme680.BME680()
# 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_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X) sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X) sensor.set_temperature_oversample(bme680.OS_8X)
@ -23,7 +27,8 @@ try:
while True: while True:
if sensor.get_sensor_data(): if sensor.get_sensor_data():
output = "{0:.2f} degC {1:.2f} hPa {2:.3f} %rH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity) output = "{0:.2f} C,{1:.2f} hPa,{2:.3f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
print(output) print(output)
except KeyboardInterrupt: except KeyboardInterrupt: