Meadow.Foundation.Sensors.Atmospheric.Sgp40
Sgp40 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Sgp40? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Sgp40(Device.CreateI2cBus());
Resolver.Log.Info($"Sensor SN: {sensor.SerialNumber:x6}");
if (sensor.RunSelfTest())
{
Resolver.Log.Info("Self test successful");
}
else
{
Resolver.Log.Warn("Self test failed");
}
var consumer = Sgp40.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: VOC changed by threshold; new index: {result.New}");
},
filter: result =>
{
return Math.Abs(result.New - result.Old ?? 0) > 10;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" VOC: {result.New}");
};
return base.Initialize();
}
public override async Task Run()
{
await ReadConditions();
sensor?.StartUpdating(TimeSpan.FromSeconds(1));
}
private async Task ReadConditions()
{
if (sensor == null) { return; }
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Temperature: {result}");
}
Sample project(s) available on GitHub
Wiring Example
To wire a Sgp40 to your Meadow board, connect the following:
Sgp40 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
Class Sgp40
Provides access to the Sensirion SGP40 VOC sensor
Assembly: Sgp40.dll
View Source
public class Sgp40 : ByteCommsSensorBase<int>, IObservable<IChangeResult<int>>, ISamplingSensor<int>, ISensor<int>, ISensor, ISamplingSensor, IDisposable, II2cPeripheral
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Implements:
System.IObservable<Meadow.IChangeResult<System.Int32>>
, Meadow.Peripherals.Sensors.ISamplingSensor<System.Int32>
, Meadow.Peripherals.Sensors.ISensor<System.Int32>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
, System.IDisposable
, Meadow.Hardware.II2cPeripheral
Properties
VocIndex
The VOC Index, from the last reading
View Source
public int VocIndex { get; }
SerialNumber
Serial number of the device
View Source
public ulong SerialNumber { get; }
DefaultI2cAddress
The default I2C address for the peripheral
View Source
public byte DefaultI2cAddress { get; }
Methods
Initialize()
Initialize the sensor
View Source
protected void Initialize()
RunSelfTest()
This command triggers the built-in self-test checking for integrity of both hotplate and MOX material
View Source
public bool RunSelfTest()
Returns
System.Boolean
: true on successful test, otherwise false### ReadSensor()
Reads data from the sensor
View Source
protected override Task<int> ReadSensor()
Returns
System.Threading.Tasks.Task<System.Int32>
: The latest sensor reading### TurnHeaterOff()
This command turns the hotplate off and stops the measurement. Subsequently, the sensor enters idle mode.
View Source
public void TurnHeaterOff()
SetCompensationData(RelativeHumidity, Temperature)
Set the compensation data
View Source
public void SetCompensationData(RelativeHumidity humidity, Temperature temperature)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Units.RelativeHumidity | humidity | Humidity compensation |
Meadow.Units.Temperature | temperature | Temperature compensation |
ClearCompensationData()
Clear the compensation data
View Source
public void ClearCompensationData()
Implements
System.IObservable<Meadow.IChangeResult<System.Int32>>
Meadow.Peripherals.Sensors.ISamplingSensor<System.Int32>
Meadow.Peripherals.Sensors.ISensor<System.Int32>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor
System.IDisposable
Meadow.Hardware.II2cPeripheral