nanoFramework.Iot.Device.Bh1745 1.2.1027

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.Bh1745 --version 1.2.1027
                    
NuGet\Install-Package nanoFramework.Iot.Device.Bh1745 -Version 1.2.1027
                    
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.1027" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.Bh1745" Version="1.2.1027" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Bh1745" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.Iot.Device.Bh1745 --version 1.2.1027
                    
#r "nuget: nanoFramework.Iot.Device.Bh1745, 1.2.1027"
                    
#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.
#:package nanoFramework.Iot.Device.Bh1745@1.2.1027
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.Iot.Device.Bh1745&version=1.2.1027
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Bh1745&version=1.2.1027
                    
Install as a Cake Tool

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
2.0.0-preview.109 49 7/13/2026
2.0.0-preview.102 60 7/6/2026
2.0.0-preview.94 70 6/22/2026
2.0.0-preview.85 64 6/1/2026
2.0.0-preview.80 64 5/27/2026
2.0.0-preview.73 64 5/20/2026
2.0.0-preview.69 71 5/18/2026
2.0.0-preview.62 65 5/13/2026
2.0.0-preview.49 64 5/4/2026
2.0.0-preview.45 66 4/29/2026
2.0.0-preview.40 69 4/27/2026
2.0.0-preview.32 69 4/20/2026
2.0.0-preview.18 82 3/11/2026
2.0.0-preview.16 67 3/10/2026
1.2.1027 98 8/3/2026
1.2.1016 225 7/13/2026
1.2.1002 118 7/1/2026
1.2.994 126 6/24/2026
1.2.991 128 6/22/2026
1.2.952 154 3/4/2026
Loading failed