![]() |
VOOZH | about |
dotnet add package nanoFramework.Iot.Device.Tsl256x --version 1.2.991
NuGet\Install-Package nanoFramework.Iot.Device.Tsl256x -Version 1.2.991
<PackageReference Include="nanoFramework.Iot.Device.Tsl256x" Version="1.2.991" />
<PackageVersion Include="nanoFramework.Iot.Device.Tsl256x" Version="1.2.991" />Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Tsl256x" />Project file
paket add nanoFramework.Iot.Device.Tsl256x --version 1.2.991
#r "nuget: nanoFramework.Iot.Device.Tsl256x, 1.2.991"
#:package nanoFramework.Iot.Device.Tsl256x@1.2.991
#addin nuget:?package=nanoFramework.Iot.Device.Tsl256x&version=1.2.991Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Tsl256x&version=1.2.991Install as a Cake Tool
TSL2560 and TSL2561 are illuminance sensor. They are light-to-digital converters that transform light intensity to a digital signal output capable of direct I2C (TSL2561) or SMBus (TSL2560) interface. Each device combines one broadband photodiode (visible plus infrared) and one infrared-responding photodiode on a single CMOS integrated circuit capable of providing a near-photopic response over an effective 20-bit dynamic range (16-bit resolution).
Two integrating ADCs convert the photodiode currents to a digital output that represents the irradiance measured on each channel. This digital output can be input to a microprocessor where illuminance (ambient light level) in lux is derived using an empirical formula to approximate the human eye response.
The TSL2560 device permits an SMB-Alert style interrupt, and the TSL2561 device supports a traditional level style interrupt that remains asserted until the firmware clears it.
TSL2560 and TSL2561 are designed to have an integration time and a gain for measuring the 2 ADC. The defaults are 402 milliseconds and a normal gain of x1.
The basic usage is the following:
I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, Tsl256x.DefaultI2cAddress));
Tsl256x tsl256X = new(i2cDevice, PackageType.Other);
tsl256X.IntegrationTime = IntegrationTime.Integration402Milliseconds;
tsl256X.Gain = Gain.Normal;
var lux = tsl256X.MeasureAndGetIlluminance();
Console.WriteLine($"Illuminance is {lux.Lux} Lux");
notes:
You can determine if you have a TSL2560 or TSL2561 version:
var ver = tsl256X.Version;
string msg = ver.Major & 0x01 == 0x01 ? $"This is a TSL2561, version {ver}" : $"This is a TSL2560, version {ver}";
Console.WriteLine(msg);
You can set interruptions, you have different possible ones you can set thru the InterruptLevel:
The InterruptPersistence will allow you to select a specific timing for the interrupt:
The following example shows how to setup a basic interruption using test mode:
Console.WriteLine("Set interruption to test. Read the interrupt pin");
GpioController controller = new();
controller.OpenPin(PinInterrupt, PinMode.Input);
tsl256X.InterruptControl = InterruptControl.TestMode;
tsl256X.Enabled = true;
while (controller.Read(PinInterrupt) == PinValue.High)
{
Thread.Sleep(1);
}
Console.WriteLine($"Interrupt detected, read the value to clear the interrupt");
tsl256X.GetRawChannels(out ushort ch0, out ushort ch1);
You can setup interruptions on thresholds as well. You first need to setup a threshold and then the type of interruptions.
// Adjust those values with a previous measurement to understand the conditions, find a level where then you can
// hide the sensor with your arm and make it going under the minimum level or vice versa with a lamp
tsl256X.SetThreshold(0x0000, 0x00FF);
tsl256X.InterruptPersistence = InterruptPersistence.OutOfRange06IntegrationTimePeriods;
tsl256X.InterruptControl = InterruptControl.LevelInterrupt;
tsl256X.Power = true;
while (controller.Read(PinInterrupt) == PinValue.High)
{
Thread.Sleep(1);
}
Console.WriteLine($"Interrupt detected, read the value to clear the interrupt");
tsl256X.GetRawChannels(out ch0, out ch1);
Console.WriteLine($"Raw data channel 0 {ch0}, channel 1 {ch1}");
You can set a manual integration as well. Be aware that you won't be able to easily calculate an illuminance equivalent. You need to use the manual integration functions offered:
Console.WriteLine("This will use a manual integration for 2 seconds");
tsl256X.StartManualIntegration();
Thread.Sleep(2000);
tsl256X.StopManualIntegration();
tsl256X.GetRawChannels(out ch0, out ch1);
Console.WriteLine($"Raw data channel 0 {ch0}, channel 1 {ch1}");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net net is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-preview.94 | 50 | 6/22/2026 |
| 2.0.0-preview.85 | 60 | 6/1/2026 |
| 2.0.0-preview.80 | 61 | 5/27/2026 |
| 2.0.0-preview.73 | 56 | 5/20/2026 |
| 2.0.0-preview.69 | 61 | 5/18/2026 |
| 2.0.0-preview.62 | 59 | 5/13/2026 |
| 2.0.0-preview.45 | 62 | 4/29/2026 |
| 2.0.0-preview.32 | 62 | 4/20/2026 |
| 2.0.0-preview.16 | 72 | 3/10/2026 |
| 1.2.991 | 106 | 6/22/2026 |
| 1.2.952 | 135 | 3/4/2026 |
| 1.2.907 | 293 | 10/2/2025 |
| 1.2.889 | 259 | 7/28/2025 |
| 1.2.869 | 374 | 4/2/2025 |
| 1.2.864 | 363 | 4/2/2025 |
| 1.2.852 | 378 | 3/11/2025 |
| 1.2.846 | 383 | 3/10/2025 |
| 1.2.822 | 265 | 2/26/2025 |
| 1.2.775 | 288 | 2/4/2025 |
| 1.2.772 | 308 | 2/4/2025 |