Remarks

Bh1745
Status
Source code GitHub
NuGet package

The BH1745 is a RGB color and luminance sensor that communicates over I2C.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Bh1745 sensor;
    RgbPwmLed rgbLed;

    public MeadowApp()
    {
        sensor = new Bh1745(Device.CreateI2cBus());
        rgbLed = new RgbPwmLed(
            Device,
            Device.Pins.OnboardLedRed,
            Device.Pins.OnboardLedGreen,
            Device.Pins.OnboardLedBlue,
            CommonType.CommonAnode);

        Thread.Sleep((int)sensor.MeasurementTime);

        Console.WriteLine("Read color values");

        Color color;

        while (true)
        {
            color = sensor.GetColor();

            Console.WriteLine($"Color: {color.R}, {color.G}, {color.B}");

            //quantize color for RGB to make color detection more obvious
            color = new Color(GetQuantizedValue(color.R),
                                GetQuantizedValue(color.G),
                                GetQuantizedValue(color.B));

            rgbLed.SetColor(color);

            Thread.Sleep(100);
        }
    }

    public double GetQuantizedValue(double value)
    {
        if (value < 0.3)
            return 0;
        if (value < 0.8)
            return 0.5;
        return 1;
    }
}

Sample projects available on GitHub

Wiring Example

To wire a Bh1745 to your Meadow board, connect the following:

Bh1745 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > Bh1745
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Light
Assembly Bh1745.dll

Syntax

public class Bh1745

Constructors

Bh1745(II2cBus, Byte)

Create a new BH17545 color sensor object

Declaration
public Bh1745(II2cBus i2cBus, byte address = 56)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Properties

AdcGain

Gets or sets the ADC gain of the sensor

Declaration
public Bh1745.AdcGainType AdcGain { get; set; }

Property Value

Type Description
Bh1745.AdcGainType

CompensationMultipliers

Gets or sets the channel compensation multipliers which are used to scale the channel measurements

Declaration
public Bh1745.ChannelMultipliers CompensationMultipliers { get; set; }

Property Value

Type Description
Bh1745.ChannelMultipliers

InterruptIsEnabled

Gets or sets whether the interrupt pin is enabled

Declaration
public bool InterruptIsEnabled { get; set; }

Property Value

Type Description
System.Boolean

InterruptPersistence

Gets or sets the persistence function of the interrupt

Declaration
public Bh1745.InterruptType InterruptPersistence { get; set; }

Property Value

Type Description
Bh1745.InterruptType

InterruptReset

Declaration
public Bh1745.InterruptStatus InterruptReset { get; set; }

Property Value

Type Description
Bh1745.InterruptStatus

InterruptSignalIsActive

Is the interrupt active

Declaration
public bool InterruptSignalIsActive { get; }

Property Value

Type Description
System.Boolean

InterruptSource

Gets or sets the source channel that triggers the interrupt

Declaration
public Bh1745.InterruptChannel InterruptSource { get; set; }

Property Value

Type Description
Bh1745.InterruptChannel

IsMeasurementActive

Is the sensor actively measuring

Declaration
public bool IsMeasurementActive { get; set; }

Property Value

Type Description
System.Boolean

LatchBehavior

Gets or sets how the interrupt pin latches

Declaration
public Bh1745.LatchBehaviorType LatchBehavior { get; set; }

Property Value

Type Description
Bh1745.LatchBehaviorType

LowerInterruptThreshold

Gets or sets the lower interrupt threshold

Declaration
public ushort LowerInterruptThreshold { get; set; }

Property Value

Type Description
System.UInt16

MeasurementTime

Gets or sets the currently set measurement time.

Declaration
public Bh1745.MeasurementTimeType MeasurementTime { get; set; }

Property Value

Type Description
Bh1745.MeasurementTimeType

PrimaryI2cAddress

The primary I2c address of the BH1745

Declaration
public static byte PrimaryI2cAddress { get; }

Property Value

Type Description
System.Byte

SecondaryI2cAddress

The secondary I2c address of the BH1745

Declaration
public static byte SecondaryI2cAddress { get; }

Property Value

Type Description
System.Byte

UpperInterruptThreshold

Gets or sets the upper interrupt threshold

Declaration
public ushort UpperInterruptThreshold { get; set; }

Property Value

Type Description
System.UInt16

Methods

GetColor()

Gets the compensated color reading from the sensor

Declaration
public Color GetColor()

Returns

Type Description
Color

ReadBlueDataRegister()

Reads the blue data register of the sensor

Declaration
public ushort ReadBlueDataRegister()

Returns

Type Description
System.UInt16

ReadClearDataRegister()

Reads the clear data register of the sensor

Declaration
public ushort ReadClearDataRegister()

Returns

Type Description
System.UInt16

ReadGreenDataRegister()

Reads the green data register of the sensor

Declaration
public ushort ReadGreenDataRegister()

Returns

Type Description
System.UInt16

ReadMeasurementIsValid()

Reads whether the last measurement is valid

Declaration
public bool ReadMeasurementIsValid()

Returns

Type Description
System.Boolean

ReadRedDataRegister()

Reads the red data register of the sensor

Declaration
public ushort ReadRedDataRegister()

Returns

Type Description
System.UInt16

Reset()

Resets the device to the default configuration On reset the sensor goes to power down mode

Declaration
public void Reset()