Skip to content

Commit 9922274

Browse files
committed
Tweaked examples
1 parent 9b18ecf commit 9922274

3 files changed

Lines changed: 63 additions & 139 deletions

File tree

examples/livetest.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

examples/test.py

100644100755
Lines changed: 32 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,53 @@
1-
"""
2-
Pressure Temperature Humidity
3-
128,0, 79,186,128, 122,185,0, 76,55, 128,0,0, 29,39,
4-
5-
128,0, 79,186,144, 122,185,64, 76,59, 128,0,0, 220,120,
6-
2017-10-13 22:51:50 T: 26.67 degC, P: 1011.79 hPa, H: 49.64 %rH , G: 24487 ohms
7-
8-
128,0, 79,186,160, 122,186,32, 76,61, 128,0,0, 70,56,
9-
2017-10-13 22:51:53 T: 26.68 degC, P: 1011.79 hPa, H: 49.65 %rH , G: 37891 ohms
10-
11-
128,0, 79,186,224, 122,187,0, 76,61, 128,0,0, 205,55,
12-
2017-10-13 22:51:56 T: 26.68 degC, P: 1011.79 hPa, H: 49.65 %rH , G: 51080 ohms
13-
14-
128,0, 79,186,224, 122,187,224, 76,62, 128,0,0, 127,247,
15-
2017-10-13 22:51:59 T: 26.68 degC, P: 1011.79 hPa, H: 49.66 %rH , G: 63052 ohms
16-
17-
128,0, 79,187,32, 122,188,64, 76,58, 128,0,0, 78,119,
18-
2017-10-13 22:52:02 T: 26.69 degC, P: 1011.79 hPa, H: 49.63 %rH , G: 74195 ohms
19-
20-
128,0, 79,187,112, 122,189,64, 76,48, 128,0,0, 46,183,
21-
2017-10-13 22:52:05 T: 26.69 degC, P: 1011.77 hPa, H: 49.57 %rH , G: 83681 ohms
22-
23-
128,0, 79,187,128, 122,189,160, 76,45, 128,0,0, 25,55,
24-
2017-10-13 22:52:08 T: 26.69 degC, P: 1011.77 hPa, H: 49.55 %rH , G: 91612 ohms
25-
26-
128,0, 79,187,144, 122,189,240, 76,48, 128,0,0, 223,182,
27-
2017-10-13 22:52:11 T: 26.69 degC, P: 1011.77 hPa, H: 49.57 %rH , G: 97109 ohms
28-
29-
128,0, 79,187,160, 122,190,80, 76,49, 128,0,0, 198,118,
30-
2017-10-13 22:52:14 T: 26.70 degC, P: 1011.77 hPa, H: 49.58 %rH , G: 103197 ohms
31-
"""
32-
1+
#!/usr/bin/env python
332

343
import bme680
35-
36-
example_calibration = [
37-
# T2L T2H T3 TP P1L P1H P2L
38-
192, 108, 103, 3, 47, 80, 144, 236,
39-
# P2H P3 - P4L P4H P5L P5H P7
40-
214, 88, 255, 42, 30, 169, 255, 54,
41-
# P6 - - P8L P8H P9L P9H P10
42-
30, 0, 0, 199, 239, 69, 248, 30,
43-
# H2H H2L H1L H1H H3 H4 H5 H6
44-
1, 64, 206, 39, 0, 45, 20, 120,
45-
# H7 T1L T1H GH2L GH2H GH1 GH3
46-
156, 24, 102, 142, 171, 226, 18, 16,
47-
0
48-
]
49-
50-
example_heat_range = 22
51-
example_heat_value = 44
52-
example_sw_error = 227
4+
import time
535

546
sensor = bme680.BME680()
557

56-
sensor.calibration_data.set_from_array(example_calibration)
57-
sensor.calibration_data.set_other(
58-
example_heat_range,
59-
example_heat_value,
60-
example_sw_error)
61-
8+
print("Calibration data:")
629
for name in dir(sensor.calibration_data):
6310
if not name.startswith('_'):
6411
value = getattr(sensor.calibration_data, name)
6512
if isinstance(value, int):
6613
print("{}: {}".format(name, value))
6714

68-
sensor.ambient_temperature = 25
69-
70-
"""
71-
result = []
72-
for x in range(63, 4033):
73-
result.append((x, sensor._calc_heater_duration(x)))
7415

75-
print(result)
16+
sensor.set_humidity_oversample(bme680.OS_2X)
17+
sensor.set_pressure_oversample(bme680.OS_4X)
18+
sensor.set_temperature_oversample(bme680.OS_8X)
19+
sensor.set_filter(bme680.FILTER_SIZE_3)
20+
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
7621

77-
result = []
78-
for x in range(200, 401):
79-
result.append(sensor._calc_heater_resistance(x))
22+
print("\n\nInitial reading:")
23+
for name in dir(sensor.data):
24+
value = getattr(sensor.data, name)
25+
if not name.startswith('_'):
26+
print("{}: {}".format(name, value))
8027

81-
print(result)
82-
"""
28+
sensor.set_gas_heater_temperature(320)
29+
sensor.set_gas_heater_duration(150)
30+
sensor.select_gas_heater_profile(0)
8331

84-
"""
85-
Pressure Temperature Humidity Gas
86-
128,0, 79,187,160, 122,190,80, 76,49, 128,0,0, 198,118,
87-
2017-10-13 22:52:14 T: 26.70 degC, P: 1011.77 hPa, H: 49.58 %rH , G: 103197 ohms
88-
"""
32+
# Up to 10 heater profiles can be configured, each
33+
# with their own temperature and duration.
34+
# sensor.set_gas_heater_profile(200, 150, nb_profile=1)
35+
# sensor.select_gas_heater_profile(1)
8936

90-
regs = [128,0, 79,186,144, 122,185,64, 76,59, 128,0,0, 220,120]
91-
vals = [26.67, 1011.79, 49.64, 24487]
37+
print("\n\nPolling:")
38+
try:
39+
while True:
40+
if sensor.get_sensor_data():
9241

93-
adc_pres = (regs[2] << 12) | (regs[3] << 4) | (regs[4] >> 4)
94-
adc_temp = (regs[5] << 12) | (regs[6] << 4) | (regs[7] >> 4)
95-
adc_hum = (regs[8] << 8) | regs[9]
96-
adc_gas_res = (regs[13] << 2) | (regs[14] >> 6)
97-
gas_range = regs[14] & bme680.constants.GAS_RANGE_MSK
42+
output = "{0:.2f} degC {1:.2f} hPa {2:.3f} %rH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
9843

99-
result = sensor._calc_temperature(adc_temp) / 100
100-
print("Temperature: Raw: {}: {} {}".format(adc_temp, vals[0], result))
44+
if sensor.data.heat_stable:
45+
print("{0} {1} ohms".format(output, sensor.data.gas_resistance))
46+
else:
47+
print(output)
10148

102-
result = sensor._calc_pressure(adc_pres)
103-
print("Pressure: Raw: {}: {} {}".format(adc_pres, vals[1], result))
49+
time.sleep(1)
10450

105-
result = sensor._calc_humidity(adc_hum) / 1000
106-
print("Humidity: Raw: {}: {}% {}%".format(adc_hum, vals[2], result))
51+
except KeyboardInterrupt:
52+
pass
10753

108-
result = sensor._calc_gas_resistance(adc_gas_res, gas_range)
109-
print("Resistance: Raw: {}: {} {}".format(adc_gas_res, vals[3], result))

examples/tph.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
import bme680
3+
import time
4+
5+
print("""Display Temperature, Pressure and Humidity
6+
7+
If you don't need gas readings, then you can read temperature,
8+
pressure and humidity quickly.
9+
10+
Press Ctrl+C to exit
11+
12+
""")
13+
14+
sensor = bme680.BME680()
15+
16+
sensor.set_humidity_oversample(bme680.OS_2X)
17+
sensor.set_pressure_oversample(bme680.OS_4X)
18+
sensor.set_temperature_oversample(bme680.OS_8X)
19+
sensor.set_filter(bme680.FILTER_SIZE_3)
20+
21+
print("Polling:")
22+
try:
23+
while True:
24+
if sensor.get_sensor_data():
25+
26+
output = "{0:.2f} degC {1:.2f} hPa {2:.3f} %rH".format(sensor.data.temperature, sensor.data.pressure, sensor.data.humidity)
27+
print(output)
28+
29+
except KeyboardInterrupt:
30+
pass
31+

0 commit comments

Comments
 (0)