Iot: BME680 Reading not working properly (programmer mistake, it's working)

Created on 9 Nov 2019  路  1Comment  路  Source: dotnet/iot

Describe the bug

I tried to experiment with the BME680 device binding but unfortunately the data which is read is not accurate.

Steps to reproduce

Code:

        internal async Task TakeMeasurement()
        {
            if (_sensorState != SensorState.Initialized)
            {
                _logger.LogWarning($"{DateTimeOffset.Now}:BME680: Attempting to take measurement while sensor is not initialized!");
                _measurement.SetMeasurement(Temperature.FromCelsius(-1), -1, -1);
                return;
            }

            /* Force the sensor to take a measurement. */
            _bme680.SetPowerMode(Bme680PowerMode.Forced);

            var temperature = await _bme680.ReadTemperatureAsync();
            var pressure = await _bme680.ReadPressureAsync();
            var humidity = await _bme680.ReadHumidityAsync();
            _measurement.SetMeasurement(temperature, pressure, humidity);

            _logger.LogInformation($"{DateTimeOffset.Now}:BME680: reading");
            _logger.LogInformation(
                $"{temperature.Celsius:N2} \u00B0C | {pressure} hPa | {humidity:N2} %rH");
        }

Expected behavior

I'd expect accurate data when trying to read from the sensor.

Actual behavior

The readings I get are wrong. The temp should be around 25 C

demo

Versions used

Add following information:

Raspberry Pi 2015 armv7 running Raspbian Buster with desktop

<PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>dotnet-NucuCar.BME680Sensor-28FAAD8B-A31F-4BBE-9FF7-30F192D82D6E</UserSecretsId>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Iot.Device.Bindings" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
    <PackageReference Include="System.Device.Gpio" Version="1.0.0" />
</ItemGroup>

bug

Most helpful comment

I forgot to set the sampling.

bme680.SetHumiditySampling(Sampling.UltraLowPower);
                bme680.SetTemperatureSampling(Sampling.LowPower);
                bme680.SetPressureSampling(Sampling.UltraHighResolution);

It works now.

>All comments

I forgot to set the sampling.

bme680.SetHumiditySampling(Sampling.UltraLowPower);
                bme680.SetTemperatureSampling(Sampling.LowPower);
                bme680.SetPressureSampling(Sampling.UltraHighResolution);

It works now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krwq picture krwq  路  6Comments

mskuratowski picture mskuratowski  路  3Comments

ZhangGaoxing picture ZhangGaoxing  路  3Comments

krwq picture krwq  路  4Comments

alex182 picture alex182  路  6Comments