Remarks
Si1145 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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
Syntax
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)>, IDisposable, II2cPeripheral
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) |
Remarks
Si1145 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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
Properties
DefaultI2cAddress
The default I2C address for the peripheral
Declaration
public byte DefaultI2cAddress { get; }
Property Value
Type | Description |
---|---|
byte |
Remarks
Si1145 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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
Methods
ReadSensor()
Read data from the sensor
Declaration
protected override Task<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)> ReadSensor()
Returns
Type | Description |
---|---|
Task<(Illuminance? VisibleLight, double? UltravioletIndex, Illuminance? Infrared)> | Returns visible, ultraviolet index and infrared data |
Overrides
Remarks
Si1145 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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