Skip to main content

Meadow.Foundation.Sensors.Light.Si1145

Si1145
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Light.Si1145

The SI1145 is a low power infrared, ultraviolet and ambient light sensor with an I2C interface.

  • Ultraviolet / Infrared / ambient light sensor
  • Proximity sensor
  • Independent LED drivers
  • I2C interface up to 3.4 MBps

Sample projects available on GitHub

Purchasing

The following application reads the sensor output Infrared, Ultraviolet and Visibility once per second and outputs the result on the output console:

Code Example

Si1145 sensor;

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

sensor = new Si1145(Device.CreateI2cBus());

// Example that uses an IObservable subscription to only be notified when the filter is satisfied
var consumer = Si1145.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New.VisibleLight?.Lux:N2}Lux, old: {result.Old?.VisibleLight?.Lux:N2}Lux"),

// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{
// returns true if > 100lux change
return ((result.New.VisibleLight.Value - old.VisibleLight.Value).Abs().Lux > 100);
}
return false;
});

sensor.Subscribe(consumer);

// classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" UV Index: {result.New.UltravioletIndex:N2}Lux");
};

return Task.CompletedTask;
}

public override async Task Run()
{
var (VisibleLight, UltravioletIndex, Infrared) = await sensor.Read();

Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" UV Index: {UltravioletIndex:N2}Lux");

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

Sample project(s) available on GitHub

Wiring Example

Class Si1145

Represents a SiLabs Proximity, UV, and ambient light sensor

Assembly: Si1145.dll
View Source
Declaration
public class Si1145 : ByteCommsSensorBase<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)>, IObservable<IChangeResult<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)>>, ISamplingSensor<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)>, ISensor<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)>, ISensor, ISamplingSensor, IDisposable, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, System.IDisposable, Meadow.Hardware.II2cPeripheral

Properties

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

Methods

ReadSensor()

Read data from the sensor

View Source
Declaration
protected override Task<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)> ReadSensor()
Returns

System.Threading.Tasks.Task<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>: Returns visible, ultraviolet index and infrared data

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Illuminance>,System.Nullable<System.Double>,System.Nullable<Meadow.Units.Illuminance>>>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • System.IDisposable
  • Meadow.Hardware.II2cPeripheral