Remarks

Bme680
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Atmospheric.Bme68x

Code Example

Bme680? sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    //CreateSpiSensor();
    CreateI2CSensor();

    //uncomment to enable on sensor heater for gas readings
    //EnableGasHeater();

    var consumer = Bme680.CreateObserver(
        handler: result =>
        {
            Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old?.Temperature is { } oldTemp &&
                result.Old?.Humidity is { } oldHumidity &&
                result.New.Temperature is { } newTemp && 
                result.New.Humidity is { } newHumidity)
            {
                return ((newTemp - oldTemp).Abs().Celsius > 0.5 &&
                        (newHumidity - oldHumidity).Percent > 0.05);
            }
            return false;
        }
    );

    sensor?.Subscribe(consumer);

    if(sensor != null)
    {
        sensor.Updated += (sender, result) =>
        {
            Resolver.Log.Info($"  Temperature: {result.New.Temperature?.Celsius:N2}C");
            Resolver.Log.Info($"  Relative Humidity: {result.New.Humidity:N2}%");
            Resolver.Log.Info($"  Pressure: {result.New.Pressure?.Millibar:N2}mbar ({result.New.Pressure?.Pascal:N2}Pa)");
            if (sensor.GasConversionIsEnabled)
            {
                Resolver.Log.Info($"  Gas Resistance: {result.New.GasResistance:N0}Ohms");
            }
        };
    }

    sensor?.StartUpdating(TimeSpan.FromSeconds(2));

    ReadConditions().Wait();

    return base.Initialize();
}

void EnableGasHeater()
{
    if(sensor != null)
    {
        sensor.GasConversionIsEnabled = true;
        sensor.HeaterIsEnabled = true;
        sensor.ConfigureHeatingProfile(Bme688.HeaterProfileType.Profile1, new Meadow.Units.Temperature(300), TimeSpan.FromMilliseconds(100), new Meadow.Units.Temperature(22));
        sensor.HeaterProfile = Bme688.HeaterProfileType.Profile1;
    }
}

void CreateSpiSensor()
{
    Resolver.Log.Info("Create BME680 sensor with SPI...");

    var spiBus = Device.CreateSpiBus();
    sensor = new Bme680(spiBus, Device.CreateDigitalOutputPort(Device.Pins.D14));
}

void CreateI2CSensor()
{
    Resolver.Log.Info("Create BME680 sensor with I2C...");

    var i2c = Device.CreateI2cBus();
    sensor = new Bme680(i2c, (byte)Bme688.Addresses.Address_0x76);
}

async Task ReadConditions()
{
    if(sensor == null) { return; }

    var (Temperature, Humidity, Pressure, Resistance) = await sensor.Read();

    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($"  Temperature: {Temperature?.Celsius:N2}C");
    Resolver.Log.Info($"  Pressure: {Pressure?.Hectopascal:N2}hPa");
    Resolver.Log.Info($"  Relative Humidity: {Humidity?.Percent:N2}%");
    Resolver.Log.Info($"  Gas Resistance: {Resistance?.Ohms:N0}Ohms");
}

Sample project(s) available on GitHub

Wiring Example

To wire a Bme680 to your Meadow board, connect the following:

<img src="../../API_Assets/Meadow.Foundation.Sensors.Atmospheric.Bme680/Bme680_Fritzing.png"

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>> PollingSensorBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>> Bme68x > Bme680
Implements ISamplingSensor<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>> ISamplingSensor<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>> ITemperatureSensor IHumiditySensor IBarometricPressureSensor
Inherited Members Bme68x.TemperatureUpdated Bme68x.PressureUpdated Bme68x.HumidityUpdated Bme68x.GasResistanceUpdated Bme68x.TemperatureOversampleMode Bme68x.PressureOversampleMode Bme68x.HumidityOversampleMode Bme68x.HeaterProfile Bme68x.FilterMode Bme68x.HeaterIsEnabled Bme68x.GasConversionIsEnabled Bme68x.Temperature Bme68x.Pressure Bme68x.Humidity Bme68x.GasResistance Bme68x.Initialize() Bme68x.Reset() Bme68x.ConfigureHeatingProfile(Bme68x.HeaterProfileType, Units.Temperature, TimeSpan, Units.Temperature) Bme68x.GetPowerMode() Bme68x.SetPowerMode(Bme68x.PowerMode) Bme68x.GetMeasurementDuration(Bme68x.HeaterProfileType) Bme68x.RaiseEventsAndNotify(IChangeResult<ValueTuple<Nullable<Units.Temperature>, Nullable<RelativeHumidity>, Nullable<Pressure>, Nullable<Resistance>>>) Bme68x.ReadSensor() Bme68x.CompensateTemperature(Int32) PollingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.StartUpdating(Nullable<TimeSpan>) PollingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.StopUpdating() SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.samplingLock SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.Updated SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.SamplingTokenSource SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.Conditions SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.IsSampling SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.UpdateInterval SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.ReadSensor() SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.Read() ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.observers ObservableBase<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity, Nullable<Pressure> Pressure, Nullable<Resistance> GasResistance)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>, System.Nullable<Pressure>, System.Nullable<Resistance>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Bme68x.dll

Syntax

public class Bme680 : Bme68x, ISamplingSensor<(Units.Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)>, ISamplingSensor<(Units.Temperature? Temperature, RelativeHumidity? Humidity, Pressure? Pressure, Resistance? GasResistance)>, ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor

Constructors

Bme680(II2cBus, Byte)

Creates a new instance of the Bme680 class

Declaration
public Bme680(II2cBus i2cBus, byte address = null)

Parameters

Type Name Description
II2cBus i2cBus

I2C Bus to use for communicating with the sensor

System.Byte address

I2C address of the sensor

Bme680(ISpiBus, IDigitalOutputPort, Bme68x.Configuration)

Creates a new instance of the Bme680 class

Declaration
public Bme680(ISpiBus spiBus, IDigitalOutputPort chipSelectPort, Bme68x.Configuration configuration = null)

Parameters

Type Name Description
ISpiBus spiBus

The SPI bus connected to the device

IDigitalOutputPort chipSelectPort

The chip select pin

Bme68x.Configuration configuration

The BMP68x configuration (optional)

Bme680(ISpiBus, IPin)

Creates a new instance of the Bme680 class

Declaration
public Bme680(ISpiBus spiBus, IPin chipSelectPin)

Parameters

Type Name Description
ISpiBus spiBus

The SPI bus connected to the device

IPin chipSelectPin

The chip select pin