marcelbuesing / bme680

Pure Rust BME680 implementation
MIT License
29 stars 28 forks source link

BME688 gives constant humidity and gas readings #42

Open mihai-dinculescu opened 2 years ago

mihai-dinculescu commented 2 years ago

Using an Adafruit BME688 with version 0.6.0 of this lib and the example code, I always get constant readings for humidity and gas. Temperature and Pressure do slightly change and seem to be correct.

FieldData { status: 176, gas_index: 0, meas_index: 0, temperature: 2222, pressure: 103645, humidity: 100000, gas_resistance: 12917167 }
mihai-dinculescu commented 2 years ago

Getting the same behavior with an Adafruit BME680 as well.

Here's my code.

fn main() -> anyhow::Result<()> {
    esp_idf_sys::link_patches();

    log::set_logger(&LOGGER).map(|()| LOGGER.initialize())?;
    LOGGER.set_target_level("", log::LevelFilter::Debug);

    let peripherals = Peripherals::take().context("failed to get peripherals")?;
    let pins = peripherals.pins;

    let mut delayer = delay::FreeRtos;

    let i2c_config = <i2c::config::MasterConfig as Default>::default();

    let i2c_master = i2c::Master::<i2c::I2C0, _, _>::new(
        peripherals.i2c0,
        i2c::MasterPins {
            sda: pins.gpio23,
            scl: pins.gpio22,
        },
        i2c_config,
    )?;

    let mut sensor: Bme680<_, FreeRtos> =
        Bme680::init(i2c_master, &mut delayer, I2CAddress::Secondary).unwrap();

    let settings = SettingsBuilder::new()
        .with_humidity_oversampling(OversamplingSetting::OS16x)
        .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_temperature_offset(-2.2)
        .with_run_gas(true)
        .build();

    let profile_dur = sensor.get_profile_dur(&settings.0).unwrap();
    info!("Profile duration {:?}", profile_dur);

    info!("Setting sensor settings");
    sensor.set_sensor_settings(&mut delayer, settings).unwrap();

    let sensor_settings = sensor.get_sensor_settings(settings.1);
    info!("Sensor settings: {:?}", sensor_settings);

    loop {
        delayer.delay_ms(5 * 1000u32);

        let power_mode = sensor.get_sensor_mode();
        info!("Sensor power mode: {:?}", power_mode);

        info!("Setting forced power modes");
        sensor
            .set_sensor_mode(&mut delayer, PowerMode::ForcedMode)
            .unwrap();

        // Something I've tried
        // delayer.delay_ms(profile_dur.as_millis() as u32);

        // Something else I've tried
        // while sensor.get_sensor_mode().unwrap() == PowerMode::SleepMode {
        //     sensor
        //         .set_sensor_mode(&mut delayer, PowerMode::ForcedMode)
        //         .unwrap();
        // }

        let (data, _state) = sensor.get_sensor_data(&mut delayer).unwrap();
        info!("Sensor Data {:?}", data);
        info!("Temperature {}°C", data.temperature_celsius());
        info!("Pressure {}hPa", data.pressure_hpa());
        info!("Humidity {}%", data.humidity_percent());
        info!("Gas Resistence {}Ω", data.gas_resistance_ohm());
    }
}
haflinger commented 1 year ago

Same behavior with and without #43 😭

Humidity seems to be correct when I remove :

.with_temperature_oversampling(OversamplingSetting::OS8x)
.with_temperature_filter(IIRFilterSize::Size3)

Any ideas ?