Crate bme680

source ·
Expand description

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;
extern crate linux_embedded_hal as hal;

use bme680::*;
use embedded_hal::blocking::i2c;
use hal::*;
use std::result;
use std::time::Duration;

fn main() -> result::Result<(), Error<<hal::I2cdev as i2c::Read>::Error, <hal::I2cdev as i2c::Write>::Error>>
{
    // Initialize device
    let i2c = I2cdev::new("/dev/i2c-1").unwrap();
    let mut dev = Bme680::init(i2c, Delay {}, 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(settings)?;

    // Read sensor data
    dev.set_sensor_mode(PowerMode::ForcedMode)?;
    let (data, _state) = dev.get_sensor_data()?;

    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

Driver for the BME680 environmental sensor
Calibration data used during initalization
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.
Contains read sensors values e.g. temperature, pressure, humidity etc.
Gas measurement settings
Stores gas and temperature settings
Builder to construct the desired settings
Temperature settings

Enums

All possible errors in this crate
Shows if new data is available
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); connection it to V DDIO results in slave address 1110111 (0x77), which is the same as BMP280’s I2C address.
IIR filter settings
Over-sampling settings
Power mode settings

Constants

BME680 unique chip identifier
BME680 General config

Type Definitions

Abbreviates std::result::Result type
Tuple of desired sensor settings flags and sensor settings