nanoFramework.Iot.Device.Tsl256x
1.2.704
Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Tsl256x --version 1.2.704
NuGet\Install-Package nanoFramework.Iot.Device.Tsl256x -Version 1.2.704
<PackageReference Include="nanoFramework.Iot.Device.Tsl256x" Version="1.2.704" />
paket add nanoFramework.Iot.Device.Tsl256x --version 1.2.704
#r "nuget: nanoFramework.Iot.Device.Tsl256x, 1.2.704"
// Install nanoFramework.Iot.Device.Tsl256x as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Tsl256x&version=1.2.704 // Install nanoFramework.Iot.Device.Tsl256x as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Tsl256x&version=1.2.704
TSL256x/TSL2560/TSL2561 - Illuminance sensor
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.
Documentation
- TSL256x datasheet
Board
Usage
Basic usage
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:
- Be aware, there are 2 types of packaging the CS and the Others T, FN and CL. Refer to the documentation to understand which package you have on the board. This is an argument when creating the sensor as the calculation for the illuminance is different.
- There are 3 different possible I2C addresses for this device depending on how the address pin is setup:
- DefaultI2cAddress = 0x39: When address pin is to the ground
- SecondI2cAddress = 0x29: When address pin is floating
- ThirdI2cAddress = 0x49: When address pin is to VDD
Check the version
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);
Using interruptions
You can set interruptions, you have different possible ones you can set thru the InterruptLevel
:
- OutputDisabled: will disable the interrupt
- LevelInterrupt: will use the permanent interrupt you'll setup, see right after
- SmbAlertCompliant: will send an alert on the SMB bus (version TSL2560 only) on address 0b0000_1100
- TestMode: will generate an interruption for test purpose
The InterruptPersistence
will allow you to select a specific timing for the interrupt:
- EveryAdc: each time you have a measurement
- AnyValueOutsideThreshold: any time a value will be outside of the setup threshold
- OutOfRangeXXIntegrationTimePeriods: where XX is from 2 to 15, will interrupt only if the value remains outside more than XX times
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}");
Manual integration
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 is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.System.Buffers.Binary.BinaryPrimitives (>= 1.2.699)
- nanoFramework.System.Device.I2c (>= 1.1.16)
- nanoFramework.System.Device.Model (>= 1.2.693)
- nanoFramework.System.Math (>= 1.5.43)
- UnitsNet.nanoFramework.Illuminance (>= 5.61.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.704 | 76 | 12/18/2024 |
1.2.696 | 72 | 12/16/2024 |
1.2.673 | 81 | 10/23/2024 |
1.2.656 | 98 | 10/3/2024 |
1.2.639 | 123 | 9/6/2024 |
1.2.631 | 101 | 8/28/2024 |
1.2.613 | 114 | 8/9/2024 |
1.2.601 | 79 | 7/26/2024 |
1.2.590 | 95 | 7/17/2024 |
1.2.573 | 118 | 6/19/2024 |
1.2.570 | 116 | 6/14/2024 |
1.2.536 | 124 | 4/15/2024 |
1.2.534 | 122 | 4/13/2024 |
1.2.514 | 120 | 3/22/2024 |
1.2.494 | 117 | 2/28/2024 |
1.2.462 | 201 | 1/5/2024 |
1.2.458 | 132 | 12/20/2023 |
1.2.436 | 175 | 11/10/2023 |
1.2.416 | 111 | 11/8/2023 |
1.2.403 | 150 | 10/6/2023 |
1.2.396 | 151 | 9/27/2023 |
1.2.384 | 152 | 9/6/2023 |
1.2.378 | 164 | 8/16/2023 |
1.2.369 | 165 | 8/2/2023 |
1.2.363 | 159 | 7/28/2023 |
1.2.357 | 169 | 7/19/2023 |
1.2.354 | 173 | 7/14/2023 |
1.2.345 | 161 | 6/21/2023 |
1.2.341 | 164 | 6/14/2023 |
1.2.337 | 181 | 6/7/2023 |
1.2.335 | 170 | 6/2/2023 |
1.2.329 | 167 | 5/26/2023 |
1.2.316 | 173 | 5/16/2023 |
1.2.313 | 176 | 5/12/2023 |
1.2.302 | 181 | 5/10/2023 |
1.2.297 | 160 | 5/3/2023 |
1.2.273 | 265 | 3/17/2023 |
1.2.267 | 272 | 3/10/2023 |
1.2.263 | 253 | 3/8/2023 |
1.2.259 | 282 | 2/27/2023 |
1.2.256 | 288 | 2/24/2023 |
1.2.253 | 278 | 2/22/2023 |
1.2.222 | 322 | 1/9/2023 |
1.2.217 | 320 | 1/6/2023 |
1.2.212 | 311 | 1/5/2023 |
1.2.208 | 340 | 1/3/2023 |
1.2.203 | 330 | 12/28/2022 |
1.2.159 | 398 | 11/14/2022 |
1.2.153 | 384 | 11/5/2022 |
1.2.141 | 418 | 10/25/2022 |
1.2.128 | 413 | 10/22/2022 |
1.2.125 | 425 | 10/12/2022 |
1.2.87 | 526 | 9/15/2022 |
1.2.63 | 434 | 9/3/2022 |
1.2.47 | 449 | 8/15/2022 |
1.2.40 | 445 | 8/6/2022 |
1.2.38 | 448 | 8/5/2022 |
1.2.28 | 427 | 8/1/2022 |
1.2.13 | 460 | 7/24/2022 |
1.2.10 | 452 | 7/23/2022 |
1.1.142.3202 | 484 | 7/7/2022 |
1.1.133.52556 | 463 | 6/30/2022 |
1.1.121.35854 | 473 | 6/26/2022 |
1.1.118.19693 | 471 | 6/24/2022 |
1.1.116.8772 | 459 | 6/24/2022 |
1.1.102.51394 | 441 | 6/15/2022 |
1.1.99.36719 | 443 | 6/14/2022 |
1.1.97.17326 | 461 | 6/13/2022 |
1.1.92.53000 | 453 | 6/8/2022 |
1.1.72.29765 | 459 | 5/31/2022 |
1.1.61.27737 | 467 | 5/25/2022 |
1.1.58.10097 | 466 | 5/23/2022 |
1.1.54.28879 | 458 | 5/23/2022 |
1.1.40 | 480 | 5/5/2022 |
1.1.3 | 463 | 4/15/2022 |
1.1.1 | 482 | 4/14/2022 |
1.0.300 | 472 | 4/3/2022 |
1.0.288-preview.113 | 130 | 3/25/2022 |
1.0.288-preview.107 | 120 | 3/24/2022 |
1.0.288-preview.104 | 116 | 3/22/2022 |
1.0.288-preview.103 | 118 | 3/21/2022 |
1.0.288-preview.99 | 127 | 3/18/2022 |
1.0.288-preview.94 | 129 | 3/15/2022 |
1.0.288-preview.77 | 127 | 2/27/2022 |
1.0.288-preview.75 | 120 | 2/26/2022 |
1.0.288-preview.63 | 125 | 2/16/2022 |
1.0.288-preview.61 | 126 | 2/12/2022 |
1.0.288-preview.58 | 124 | 2/10/2022 |
1.0.288-preview.53 | 128 | 2/9/2022 |
1.0.288-preview.48 | 139 | 2/4/2022 |
1.0.288-preview.41 | 141 | 1/31/2022 |
1.0.288-preview.22 | 129 | 1/27/2022 |
1.0.288-preview.20 | 141 | 1/27/2022 |
1.0.288-preview.18 | 144 | 1/27/2022 |
1.0.272 | 496 | 1/10/2022 |
1.0.260 | 337 | 12/10/2021 |
1.0.259 | 340 | 12/9/2021 |
1.0.258 | 324 | 12/7/2021 |
1.0.231 | 349 | 10/27/2021 |