Remarks

Si70xx
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Atmospheric.Si70xx

The SI70xx is a humidity and temperature sensor controlled via I2C.

  • ± 3% RH (max)
  • 0–80% RH
  • High Accuracy Temperature Sensor ±0.4 °C
  • –10 to 85 °C
  • 0 to 100% RH operating range
  • Up to –40 to +125 °C operating range
  • Wide operating voltage (1.9 to 3.6 V)
  • Low Power Consumption
  • 150 µA active current
  • 60 nA standby current

Purchasing

The Si7021 is available on a breakout board from the the following suppliers:

Code Example

Si70xx? sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    sensor = new Si70xx(Device.CreateI2cBus());

    var consumer = Si70xx.CreateObserver(
        handler: result =>
        {
            Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old?.Temperature is { } oldTemp &&
                result.Old?.Humidity is { } oldHumidity &&
                result.New.Temperature is { } newTemp &&
                result.New.Humidity is { } newHumidity)
            {
                return ((newTemp - oldTemp).Abs().Celsius > 0.5 &&
                        (newHumidity - oldHumidity).Percent > 0.05);
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"  Temperature: {result.New.Temperature?.Celsius:F1}C");
        Resolver.Log.Info($"  Relative Humidity: {result.New.Humidity:F1}%");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    if(sensor == null) { return; }

    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($"  Temperature: {result.Temperature?.Celsius:F1}C");
    Resolver.Log.Info($"  Relative Humidity: {result.Humidity:F1}%");

    sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

Wiring Example

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

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

It should look like the following diagram:

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

Syntax

public class Si70xx : ByteCommsSensorBase<(Units.Temperature? Temperature, RelativeHumidity? Humidity)>, ITemperatureSensor, IHumiditySensor

Constructors

Si70xx(II2cBus, Byte)

Create a new SI7021 temperature and humidity sensor

Declaration
public Si70xx(II2cBus i2cBus, byte address = null)

Parameters

Type Name Description
II2cBus i2cBus

I2CBus

System.Byte address

I2C address (default to 0x40)

Fields

DEFAULT_SPEED

Default SPI bus speed

Declaration
public static Frequency DEFAULT_SPEED

Field Value

Type Description
Frequency

Properties

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 RelativeHumidity? Humidity { get; }

Property Value

Type Description
System.Nullable<RelativeHumidity>

SensorType

Device type as extracted from the serial number

Declaration
public Si70xx.DeviceType SensorType { get; }

Property Value

Type Description
Si70xx.DeviceType

SerialNumber

Serial number of the device

Declaration
public ulong SerialNumber { get; }

Property Value

Type Description
System.UInt64

Temperature

The temperature, from the last reading

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

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()

Initalize the sensor

Declaration
protected void Initialize()

RaiseEventsAndNotify(IChangeResult<(Nullable<Units.Temperature> Temperature, Nullable<RelativeHumidity> Humidity)>)

Inheritance-safe way to raise events and notify observers.

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? Temperature, RelativeHumidity? Humidity)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>> changeResult

ReadSensor()

Reads data from the sensor

Declaration
protected override Task<(Units.Temperature? Temperature, RelativeHumidity? Humidity)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<RelativeHumidity>>>

The latest sensor reading

Reset()

Reset the sensor

Declaration
protected void Reset()

Events

HumidityUpdated

Raised when the humidity value changes

Declaration
public event EventHandler<IChangeResult<RelativeHumidity>> HumidityUpdated

Event Type

Type Description
EventHandler<IChangeResult<RelativeHumidity>>

TemperatureUpdated

Raised when the temperature value changes

Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>