Meadow.Foundation.Sensors.Atmospheric.Bh1900Nux
Bh1900Nux | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Bh1900Nux _sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
_sensor = new Bh1900Nux(Device.CreateI2cBus(), Bh1900Nux.Addresses.Default);
var consumer = Bh1900Nux.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Celsius:N2}C, old: {result.Old?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old is { } old)
{
return (result.New - old).Abs().Celsius > 0.5;
}
return false;
}
);
_sensor.Subscribe(consumer);
_sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Celsius:N2}C");
};
return Task.CompletedTask;
}
public async override Task Run()
{
var conditions = await _sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" 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 |