Crate bme680[−][src]
This crate is a pure Rust implementation for the BME680 environmental sensor. The library can be used to read the gas, pressure, humidity and temperature sensors via I²C.
The library uses the embedded-hal crate to abstract reading and writing via I²C. In the examples you can find a demo how to use the library in Linux using the linux-embedded-hal crate (e.g. on a RPI).
extern crate bme680; extern crate embedded_hal; // Note that you'll have to import your board crates types corresponding to // Delay and I2cdev. use bme680::*; use embedded_hal::blocking::i2c; use hal::*; use std::result; use std::time::Duration; use std::thread::sleep; fn main() -> result::Result<(), Error<<hal::I2cdev as i2c::Read>::Error, <hal::I2cdev as i2c::Write>::Error>> { // Initialize device let i2c = I2cdev {}; // Your I2C device construction will look different, perhaps using I2cdev::new(..) let mut delayer = Delay {}; // Your Delay construction will look different, perhaps using Delay::new(..) let mut dev = Bme680::init(i2c, &mut delayer, I2CAddress::Primary)?; let settings = SettingsBuilder::new() .with_humidity_oversampling(OversamplingSetting::OS2x) .with_pressure_oversampling(OversamplingSetting::OS4x) .with_temperature_oversampling(OversamplingSetting::OS8x) .with_temperature_filter(IIRFilterSize::Size3) .with_gas_measurement(Duration::from_millis(1500), 320, 25) .with_run_gas(true) .build(); dev.set_sensor_settings(&mut delayer, settings)?; let profile_duration = dev.get_profile_dur(&settings.0)?; // Read sensor data dev.set_sensor_mode(&mut delayer, PowerMode::ForcedMode)?; sleep(profile_duration); let (data, _state) = dev.get_sensor_data(&mut delayer)?; println!("Temperature {}°C", data.temperature_celsius()); println!("Pressure {}hPa", data.pressure_hpa()); println!("Humidity {}%", data.humidity_percent()); println!("Gas Resistence {}Ω", data.gas_resistance_ohm()); Ok(()) }
Structs
Bme680 | Driver for the BME680 environmental sensor |
CalibData | Calibration data used during initalization |
DesiredSensorSettings | Flags that determine what settings are to be set and what settings are to be read.
Use the |
FieldData | Contains read sensors values e.g. temperature, pressure, humidity etc. |
GasSett | Gas measurement settings |
SensorSettings | Stores gas and temperature settings |
SettingsBuilder | Builder to construct the desired settings |
TphSett | Temperature settings |
Enums
Error | All possible errors in this crate |
FieldDataCondition | Shows if new data is available |
I2CAddress | I2C Slave Address
To determine the slave address of your device you can use |
IIRFilterSize | IIR filter settings |
OversamplingSetting | Over-sampling settings |
PowerMode | Power mode settings |
Constants
BME680_CHIP_ID | BME680 unique chip identifier |
BME680_POLL_PERIOD_MS | BME680 General config |
Type Definitions
Result | Abbreviates |
Settings | Tuple of desired sensor settings flags and sensor settings |