embassy-bme280-sensor
An async BME280 sensor driver for the Embassy async runtime, designed for embedded systems.
The BME280 is a combined digital humidity, pressure and temperature sensor based on proven sensing principles. This driver provides a high-level async interface for reading environmental data from BME280 sensors over I2C.
Features
- Async/await support - Built for the Embassy async runtime
- Comprehensive configuration - Full control over oversampling, filtering, and sensor modes
- Multiple platform support - Currently supports RP2040, with extensible architecture
- No-std compatible - Designed for embedded systems
- Type-safe configuration - Builder pattern for sensor configuration
- Automatic calibration - Handles sensor calibration data reading and compensation
- Error handling - Comprehensive error types for robust applications
Supported Platforms
- RP2040 (Raspberry Pi Pico and compatible boards)
Hardware Requirements
- BME280 sensor module
- I2C connection (SDA/SCL pins)
- Pull-up resistors on I2C lines (typically 4.7kΩ)
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.8.0"
= "0.9"
= "0.5"
= "1"
= "1"
= { = "1", = ["print-defmt"] }
Basic Usage
use BME280Sensor;
use ;
use BME280Error;
use Spawner;
use I2C0;
use ;
use ;
use ;
use defmt_rtt as _;
use panic_probe as _;
bind_interrupts!;
async !
Configuration Options
Oversampling
Control the precision and power consumption of measurements:
use Oversampling;
// Available options:
Skip // Skip measurement
X1 // 1x oversampling (fastest, lowest power)
X2 // 2x oversampling
X4 // 4x oversampling
X8 // 8x oversampling
X16 // 16x oversampling (most precise, highest power)
Sensor Modes
use SensorMode;
Sleep // Low power mode, no measurements
Forced // Single measurement then sleep
Normal // Continuous measurements
Standby Duration
Control the interval between measurements in normal mode:
use StandbyDuration;
Millis0_5 // 0.5ms
Millis10 // 10ms
Millis20 // 20ms
Millis62_5 // 62.5ms
Millis125 // 125ms
Millis250 // 250ms
Millis500 // 500ms
Millis1000 // 1000ms
Filtering
Apply digital filtering to reduce noise:
use Filter;
Off // No filtering
X2 // 2x filtering
X4 // 4x filtering
X8 // 8x filtering
X16 // 16x filtering
Data Structure
The sensor returns a BME280Response struct:
Error Handling
The driver provides comprehensive error handling:
I2C Address
The BME280 supports two I2C addresses:
0x76(default, SDO pin connected to GND)0x77(SDO pin connected to VCC)
Examples
See the examples/ directory for complete working examples:
read-bme280-sensor-rp.rs- Basic sensor reading example for RP2040
To run the example:
Hardware Connections
RP2040 (Raspberry Pi Pico)
| BME280 Pin | RP2040 Pin | Description |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
| SCL | GP1 | I2C Clock |
| SDA | GP0 | I2C Data |
| SDO | GND | I2C Address select (0x76) |
Performance Considerations
- Oversampling: Higher oversampling provides better accuracy but increases measurement time and power consumption
- Filtering: Digital filtering reduces noise but adds latency
- Standby duration: Longer standby periods reduce power consumption in normal mode
- Measurement time: Typical measurement times range from 1ms (1x oversampling) to 20ms (16x oversampling)
License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Acknowledgments
- Bosch Sensortec for the BME280 sensor
- Embassy for the excellent async runtime
- The embedded Rust community for inspiration and support