VOOZH about

URL: https://www.nuget.org/packages/nanoFramework.Iot.Device.Bh1745/

⇱ NuGet Gallery | nanoFramework.Iot.Device.Bh1745 1.2.952




👁 Image
nanoFramework.Iot.Device.Bh1745 1.2.952

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.952
 
 
NuGet\Install-Package nanoFramework.Iot.Device.Bh1745 -Version 1.2.952
 
 
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.952" />
 
 
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.952" />
 
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.952
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: nanoFramework.Iot.Device.Bh1745, 1.2.952"
 
 
#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.952
 
 
#: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.952
 
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Bh1745&version=1.2.952
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 .

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 Versions Compatible and additional computed target framework versions.
.NET Framework net 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.85 50 6/1/2026
2.0.0-preview.80 51 5/27/2026
2.0.0-preview.73 52 5/20/2026
2.0.0-preview.69 58 5/18/2026
2.0.0-preview.62 55 5/13/2026
2.0.0-preview.49 57 5/4/2026
2.0.0-preview.45 58 4/29/2026
2.0.0-preview.40 60 4/27/2026
2.0.0-preview.32 59 4/20/2026
2.0.0-preview.18 72 3/11/2026
2.0.0-preview.16 58 3/10/2026
1.2.952 138 3/4/2026
1.2.931 337 11/10/2025
1.2.907 288 10/2/2025
1.2.889 272 7/28/2025
1.2.869 382 4/2/2025
1.2.864 328 4/2/2025
1.2.852 339 3/11/2025
1.2.846 354 3/10/2025
1.2.822 320 2/26/2025
Loading failed