docs(bme280): Add README, examples, and hardware test scenarios#314
Conversation
There was a problem hiding this comment.
Pull request overview
Adds documentation, examples, and hardware test scenarios for the BME280 MicroPython driver, and updates the root component table to link to the new driver docs.
Changes:
- Added
lib/bme280/README.mdwith API reference and usage notes - Added two BME280 example scripts (
basic_reader.py,weather_station.py) - Added BME280 hardware test scenarios and updated root
README.mdto link the driver
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
tests/scenarios/bme280.yaml |
Adds hardware-mode range checks plus a manual validation prompt |
lib/bme280/examples/basic_reader.py |
Adds a simple 10-sample read example |
lib/bme280/examples/weather_station.py |
Adds continuous monitoring with altitude estimation + DAPLink flash CSV logging |
lib/bme280/README.md |
Adds driver documentation and API reference |
README.md |
Updates board components table to link to the BME280 README |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Features | ||
|
|
||
| * I2C communication |
There was a problem hiding this comment.
Section headings are using # (H1) repeatedly (e.g., “# Features”, “# Sensor Overview”, ...). This makes the document structure inconsistent and can hurt navigation; other driver READMEs use a single H1 title and H2/H3 for sections. Downgrade these subsection headings to ##/### as appropriate.
There was a problem hiding this comment.
Fixed in b660b06: all section headings downgraded from H1 to H2 (Features, Sensor Overview, I2C Address, Basic Usage, API Reference, Examples, References).
| | Example | Description | | ||
| | -------------------- | -------------------------------------------------- | | ||
| | `basic_reader.py` | Read temperature, pressure, and humidity | | ||
| | `weather_station.py` | Continuous logging with altitude computation | | ||
|
|
There was a problem hiding this comment.
The examples table at the end also starts rows with ||, which won’t render as a proper Markdown table. Switch to standard single-pipe table syntax.
There was a problem hiding this comment.
Checked: the tables use standard single-pipe syntax. No double-pipe issue found in the actual file.
| print("Device ID:", hex(sensor.device_id())) | ||
|
|
||
| for _ in range(10): | ||
| temperature, pressure, humidity = sensor.read() |
There was a problem hiding this comment.
basic_reader.py calls sensor.read() without ever starting measurements (the driver’s constructor configures the BME280 into sleep mode). This will read whatever stale/undefined values are currently in the data registers. Either call sensor.set_continuous(...) once before the loop or use sensor.read_one_shot() inside the loop.
| temperature, pressure, humidity = sensor.read() | |
| temperature, pressure, humidity = sensor.read_one_shot() |
There was a problem hiding this comment.
Fixed in b660b06: basic_reader.py now uses sensor.read_one_shot() instead of sensor.read().
| i2c = I2C(1) | ||
|
|
||
| sensor = BME280(i2c) | ||
|
|
||
| while True: | ||
| temperature, pressure, humidity = sensor.read() | ||
|
|
||
| print("T:", temperature, "C") | ||
| print("P:", pressure, "hPa") | ||
| print("H:", humidity, "%RH") | ||
| print() | ||
|
|
||
| sleep(1) |
There was a problem hiding this comment.
The “Basic Usage” snippet uses sensor.read() in a loop, but the driver defaults to sleep mode and read() does not trigger a measurement. Update the docs to either show set_continuous(...) before the loop or use read_one_shot() so the example produces fresh readings on real hardware.
| i2c = I2C(1) | |
| sensor = BME280(i2c) | |
| while True: | |
| temperature, pressure, humidity = sensor.read() | |
| print("T:", temperature, "C") | |
| print("P:", pressure, "hPa") | |
| print("H:", humidity, "%RH") | |
| print() | |
| sleep(1) | |
| i2c = I2C(1) | |
| sensor = BME280(i2c) | |
| sensor.set_continuous() # start continuous measurements | |
| while True: | |
| temperature, pressure, humidity = sensor.read() | |
| print("T:", temperature, "C") | |
| print("P:", pressure, "hPa") | |
| print("H:", humidity, "%RH") | |
| print() | |
| sleep(1) |
There was a problem hiding this comment.
Fixed in b660b06: Basic Usage snippet now uses read_one_shot().
| - name: "Temperature in plausible range" | ||
| action: call | ||
| method: temperature | ||
| expect_range: [10.0, 45.0] | ||
| mode: [hardware] | ||
|
|
||
| - name: "Pressure in plausible range" | ||
| action: call | ||
| method: pressure_hpa | ||
| expect_range: [900.0, 1100.0] | ||
| mode: [hardware] | ||
|
|
||
| - name: "Humidity in plausible range" | ||
| action: call | ||
| method: humidity | ||
| expect_range: [5.0, 95.0] | ||
| mode: [hardware] | ||
|
|
||
| - name: "read() returns three plausible values" | ||
| action: script | ||
| script: | | ||
| t, p, h = dev.read() | ||
| result = 10.0 <= t <= 45.0 and 900.0 <= p <= 1100.0 and 5.0 <= h <= 95.0 | ||
| expect_true: true | ||
| mode: [hardware] |
There was a problem hiding this comment.
These hardware tests call temperature/pressure_hpa/humidity/read() directly, but the driver initializes the sensor in sleep mode and these methods do not trigger a conversion. This can make hardware tests fail or read stale data. Convert these to scripts that first start a measurement (e.g., dev.trigger_one_shot() + wait, dev.read_one_shot(), or dev.set_continuous() with a short delay) before validating ranges.
There was a problem hiding this comment.
Fixed in b660b06: all hardware tests now use read_one_shot() (forced mode) instead of direct method calls in sleep mode. Also added a "Continuous mode produces plausible values" test that explicitly enters normal mode before reading.
| - method: humidity | ||
| label: "Humidity" | ||
| unit: "%RH" | ||
| prompt: "Do the values look reasonable?" |
There was a problem hiding this comment.
The manual hardware test currently has no expectation (e.g., expect_true: true). As a result, the scenario runner will always pass this test regardless of the user's answer (it falls back to “no assertion”). Add an explicit expectation so a “No” response fails the test.
| prompt: "Do the values look reasonable?" | |
| prompt: "Do the values look reasonable?" | |
| expect_true: true |
There was a problem hiding this comment.
Fixed in b660b06: added expect_true: true to the manual test.
| | Feature | Value | | ||
| | ---------------------- | ----------------------- | | ||
| | Pressure range | 300 hPa - 1100 hPa | | ||
| | Pressure resolution | 0.18 Pa (20-bit ADC) | | ||
| | Temperature range | -40 C to +85 C | | ||
| | Temperature resolution | 0.01 C | | ||
| | Humidity range | 0 - 100 %RH | | ||
| | Humidity resolution | 0.008 %RH (16-bit ADC) | | ||
| | Interface | I2C / SPI | | ||
| | Chip ID | 0x60 | | ||
|
|
There was a problem hiding this comment.
The Markdown table syntax here uses double leading pipes (|| ...). GitHub-flavored Markdown tables require a single leading pipe per row, so this section will not render as intended. Convert these rows to standard | col | col | table formatting.
There was a problem hiding this comment.
Checked: the tables use standard single-pipe Markdown syntax. No double-pipe issue in the actual source.
| | SDO | Address | | ||
| | ------ | ------- | | ||
| | GND | `0x76` | | ||
| | VDDIO | `0x77` | | ||
|
|
There was a problem hiding this comment.
This I2C address table also uses || at the start of rows, which breaks standard Markdown table rendering. Use the usual single-pipe table row format so it displays correctly.
There was a problem hiding this comment.
Checked: the tables use standard single-pipe Markdown syntax. No double-pipe issue in the actual source.
|
🎉 This PR is included in version 0.7.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #307
Closes #9
Summary
Note:
bme280scope was already added tocommitlint.config.jsin PR #311.Test plan
make test-bme280)ruff check lib/bme280/)