Skip to main content

Meadow.Foundation.mikroBUS.Sensors.Atmospheric.CTempHum15

CTempHum15
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation.mikroBUS.Sensors.Atmospheric.CTempHum15

Code Example

CTempHum15 cTempHum15;

public MeadowApp()
{
Console.WriteLine("Initializing...");

cTempHum15 = new CTempHum15(Device.CreateI2cBus());

var consumer = CTempHum15.CreateObserver(
handler: result =>
{
Console.WriteLine($"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 is { } old)
{
return (
(result.New.Temperature.Value - old.Temperature.Value).Abs().Celsius > 0.5
&&
(result.New.Humidity.Value.Percent - old.Humidity.Value.Percent) > 0.05
);
}
return false;
}
);
cTempHum15.Subscribe(consumer);

cTempHum15.Updated += (sender, result) =>
{
Console.WriteLine($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Console.WriteLine($" Relative Humidity: {result.New.Humidity:N2}%");
};

ReadConditions().Wait();

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

async Task ReadConditions()
{
var conditions = await cTempHum15.Read();
Console.WriteLine("Initial Readings:");
Console.WriteLine($" Temperature: {conditions.Temperature?.Celsius:N2}C");
Console.WriteLine($" Relative Humidity: {conditions.Humidity?.Percent:N2}%");
}

Sample project(s) available on GitHub

Class CTempHum15

Represents a mikroBUS Temp and Hum 15 Click board

Assembly: CTempHum15.dll
View Source
Declaration
public class CTempHum15 : Sht4x, IObservable<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>>, ISamplingSensor<(Temperature? Temperature, RelativeHumidity? Humidity)>, ISensor<(Temperature? Temperature, RelativeHumidity? Humidity)>, IDisposable, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, IHumiditySensor, ISamplingSensor<RelativeHumidity>, ISamplingSensor, ISensor<RelativeHumidity>, ISensor, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>> -> Meadow.Foundation.SamplingSensorBase<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>> -> Meadow.Foundation.PollingSensorBase<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>> -> Meadow.Foundation.ByteCommsSensorBase<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>> -> Meadow.Foundation.Sensors.Atmospheric.Sht4x

Implements:

Expand

System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>, System.IDisposable, Meadow.Peripherals.Sensors.ITemperatureSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.Atmospheric.IHumiditySensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.RelativeHumidity>, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.RelativeHumidity>, Meadow.Peripherals.Sensors.ISensor, Meadow.Hardware.II2cPeripheral

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>
  • System.IDisposable
  • Meadow.Peripherals.Sensors.ITemperatureSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.Atmospheric.IHumiditySensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.RelativeHumidity>
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.RelativeHumidity>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Hardware.II2cPeripheral