Bme680

Struct Bme680 

Source
pub struct Bme680<I2C, STATE> { /* private fields */ }
Expand description

The main BME680 driver structure.

Use Bme680::new(...) or Bme680::with_config(...) to start. The STATE generic uses the Typestate pattern to track initialization status at compile time, preventing invalid API calls.

Implementations§

Source§

impl<I2C> Bme680<I2C, Idle>
where I2C: I2c,

Source

pub fn new(i2c: I2C, address: u8) -> Bme680<I2C, Uninitialized>

Creates a new driver instance in the Uninitialized state.

This method does not yet communicate with the sensor.

§Arguments
  • i2c - The I2C bus object.
  • address - The I2C address of the sensor (typically 0x76 or 0x77).
Source

pub fn with_config( i2c: I2C, address: u8, config: Config, ) -> Bme680<I2C, Uninitialized>

Creates a new driver instance with a pre-defined configuration.

Use the BME680Builder to create the config object.

Source§

impl<I2C> Bme680<I2C, Uninitialized>
where I2C: I2c,

Source

pub fn init(self, delay: &mut impl DelayNs) -> Result<Bme680<I2C, Ready>>

Initializes the sensor: performs a soft-reset and loads factory calibration data.

This consumes the Uninitialized driver and returns a Ready instance.

§Process
  1. Soft Reset.
  2. Apply configuration (oversampling, IIR filter, gas settings).
  3. Read calibration coefficients from ROM.
§Errors

Returns an error if I2C communication fails or if the sensor is unresponsive.

Source§

impl<I2C> Bme680<I2C, Ready>
where I2C: I2c,

Source

pub fn read_new_data(&mut self, delay: &mut impl DelayNs) -> Result<Measurement>

Triggers a full measurement cycle (Forced Mode), waits for completion, and returns the data.

This is the primary method for retrieving sensor data. It handles the entire sequence:

  1. Wakes the sensor (Forced Mode).
  2. Waits for the TPH measurement + Gas Heating duration.
  3. Reads raw ADC data.
  4. Compensates raw values using factory calibration data.
§Power Optimization

If all measurements are set to Skipped and gas is disabled in the Config, this function returns immediately with a default Measurement, avoiding I2C traffic.

Source

pub fn read_chip_id(&mut self) -> Result<u8>

Reads the Chip ID from the sensor.

Used to verify communication. Expected value is usually 0x61.

Source

pub fn update_ambient_temp(&mut self, temp: Celsius) -> Result<()>

Updates the ambient temperature used for gas heater calculation.

Important: To maintain stability, avoid calling this method after every single measurement. Only update if the temperature has changed significantly (e.g. > 1°C), as changes to the heater resistance can cause the gas sensor values to fluctuate temporarily.

Source

pub fn switch_profile(&mut self, profile: GasProfile) -> Result<()>

Switches the active gas profile to a new one.

This updates the configuration, selects the profile on the sensor, and recalculates the heater resistance values.

Trait Implementations§

Source§

impl<I2C: Clone, STATE: Clone> Clone for Bme680<I2C, STATE>

Source§

fn clone(&self) -> Bme680<I2C, STATE>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I2C: Debug, STATE: Debug> Debug for Bme680<I2C, STATE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I2C: Copy, STATE: Copy> Copy for Bme680<I2C, STATE>

Auto Trait Implementations§

§

impl<I2C, STATE> Freeze for Bme680<I2C, STATE>
where I2C: Freeze,

§

impl<I2C, STATE> RefUnwindSafe for Bme680<I2C, STATE>
where I2C: RefUnwindSafe, STATE: RefUnwindSafe,

§

impl<I2C, STATE> Send for Bme680<I2C, STATE>
where I2C: Send, STATE: Send,

§

impl<I2C, STATE> Sync for Bme680<I2C, STATE>
where I2C: Sync, STATE: Sync,

§

impl<I2C, STATE> Unpin for Bme680<I2C, STATE>
where I2C: Unpin, STATE: Unpin,

§

impl<I2C, STATE> UnwindSafe for Bme680<I2C, STATE>
where I2C: UnwindSafe, STATE: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.