Remarks

Si1145
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet 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()
{
    Console.WriteLine("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 => Console.WriteLine($"Observer: filter satisifed: {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) { //c# 8 pattern match syntax. checks for !null and assigns var.
                // 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) => {
        Console.WriteLine($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
        Console.WriteLine($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
        Console.WriteLine($" UV Index: {result.New.UltravioletIndex:N2}Lux");
    };

    return Task.CompletedTask;
}

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

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

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

Sample project(s) available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>> SensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>> > Si1145
Implements IDisposable
Inherited Members ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Peripheral ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.ReadBuffer ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.WriteBuffer ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Dispose() SamplingSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.StopUpdating() SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Updated SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.samplingLock SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.SamplingTokenSource SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Conditions SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.IsSampling SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.UpdateInterval SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.ReadSensor() SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.Read() ObservableBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.observers ObservableBase<(Nullable<Illuminance> VisibleLight, Nullable<Double> UltravioletIndex, Nullable<Illuminance> Infrared)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Light
Assembly Si1145.dll

Syntax

public class Si1145 : ByteCommsSensorBase<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)>, IDisposable

Constructors

Si1145(II2cBus)

Create a new SI1145 sensor object.

Declaration
public Si1145(II2cBus i2cBus)

Parameters

Type Name Description
II2cBus i2cBus

I2cBus (default to 400 KHz).

Methods

ReadSensor()

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

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<System.Double>, System.Nullable<Illuminance>>>.ReadSensor()