bme680-driver
Table of Contents
Overview
A type-safe, no_std Rust driver for the Bosch BME680 environmental sensor. It provides high-level access to temperature, humidity, atmospheric pressure, and gas resistance measurements using the embedded-hal traits.
Features
- Power Saving: Individually enable/disable gas, pressure, temperature, or humidity measurements to reduce power consumption.
- Typestate Pattern: Prevents illegal sensor states and ensures correct initialization.
- Fixed-Point Arithmetic: High-performance compensation formulas without the need for a floating-point unit (FPU).
- Type-Safe Units: Uses custom types like
CelsiusandMillisecondsto prevent unit-mixing errors. - No-Std: Suitable for all bare-metal microcontrollers (STM32, ESP32, AVR, etc.).
Repository Structure
Installation
Add this to your Cargo.toml:
[]
= "0.3.0"
Quick Start (STM32 Example)
use *;
// --- 1. Sensor-Konfiguration via Builder ---
// Wir definieren ein Profil für die Gassensor-Heizplatte.
let gas_profile = GasProfile ;
let config = new
.temp_oversampling
.hum_oversampling
.pres_oversampling // Druckmessung deaktiviert
.gas_profile
.ambient_temp // Erste Schätzung: 21.00°C
.build;
// --- 2. Initialisierung (Typestate: Uninitialized -> Ready) ---
// I2C und Delay kommen von deinem HAL (z.B. stm32f4xx-hal)
let mut bme = with_config
.init
.expect;
// Tracking für die Heizungskompensation
let mut last_heater_update_temp = Celsius;
loop
Units and Precision
| Measurement | Unit | Scaling | Example |
|---|---|---|---|
| Temperature | Celsius | T * 100 | 2350 = 23.50 °C |
| Humidity | % Relative Humidity | H * 1000 | 45123 = 45.123 % |
| Pressure | Pascal (Pa) | 1.0 | 101325 Pa = 1013.25 hPa |
| Gas Resistance | Ohm (Ω) | 1.0 | 45000 = 45 kΩ |
License
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)
at your option.