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 : FilterableObservableBase<AtmosphericConditionChangeResult, AtmosphericConditions>, IAtmosphericSensor, ITemperatureSensor, IHumiditySensor

Constructors

View Source

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

View Source

htu21d

HTD21D(F) is an I2C device.

Declaration
protected readonly II2cPeripheral htu21d

Field Value

Type Description
II2cPeripheral

Properties

View Source

Conditions

The AtmosphericConditions from the last reading.

Declaration
public AtmosphericConditions Conditions { get; protected set; }

Property Value

Type Description
AtmosphericConditions
View Source

DEFAULT_SPEED

Declaration
public int DEFAULT_SPEED { get; }

Property Value

Type Description
System.Int32
View Source

FirmwareRevision

Firmware revision of the sensor.

Declaration
public byte FirmwareRevision { get; }

Property Value

Type Description
System.Byte
View Source

Humidity

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

Declaration
public float Humidity { get; }

Property Value

Type Description
System.Single
View Source

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.

View Source

SerialNumber

Serial number of the device.

Declaration
public ulong SerialNumber { get; }

Property Value

Type Description
System.UInt64
View Source

Temperature

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

Declaration
public float Temperature { get; }

Property Value

Type Description
System.Single

Methods

View Source

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.

View Source

Initialize()

Declaration
protected void Initialize()
View Source

RaiseChangedAndNotify(AtmosphericConditionChangeResult)

Declaration
protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)

Parameters

Type Name Description
AtmosphericConditionChangeResult changeResult
View Source

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>
View Source

ReadSensor()

Declaration
protected Task<AtmosphericConditions> ReadSensor()

Returns

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

Reset()

Reset the sensor and take a fresh reading.

Declaration
public void Reset()
View Source

StartUpdating(Int32)

Declaration
public void StartUpdating(int standbyDuration = 1000)

Parameters

Type Name Description
System.Int32 standbyDuration
View Source

StopUpdating()

Stops sampling the temperature.

Declaration
public void StopUpdating()

Events

View Source

Updated

Declaration
public event EventHandler<AtmosphericConditionChangeResult> Updated

Event Type

Type Description
System.EventHandler<AtmosphericConditionChangeResult>