From f8548e4d34f7ad5f608bd3bb41ad4581695fb623 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Tue, 15 Apr 2025 11:14:16 +0100 Subject: [PATCH] Update BME68X and BME690 examples --- .../examples/breakout_bme68x/README.md | 20 ++-- .../examples/breakout_bme68x/bme68x_demo.py | 12 +-- .../examples/breakout_bme690/README.md | 101 ++++++++++++++++++ .../examples/breakout_bme690/demo_bme690.py | 19 ++++ 4 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 micropython/examples/breakout_bme690/README.md create mode 100644 micropython/examples/breakout_bme690/demo_bme690.py diff --git a/micropython/examples/breakout_bme68x/README.md b/micropython/examples/breakout_bme68x/README.md index e79c9cc1..dd8df3a7 100644 --- a/micropython/examples/breakout_bme68x/README.md +++ b/micropython/examples/breakout_bme68x/README.md @@ -11,23 +11,25 @@ ## Getting Started -Construct new `PimoroniI2C` and `BreakoutBME68X` instances: +Construct new `I2C` and `BreakoutBME68X` instances: ```python from breakout_bme68x import BreakoutBME68X -from pimoroni_i2c import PimoroniI2C -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - -i2c = PimoroniI2C(**PINS_PICO_EXPLORER) +i2c = machine.I2C() bme = BreakoutBME68X(i2c) ``` -The `breakout_bme68x` module includes constants for the possible I2C addresses: +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: -* `ADDRESS_DEFAULT` -* `ADDRESS_ALT` +``` python +bme = BreakoutBME68X(i2c, 0x77) +``` + +The `breakout_bme68x` module also includes constants for the possible I2C addresses: + +* `I2C_ADDRESS_DEFAULT` +* `I2C_ADDRESS_ALT` ## Reading Data From The Sensor diff --git a/micropython/examples/breakout_bme68x/bme68x_demo.py b/micropython/examples/breakout_bme68x/bme68x_demo.py index acae036e..5c5eeced 100644 --- a/micropython/examples/breakout_bme68x/bme68x_demo.py +++ b/micropython/examples/breakout_bme68x/bme68x_demo.py @@ -2,18 +2,14 @@ This demo will work for both the BME680 and BME688. """ + +import machine import time from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE -from pimoroni_i2c import PimoroniI2C -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) - -bme = BreakoutBME68X(i2c) +bme = BreakoutBME68X(machine.I2C(), 0x76) # If this gives an error, try the alternative address -# bme = BreakoutBME68X(i2c, 0x77) +# bme = BreakoutBME68X(machine.I2C(), 0x77) while True: temperature, pressure, humidity, gas, status, _, _ = bme.read() diff --git a/micropython/examples/breakout_bme690/README.md b/micropython/examples/breakout_bme690/README.md new file mode 100644 index 00000000..1d995519 --- /dev/null +++ b/micropython/examples/breakout_bme690/README.md @@ -0,0 +1,101 @@ +# BME69X + +- [Getting Started](#getting-started) +- [Reading Data From The Sensor](#reading-data-from-the-sensor) +- [Configuring The Sensor](#configuring-the-sensor) + - [Filter Settings](#filter-settings) + - [Oversampling Settings](#oversampling-settings) + - [Mode Settings](#mode-settings) + - [Standby/Output Data Rate Settings](#standbyoutput-data-rate-settings) + - [Defaults](#defaults) + +## Getting Started + +Construct new `I2C` and `BreakoutBME69X` instances: + +```python +from breakout_bme69x import BreakoutBME69X + +i2c = machine.I2C() +bme = BreakoutBME69X(i2c) +``` + +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: + +``` python +bme = BreakoutBME69X(i2c, 0x77) +``` + +The `breakout_bme69x` module also includes constants for the possible I2C addresses: + +* `I2C_ADDRESS_DEFAULT` +* `I2C_ADDRESS_ALT` + +## Reading Data From The Sensor + +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: + +```python +temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read() +``` + +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. + +You can pass a custom temperature and duration into `read`: + +```python +temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read(heater_temp=250, heater_duration=50) +``` + +## Configuring The Sensor + +The `configure` method allows you to set up the oversampling, filtering and operation mode. + +```python +bme.configure(filter, standby_time, os_pressure, os_temp, os_humidity) +``` + +The `breakout_bme69x` module includes constants for these: + +### Filter Settings + +* `FILTER_COEFF_OFF` +* `FILTER_COEFF_1` +* `FILTER_COEFF_3` +* `FILTER_COEFF_8` +* `FILTER_COEFF_15` +* `FILTER_COEFF_31` +* `FILTER_COEFF_63` +* `FILTER_COEFF_127` + +### Oversampling Settings + +* `NO_OVERSAMPLING` +* `OVERSAMPLING_1X` +* `OVERSAMPLING_2X` +* `OVERSAMPLING_4X` +* `OVERSAMPLING_8X` +* `OVERSAMPLING_16X` + +### Mode Settings + +* `SLEEP_MODE` +* `FORCED_MODE` +* `NORMAL_MODE` + +### Standby/Output Data Rate Settings + +* `STANDBY_TIME_0_59_MS` +* `STANDBY_TIME_62_5_MS` +* `STANDBY_TIME_125_MS` +* `STANDBY_TIME_250_MS` +* `STANDBY_TIME_500_MS` +* `STANDBY_TIME_1000_MS` +* `STANDBY_TIME_10_MS` +* `STANDBY_TIME_20_MS` + +### Defaults + +```python +bme.configure(FILTER_COEFF_3, STANDBY_TIME_1000_MS, OVERSAMPLING_16X, OVERSAMPLING_2X, OVERSAMPLING_1X) +``` diff --git a/micropython/examples/breakout_bme690/demo_bme690.py b/micropython/examples/breakout_bme690/demo_bme690.py new file mode 100644 index 00000000..25b2ddbc --- /dev/null +++ b/micropython/examples/breakout_bme690/demo_bme690.py @@ -0,0 +1,19 @@ +"""BME69X demo + +Demo of how to read the BME690 sensor. +""" + +import machine +import time +from breakout_bme69x import BreakoutBME69X, STATUS_HEATER_STABLE + +bme = BreakoutBME69X(machine.I2C(), 0x76) +# If this gives an error, try the alternative address +# bme = BreakoutBME69X(machine.I2C(), 0x77) + +while True: + temperature, pressure, humidity, gas, status, _, _ = bme.read() + heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable" + print("{:0.2f}c, {:0.2f}Pa, {:0.2f}%, {:0.2f} Ohms, Heater: {}".format( + temperature, pressure, humidity, gas, heater)) + time.sleep(1.0)