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,
impl<I2C> Bme680<I2C, Idle>where
I2C: I2c,
Sourcepub fn new(i2c: I2C, address: u8) -> Bme680<I2C, Uninitialized>
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 (typically0x76or0x77).
Sourcepub fn with_config(
i2c: I2C,
address: u8,
config: Config,
) -> Bme680<I2C, Uninitialized>
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,
impl<I2C> Bme680<I2C, Uninitialized>where
I2C: I2c,
Sourcepub fn init(self, delay: &mut impl DelayNs) -> Result<Bme680<I2C, Ready>>
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
- Soft Reset.
- Apply configuration (oversampling, IIR filter, gas settings).
- 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,
impl<I2C> Bme680<I2C, Ready>where
I2C: I2c,
Sourcepub fn read_new_data(&mut self, delay: &mut impl DelayNs) -> Result<Measurement>
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:
- Wakes the sensor (Forced Mode).
- Waits for the TPH measurement + Gas Heating duration.
- Reads raw ADC data.
- 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.
Sourcepub fn read_chip_id(&mut self) -> Result<u8>
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.
Sourcepub fn update_ambient_temp(&mut self, temp: Celsius) -> Result<()>
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.
Sourcepub fn switch_profile(&mut self, profile: GasProfile) -> Result<()>
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.