From bcf37046100215590dcd2848e6d70f569cfd49ba Mon Sep 17 00:00:00 2001 From: sandyjmacdonald Date: Wed, 18 Oct 2017 09:23:30 +0000 Subject: [PATCH] Tidied up examples a little. --- examples/{test.py => read-all.py} | 16 ++++++++++++---- examples/{tph.py => temp-press-hum.py} | 7 ++++++- 2 files changed, 18 insertions(+), 5 deletions(-) rename examples/{test.py => read-all.py} (76%) rename examples/{tph.py => temp-press-hum.py} (69%) diff --git a/examples/test.py b/examples/read-all.py similarity index 76% rename from examples/test.py rename to examples/read-all.py index a8cab4f..24baef5 100755 --- a/examples/test.py +++ b/examples/read-all.py @@ -5,13 +5,21 @@ import time sensor = bme680.BME680() +# These calibration data can safely be commented +# out, if desired. + print("Calibration data:") for name in dir(sensor.calibration_data): + if not name.startswith('_'): value = getattr(sensor.calibration_data, name) + if isinstance(value, int): 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_pressure_oversample(bme680.OS_4X) @@ -22,6 +30,7 @@ sensor.set_gas_status(bme680.ENABLE_GAS_MEAS) print("\n\nInitial reading:") for name in dir(sensor.data): value = getattr(sensor.data, name) + if not name.startswith('_'): print("{}: {}".format(name, value)) @@ -38,11 +47,11 @@ print("\n\nPolling:") try: while True: 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:.2f} %RH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity) 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: print(output) @@ -50,4 +59,3 @@ try: except KeyboardInterrupt: pass - diff --git a/examples/tph.py b/examples/temp-press-hum.py similarity index 69% rename from examples/tph.py rename to examples/temp-press-hum.py index a9535be..b21d0f4 100755 --- a/examples/tph.py +++ b/examples/temp-press-hum.py @@ -13,6 +13,10 @@ Press Ctrl+C to exit 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_pressure_oversample(bme680.OS_4X) sensor.set_temperature_oversample(bme680.OS_8X) @@ -23,7 +27,8 @@ try: while True: 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) except KeyboardInterrupt: