Remarks

HTU21D
Status
Source code GitHub
NuGet package

The HTU21D is a low-cost, easy to use, highly accurate, digital humidity and temperature sensor controlled via the I2C bus.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Htu21d sensor;

    public MeadowApp()
    {
        sensor = new Htu21d(Device.CreateI2cBus(400));

        sensor.Updated += Sensor_Updated;

        sensor.StartUpdating(1000);
    }

    private void Sensor_Updated(object sender, Meadow.Peripherals.Sensors.Atmospheric.AtmosphericConditionChangeResult e)
    {
        Console.WriteLine($"Temp: {e.New.Temperature}, Humidity: {e.New.Humidity}");
    }
}

Sample projects available on GitHub

Wiring Example

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

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

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > Htu21d
Implements IAtmosphericSensor ITemperatureSensor IHumiditySensor
Namespace Meadow.Foundation.Sensors.Atmospheric
Assembly Htu21d.dll

Syntax

public class Htu21d : FilterableChangeObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IAtmosphericSensor, ITemperatureSensor, IHumiditySensor

Constructors

Htu21d(II2cBus, Byte)

Create a new Htu21d temperature and humidity sensor.

Declaration
public Htu21d(II2cBus i2cBus, byte address = 64)

Parameters

Type Name Description
II2cBus i2cBus

I2CBus (default to 100 KHz).

System.Byte address

Sensor address (default to 0x40).

Fields

htu21d

HTD21D(F) is an I2C device.

Declaration
protected readonly II2cPeripheral htu21d

Field Value

Type Description
II2cPeripheral

Properties

Conditions

The AtmosphericConditions from the last reading.

Declaration
public AtmosphericConditions Conditions { get; protected set; }

Property Value

Type Description
AtmosphericConditions

DEFAULT_SPEED

Declaration
public int DEFAULT_SPEED { get; }

Property Value

Type Description
System.Int32

FirmwareRevision

Firmware revision of the sensor.

Declaration
public byte FirmwareRevision { get; }

Property Value

Type Description
System.Byte

Humidity

The humidity, in percent relative humidity, from the last reading..

Declaration
public float Humidity { get; }

Property Value

Type Description
System.Single

IsSampling

Gets a value indicating whether the sensor is currently in a sampling loop. Call StartSampling() to spin up the sampling process.

Declaration
public bool IsSampling { get; protected set; }

Property Value

Type Description
System.Boolean

true if sampling; otherwise, false.

SerialNumber

Serial number of the device.

Declaration
public ulong SerialNumber { get; }

Property Value

Type Description
System.UInt64

Temperature

The temperature, in degrees celsius (°C), from the last reading.

Declaration
public float Temperature { get; }

Property Value

Type Description
System.Single

Methods

Heater(Boolean)

Turn the heater on or off.

Declaration
public void Heater(bool onOrOff)

Parameters

Type Name Description
System.Boolean onOrOff

Heater status, true = turn heater on, false = turn heater off.

Initialize()

Declaration
protected void Initialize()

RaiseChangedAndNotify(AtmosphericConditionChangeResult)

Declaration
protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)

Parameters

Type Name Description
AtmosphericConditionChangeResult changeResult

Read()

Convenience method to get the current sensor readings. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
public Task<AtmosphericConditions> Read()

Returns

Type Description
System.Threading.Tasks.Task<AtmosphericConditions>

ReadSensor()

Declaration
protected Task<AtmosphericConditions> ReadSensor()

Returns

Type Description
System.Threading.Tasks.Task<AtmosphericConditions>

Reset()

Reset the sensor and take a fresh reading.

Declaration
public void Reset()

StartUpdating(Int32)

Declaration
public void StartUpdating(int standbyDuration = 1000)

Parameters

Type Name Description
System.Int32 standbyDuration

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()

Events

Updated

Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated

Event Type

Type Description
System.EventHandler<AtmosphericConditionChangeResult>