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 SettingsBuilder to initialize an instance when setting the settings.

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 i2cdetect -y 1 on linux. The 7-bit device address is 111011x. The 6 MSB bits are fixed. The last bit is changeable by SDO value and can be changed during operation. Connecting SDO to GND results in slave address 1110110 (0x76); connecting it to V DDIO results in slave address 1110111 (0x77), which is the same as BMP280’s I2C address.

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 std::result::Result type

Settings

Tuple of desired sensor settings flags and sensor settings