-
Notifications
You must be signed in to change notification settings - Fork 3
BME280 driver using custom PIO instead of I2C Wire #67
Open
Description
Context
The current BME280 driver (src/sensors/BME280Driver.h) uses the RP2040's hardware I2C peripheral via Wire/Wire1. This has two limitations:
- GPIO constraints — Hardware I2C0/I2C1 only work on specific GPIO pairs (I2C0: 0/1, 4/5, 8/9, 12/13, 16/17, 20/21; I2C1: 2/3, 6/7, 10/11, 14/15, 18/19, 26/27). A PIO-based implementation would work on any GPIO 0-15, keeping the universal slot promise.
- Library dependency — Uses
<Wire.h>which pulls in the Arduino I2C stack. A custom PIO driver would be self-contained and potentially smaller.
Proposal
Implement a PIO-based I2C bit-bang driver for BME280 that:
- Works on any GPIO pair (not just hardware I2C pins)
- Follows the existing driver pattern (async state machine like DS18B20/DHT22)
- Uses the same compensation formulas already implemented
- Has no external library dependency
References
- BME280 datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
- RP2040 PIO documentation: https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf (Chapter 3)
- Current driver:
src/sensors/BME280Driver.h - Sensor format metadata:
src/sensors/SensorHelpers.h(SensorFormat::forType())
Acceptance
- Compiles with
SIMUT_SENSOR_BME280=1 - BME280 detected and read on any GPIO 0-15 pair
- No
<Wire.h>dependency - Async reads work alongside DS18B20/DHT22 without blocking
- Flash cost ≤ current driver (~7 KB)