Remarks

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

Code Example

private Bh1900Nux _sensor;

public override Task Initialize()
{
    Console.WriteLine("Initializing...");

    _sensor = new Bh1900Nux(Device.CreateI2cBus(), Bh1900Nux.Address.Default);

    var consumer = Bh1900Nux.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer: Temp changed by threshold; new temp: {result.New.Celsius:N2}C, old: {result.Old?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Celsius > 0.5;
            }
            return false;
        }
    );
    _sensor.Subscribe(consumer);

    _sensor.Updated += (sender, result) =>
    {
        Console.WriteLine($"  Temperature: {result.New.Celsius:N2}C");
    };

    return Task.CompletedTask;
}

public async override Task Run()
{
    var conditions = await _sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"  Temperature: {conditions.Celsius:N2}C");

    _sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

To wire a Adafruit Bh1900Nux Sensor to your Meadow board, connect the following:

Bh1900Nux Meadow Pin
GND GND
VCC 3.3V
SCL D08
SDA D07
Characteristic Locus
Inheritance System.Object ObservableBase<Units.Temperature> SensorBase<Units.Temperature> SamplingSensorBase<Units.Temperature> ByteCommsSensorBase<Units.Temperature> > Bh1900Nux
Implements ISamplingSensor<Units.Temperature> IDisposable ITemperatureSensor
Inherited Members ByteCommsSensorBase<Units.Temperature>.Peripheral ByteCommsSensorBase<Units.Temperature>.ReadBuffer ByteCommsSensorBase<Units.Temperature>.WriteBuffer ByteCommsSensorBase<Units.Temperature>.Init(Int32, Int32) ByteCommsSensorBase<Units.Temperature>.Dispose(Boolean) ByteCommsSensorBase<Units.Temperature>.Dispose() SamplingSensorBase<Units.Temperature>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<Units.Temperature>.StopUpdating() SensorBase<Units.Temperature>.Updated SensorBase<Units.Temperature>.samplingLock SensorBase<Units.Temperature>.SamplingTokenSource SensorBase<Units.Temperature>.Conditions SensorBase<Units.Temperature>.IsSampling SensorBase<Units.Temperature>.UpdateInterval SensorBase<Units.Temperature>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<Units.Temperature>.Read() ObservableBase<Units.Temperature>.observers ObservableBase<Units.Temperature>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Units.Temperature>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Units.Temperature>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Bh1900Nux.dll

Syntax

public class Bh1900Nux : ByteCommsSensorBase<Units.Temperature>, ISamplingSensor<Units.Temperature>, IDisposable, ITemperatureSensor

Constructors

Bh1900Nux(II2cBus, Bh1900Nux.Address)

Create a new Bh1900Nux object

Declaration
public Bh1900Nux(II2cBus i2cBus, Bh1900Nux.Address address)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus

Bh1900Nux.Address address

The I2C address

Bh1900Nux(II2cBus, Byte)

Create a new Bh1900Nux object

Declaration
public Bh1900Nux(II2cBus i2cBus, byte address)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus

System.Byte address

The I2C address

Properties

AlertIsActive

Is the alert active

Declaration
public bool AlertIsActive { get; }

Property Value

Type Description
System.Boolean

AlertPolarity

The alert polarity

Declaration
public Bh1900Nux.Polarity AlertPolarity { get; set; }

Property Value

Type Description
Bh1900Nux.Polarity

FaultQueueDepth

The fault queue depth

Declaration
public Bh1900Nux.FaultQueue FaultQueueDepth { get; set; }

Property Value

Type Description
Bh1900Nux.FaultQueue

HighLimit

The temperature high limit

Declaration
public Units.Temperature HighLimit { get; set; }

Property Value

Type Description
Units.Temperature

LowLimit

The temperture low limit

Declaration
public Units.Temperature LowLimit { get; set; }

Property Value

Type Description
Units.Temperature

MeasurementMode

The measurement mode

Declaration
public Bh1900Nux.MeasurementModes MeasurementMode { get; set; }

Property Value

Type Description
Bh1900Nux.MeasurementModes

Temperature

The current temperature

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

Methods

RaiseEventsAndNotify(IChangeResult<Units.Temperature>)

Raise events for subcribers and notify of value changes

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Units.Temperature> changeResult)

Parameters

Type Name Description
IChangeResult<Units.Temperature> changeResult

The updated sensor data

ReadSensor()

Read the temperature

Declaration
protected override Task<Units.Temperature> ReadSensor()

Returns

Type Description
Task<Units.Temperature>

The current temperature value

Overrides

Meadow.Foundation.SensorBase<Units.Temperature>.ReadSensor()

Reset()

Reset the sensor

Declaration
public void Reset()

Sleep()

Set the sensor to sleep state

Declaration
public void Sleep()

Wake()

Wake the device

Declaration
public void Wake()

Events

TemperatureUpdated

Raised when the temperature value changes

Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>