Meadow.Foundation.Sensors.Environmental.MiniPID2
MiniPID2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
MiniPID2 sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new MiniPID2(Device.Pins.A01, MiniPID2.MiniPID2Type.PPB_WR);
var consumer = MiniPID2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: VOC concentration changed by threshold; new: {result.New.PartsPerBillion:N1}ppm");
},
filter: result =>
{
if (result.Old is { } oldCon &&
result.New is { } newCon)
{
return Math.Abs((newCon - oldCon).PartsPerMillion) > 10;
}
return false;
}
);
sensor?.Subscribe(consumer);
if (sensor != null)
{
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" VOC Concentration: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Sample project(s) available on GitHub
Class MiniPID2
Represents an IonScience MiniPID2 analog photoionisation (PID) Volatile Organic Compounds (VOC) sensor
Assembly: MiniPID2.dll
View Source
public class MiniPID2 : SamplingSensorBase<Concentration>, IObservable<IChangeResult<Concentration>>, IVOCConcentrationSensor, ISamplingSensor<Concentration>, ISensor<Concentration>, ISensor, ISamplingSensor, IDisposable
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Concentration>>
, Meadow.Peripherals.Sensors.Environmental.IVOCConcentrationSensor
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Concentration>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Concentration>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
, System.IDisposable
Properties
VOCConcentration
The current VOC concentration value
View Source
public Concentration? VOCConcentration { get; protected set; }
MiniPID2DeviceType
The MiniPID2 device type
View Source
public MiniPID2.MiniPID2Type MiniPID2DeviceType { get; protected set; }
AnalogInputPort
View Source
protected IAnalogInputPort AnalogInputPort { get; }
IsDisposed
Is the object disposed
View Source
public bool IsDisposed { get; }
Methods
SetOffsetForSensor(Voltage, MiniPID2Type)
Set the sensor voltage offset Useful for compensating for air conditions
View Source
public void SetOffsetForSensor(Voltage offset, MiniPID2.MiniPID2Type sensorType)
Parameters
Type | Name | Description |
---|---|---|
Meadow.Units.Voltage | offset | Offset voltage |
Meadow.Foundation.Sensors.Environmental.MiniPID2.MiniPID2Type | sensorType | The sensor to change |
GetOffsetForSensor(MiniPID2Type)
Get the voltage offset for a sensor
View Source
public Voltage GetOffsetForSensor(MiniPID2.MiniPID2Type sensorType)
Returns
Meadow.Units.Voltage
: The offset as voltage
Parameters
Type | Name | Description |
---|---|---|
Meadow.Foundation.Sensors.Environmental.MiniPID2.MiniPID2Type | sensorType | The sensor |
ReadSensor()
Convenience method to get the current concentration. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.
View Source
protected override Task<Concentration> ReadSensor()
Returns
System.Threading.Tasks.Task<Meadow.Units.Concentration>
: The concentration averages of the given sample count### StartUpdating(TimeSpan?)
Starts updating the sensor on the updateInterval frequency specified
View Source
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name |
---|---|
System.Nullable<System.TimeSpan> | updateInterval |
StopUpdating()
Stops sampling the concentration
View Source
public override void StopUpdating()
VoltageToConcentration(Voltage)
Converts voltage to Concentration
View Source
protected Concentration VoltageToConcentration(Voltage voltage)
Returns
Meadow.Units.Concentration
: Concentration
Parameters
Type | Name |
---|---|
Meadow.Units.Voltage | voltage |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
View Source
public void Dispose()
Dispose(bool)
Dispose of the object
View Source
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | Is disposing |
Implements
System.IObservable<Meadow.IChangeResult<Meadow.Units.Concentration>>
Meadow.Peripherals.Sensors.Environmental.IVOCConcentrationSensor
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Concentration>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Concentration>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor
System.IDisposable