Skip to content

Commit f8548e4

Browse files
committed
Update BME68X and BME690 examples
1 parent 575e3a1 commit f8548e4

File tree

4 files changed

+135
-17
lines changed

4 files changed

+135
-17
lines changed

micropython/examples/breakout_bme68x/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111

1212
## Getting Started
1313

14-
Construct new `PimoroniI2C` and `BreakoutBME68X` instances:
14+
Construct new `I2C` and `BreakoutBME68X` instances:
1515

1616
```python
1717
from breakout_bme68x import BreakoutBME68X
18-
from pimoroni_i2c import PimoroniI2C
1918

20-
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
21-
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
22-
23-
i2c = PimoroniI2C(**PINS_PICO_EXPLORER)
19+
i2c = machine.I2C()
2420
bme = BreakoutBME68X(i2c)
2521
```
2622

27-
The `breakout_bme68x` module includes constants for the possible I2C addresses:
23+
The default I2C address is `0x76`. If you've cut the trace to change the I2C address of the sensor, you can specify the alternate I2C address like this:
24+
25+
``` python
26+
bme = BreakoutBME68X(i2c, 0x77)
27+
```
28+
29+
The `breakout_bme68x` module also includes constants for the possible I2C addresses:
2830

29-
* `ADDRESS_DEFAULT`
30-
* `ADDRESS_ALT`
31+
* `I2C_ADDRESS_DEFAULT`
32+
* `I2C_ADDRESS_ALT`
3133

3234
## Reading Data From The Sensor
3335

micropython/examples/breakout_bme68x/bme68x_demo.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
22
33
This demo will work for both the BME680 and BME688.
44
"""
5+
6+
import machine
57
import time
68
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
7-
from pimoroni_i2c import PimoroniI2C
8-
9-
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
10-
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
11-
12-
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
139

14-
bme = BreakoutBME68X(i2c)
10+
bme = BreakoutBME68X(machine.I2C(), 0x76)
1511
# If this gives an error, try the alternative address
16-
# bme = BreakoutBME68X(i2c, 0x77)
12+
# bme = BreakoutBME68X(machine.I2C(), 0x77)
1713

1814
while True:
1915
temperature, pressure, humidity, gas, status, _, _ = bme.read()
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# BME69X <!-- omit in toc -->
2+
3+
- [Getting Started](#getting-started)
4+
- [Reading Data From The Sensor](#reading-data-from-the-sensor)
5+
- [Configuring The Sensor](#configuring-the-sensor)
6+
- [Filter Settings](#filter-settings)
7+
- [Oversampling Settings](#oversampling-settings)
8+
- [Mode Settings](#mode-settings)
9+
- [Standby/Output Data Rate Settings](#standbyoutput-data-rate-settings)
10+
- [Defaults](#defaults)
11+
12+
## Getting Started
13+
14+
Construct new `I2C` and `BreakoutBME69X` instances:
15+
16+
```python
17+
from breakout_bme69x import BreakoutBME69X
18+
19+
i2c = machine.I2C()
20+
bme = BreakoutBME69X(i2c)
21+
```
22+
23+
The default I2C address is `0x76`. If you've cut the trace to change the I2C address of the sensor, you can specify the alternate I2C address like this:
24+
25+
``` python
26+
bme = BreakoutBME69X(i2c, 0x77)
27+
```
28+
29+
The `breakout_bme69x` module also includes constants for the possible I2C addresses:
30+
31+
* `I2C_ADDRESS_DEFAULT`
32+
* `I2C_ADDRESS_ALT`
33+
34+
## Reading Data From The Sensor
35+
36+
The `read` method will return a tuple containing Temperature (degrees C), Pressure (Pa), relative humidity (%rH), and gas resistance (Ω) values, plus the status code and gas/measurement indexes:
37+
38+
```python
39+
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
40+
```
41+
42+
In all cases `gas_index` and `meas_index` will be zero, since these refer to the measurement profile used to gather the current readings. The MicroPython bindings currently only support a single measurement profile with a default of 300c for 100ms.
43+
44+
You can pass a custom temperature and duration into `read`:
45+
46+
```python
47+
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read(heater_temp=250, heater_duration=50)
48+
```
49+
50+
## Configuring The Sensor
51+
52+
The `configure` method allows you to set up the oversampling, filtering and operation mode.
53+
54+
```python
55+
bme.configure(filter, standby_time, os_pressure, os_temp, os_humidity)
56+
```
57+
58+
The `breakout_bme69x` module includes constants for these:
59+
60+
### Filter Settings
61+
62+
* `FILTER_COEFF_OFF`
63+
* `FILTER_COEFF_1`
64+
* `FILTER_COEFF_3`
65+
* `FILTER_COEFF_8`
66+
* `FILTER_COEFF_15`
67+
* `FILTER_COEFF_31`
68+
* `FILTER_COEFF_63`
69+
* `FILTER_COEFF_127`
70+
71+
### Oversampling Settings
72+
73+
* `NO_OVERSAMPLING`
74+
* `OVERSAMPLING_1X`
75+
* `OVERSAMPLING_2X`
76+
* `OVERSAMPLING_4X`
77+
* `OVERSAMPLING_8X`
78+
* `OVERSAMPLING_16X`
79+
80+
### Mode Settings
81+
82+
* `SLEEP_MODE`
83+
* `FORCED_MODE`
84+
* `NORMAL_MODE`
85+
86+
### Standby/Output Data Rate Settings
87+
88+
* `STANDBY_TIME_0_59_MS`
89+
* `STANDBY_TIME_62_5_MS`
90+
* `STANDBY_TIME_125_MS`
91+
* `STANDBY_TIME_250_MS`
92+
* `STANDBY_TIME_500_MS`
93+
* `STANDBY_TIME_1000_MS`
94+
* `STANDBY_TIME_10_MS`
95+
* `STANDBY_TIME_20_MS`
96+
97+
### Defaults
98+
99+
```python
100+
bme.configure(FILTER_COEFF_3, STANDBY_TIME_1000_MS, OVERSAMPLING_16X, OVERSAMPLING_2X, OVERSAMPLING_1X)
101+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""BME69X demo
2+
3+
Demo of how to read the BME690 sensor.
4+
"""
5+
6+
import machine
7+
import time
8+
from breakout_bme69x import BreakoutBME69X, STATUS_HEATER_STABLE
9+
10+
bme = BreakoutBME69X(machine.I2C(), 0x76)
11+
# If this gives an error, try the alternative address
12+
# bme = BreakoutBME69X(machine.I2C(), 0x77)
13+
14+
while True:
15+
temperature, pressure, humidity, gas, status, _, _ = bme.read()
16+
heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable"
17+
print("{:0.2f}c, {:0.2f}Pa, {:0.2f}%, {:0.2f} Ohms, Heater: {}".format(
18+
temperature, pressure, humidity, gas, heater))
19+
time.sleep(1.0)

0 commit comments

Comments
 (0)