nanoFramework.Iot.Device.Bh1745 1.2.651

Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Bh1745 --version 1.2.651                
NuGet\Install-Package nanoFramework.Iot.Device.Bh1745 -Version 1.2.651                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Bh1745" Version="1.2.651" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Bh1745 --version 1.2.651                
#r "nuget: nanoFramework.Iot.Device.Bh1745, 1.2.651"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Iot.Device.Bh1745 as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Bh1745&version=1.2.651

// Install nanoFramework.Iot.Device.Bh1745 as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Bh1745&version=1.2.651                

Bh1745 - RGB Sensor

The Bh1745 is a digital color sensor able to detect 3 distinct channels of light (red, green, blue) and is most suitable to obtain the illuminance and color temperature of ambient light. The device can detect light intensity in a range of 0.005 to 40 000 lux.

Documentation

Datasheet of the Bh1745

Usage

Important: make sure you properly setup the I2C pins especially for ESP32 before creating the I2cDevice, make sure you install the nanoFramework.Hardware.ESP32 nuget:

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

For other devices like STM32, please make sure you're using the preset pins for the I2C bus you want to use.

2 examples on how to use this device binding are available in the samples folder.

sensor

The quality of the color measurements is very reliant on the lighting. For accurate color readings it is advisable to calibrate the sensor on first use and to use it under stable lighting conditions.

Some breakout boards come with built in LEDs for this purpose (some of the API functionality may also have been repurposed to control these LEDs).

Basic usage:

using System;
using System.Device.I2c;
using System.Threading;
using Iot.Device.Bh1745;

// bus id on the MCU
const int busId = 1;

// create device
I2cConnectionSettings i2cSettings = new(busId, Bh1745.DefaultI2cAddress);
using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);
using Bh1745 i2cBh1745 = new Bh1745(i2cDevice);
// wait for first measurement
Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan());

while (true)
{
    var color = i2cBh1745.GetCompensatedColor();
    Debug.WriteLine("RGB color read: #{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
    Debug.WriteLine($"Raw illumination value: {i2cBh1745.ReadClearDataRegister()}");

    Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan());
}

Advance usage with configuration:

// bus id on the MCU
const int busId = 1;

// create device
var i2cSettings = new I2cConnectionSettings(busId, Bh1745.DefaultI2cAddress);
var i2cDevice = I2cDevice.Create(i2cSettings);

using Bh1745 i2cBh1745 = new Bh1745(i2cDevice)
{
    // multipliers affect the compensated values
    // ChannelCompensationMultipliers:  Red, Green, Blue, Clear
    ChannelCompensationMultipliers = new(2.5, 0.9, 1.9, 9.5),

    // set custom  measurement time
    MeasurementTime = MeasurementTime.Ms1280,

    // interrupt functionality is detailed in the datasheet
    // Reference: https://www.mouser.co.uk/datasheet/2/348/bh1745nuc-e-519994.pdf (page 13)
    LowerInterruptThreshold = 0xABFF,
    HigherInterruptThreshold = 0x0A10,

    LatchBehavior = LatchBehavior.LatchEachMeasurement,
    InterruptPersistence = InterruptPersistence.UpdateMeasurementEnd,
    InterruptIsEnabled = true,
};

// wait for first measurement
Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan());

while (true)
{
    var color = i2cBh1745.GetCompensatedColor();

    if (!i2cBh1745.ReadMeasurementIsValid())
    {
        Debug.WriteLine("Measurement was not valid!");
        continue;
    }

    Debug.WriteLine("RGB color read: #{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
    Debug.WriteLine($"Raw illumination value: {i2cBh1745.ReadClearDataRegister()}");

    Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan());
}
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.651 37 9/27/2024
1.2.639 87 9/6/2024
1.2.631 83 8/28/2024
1.2.613 100 8/9/2024
1.2.601 67 7/26/2024
1.2.590 88 7/17/2024
1.2.580 97 6/28/2024
1.2.573 109 6/19/2024
1.2.570 109 6/14/2024
1.2.560 106 5/29/2024
1.2.548 95 5/15/2024
1.2.536 107 4/15/2024
1.2.514 107 3/22/2024
1.2.494 107 2/28/2024
1.2.474 126 1/24/2024
1.2.462 155 1/5/2024
1.2.458 141 12/20/2023
1.2.436 163 11/10/2023
1.2.416 142 11/8/2023
1.2.403 131 10/6/2023
1.2.396 149 9/27/2023
1.2.384 155 9/6/2023
1.2.378 128 8/16/2023
1.2.369 151 8/2/2023
1.2.363 150 7/28/2023
1.2.357 162 7/19/2023
1.2.354 152 7/14/2023
1.2.345 136 6/21/2023
1.2.341 160 6/14/2023
1.2.337 165 6/7/2023
1.2.335 148 6/2/2023
1.2.329 156 5/26/2023
1.2.313 166 5/12/2023
1.2.308 167 5/11/2023
1.2.304 153 5/10/2023
1.2.302 137 5/10/2023
1.2.297 146 5/3/2023
1.2.273 227 3/17/2023
1.2.267 226 3/10/2023
1.2.263 247 3/8/2023
1.2.259 246 2/27/2023
1.2.256 270 2/24/2023
1.2.253 261 2/22/2023
1.2.236 268 2/13/2023
1.2.222 312 1/9/2023
1.2.217 306 1/6/2023
1.2.212 299 1/5/2023
1.2.208 328 1/3/2023
1.2.203 303 12/28/2022
1.2.159 381 11/14/2022
1.2.153 384 11/5/2022
1.2.141 399 10/25/2022
1.2.128 397 10/22/2022
1.2.122 460 10/12/2022
1.2.114 393 10/8/2022
1.2.95 456 9/22/2022
1.2.87 518 9/15/2022
1.2.73 427 9/8/2022
1.2.63 437 9/3/2022
1.2.47 415 8/15/2022
1.2.40 445 8/6/2022
1.2.38 445 8/5/2022
1.2.32 447 8/2/2022
1.2.28 449 8/1/2022
1.2.13 423 7/24/2022
1.2.10 407 7/23/2022
1.1.145.58726 457 7/7/2022
1.1.133.52556 437 6/30/2022
1.1.121.35854 481 6/26/2022
1.1.116.8772 436 6/24/2022
1.1.113.2032 426 6/23/2022
1.1.102.51394 437 6/15/2022
1.1.99.36719 455 6/14/2022
1.1.97.17326 455 6/13/2022
1.1.92.53000 449 6/8/2022
1.1.72.29765 443 5/31/2022
1.1.64.21380 450 5/26/2022
1.1.58.10097 468 5/23/2022
1.1.54.28879 479 5/23/2022
1.1.40 471 5/5/2022
1.1.3 496 4/15/2022
1.1.1 478 4/14/2022
1.0.300 476 3/31/2022
1.0.288-preview.114 119 3/25/2022
1.0.288-preview.113 113 3/25/2022
1.0.288-preview.110 106 3/25/2022
1.0.288-preview.104 104 3/22/2022
1.0.288-preview.103 107 3/21/2022
1.0.288-preview.100 108 3/19/2022
1.0.288-preview.99 120 3/18/2022
1.0.288-preview.98 112 3/18/2022
1.0.288-preview.93 110 3/15/2022
1.0.288-preview.86 116 3/8/2022
1.0.288-preview.77 115 2/27/2022
1.0.288-preview.75 113 2/26/2022
1.0.288-preview.65 112 2/18/2022
1.0.288-preview.63 109 2/16/2022
1.0.288-preview.61 120 2/12/2022
1.0.288-preview.58 114 2/10/2022
1.0.288-preview.53 106 2/9/2022
1.0.288-preview.48 130 2/4/2022
1.0.288-preview.41 123 1/31/2022
1.0.288-preview.29 129 1/28/2022
1.0.288-preview.22 126 1/27/2022
1.0.288-preview.20 128 1/27/2022
1.0.288-preview.19 127 1/27/2022
1.0.288-preview.18 126 1/27/2022
1.0.288-preview.5 132 1/24/2022
1.0.288-preview.3 125 1/21/2022
1.0.288-preview.1 128 1/21/2022
1.0.272 155 1/10/2022
1.0.270 291 1/6/2022
1.0.260 339 12/10/2021
1.0.259 328 12/9/2021
1.0.258 297 12/7/2021
1.0.218 197 10/18/2021
1.0.155 347 8/31/2021
1.0.136 233 7/17/2021
1.0.135 162 7/16/2021
1.0.134 167 7/15/2021
1.0.133 176 7/14/2021
1.0.130 157 7/6/2021
1.0.129 155 7/6/2021
1.0.125 190 7/5/2021
1.0.121 201 6/29/2021
1.0.119 221 6/28/2021
1.0.40 181 5/24/2021
1.0.23 211 5/21/2021