Skip to main content

Meadow.Foundation.Sensors.Environmental.MiniPID2

MiniPID2
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Environmental.MiniPID2

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
Declaration
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
Declaration
public Concentration? VOCConcentration { get; protected set; }

MiniPID2DeviceType

The MiniPID2 device type

View Source
Declaration
public MiniPID2.MiniPID2Type MiniPID2DeviceType { get; protected set; }

AnalogInputPort

View Source
Declaration
protected IAnalogInputPort AnalogInputPort { get; }

IsDisposed

Is the object disposed

View Source
Declaration
public bool IsDisposed { get; }

Methods

SetOffsetForSensor(Voltage, MiniPID2Type)

Set the sensor voltage offset Useful for compensating for air conditions

View Source
Declaration
public void SetOffsetForSensor(Voltage offset, MiniPID2.MiniPID2Type sensorType)
Parameters
TypeNameDescription
Meadow.Units.VoltageoffsetOffset voltage
Meadow.Foundation.Sensors.Environmental.MiniPID2.MiniPID2TypesensorTypeThe sensor to change

GetOffsetForSensor(MiniPID2Type)

Get the voltage offset for a sensor

View Source
Declaration
public Voltage GetOffsetForSensor(MiniPID2.MiniPID2Type sensorType)
Returns

Meadow.Units.Voltage: The offset as voltage

Parameters
TypeNameDescription
Meadow.Foundation.Sensors.Environmental.MiniPID2.MiniPID2TypesensorTypeThe sensor

ReadSensor()

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

View Source
Declaration
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
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
TypeName
System.Nullable<System.TimeSpan>updateInterval

StopUpdating()

Stops sampling the concentration

View Source
Declaration
public override void StopUpdating()

VoltageToConcentration(Voltage)

Converts voltage to Concentration

View Source
Declaration
protected Concentration VoltageToConcentration(Voltage voltage)
Returns

Meadow.Units.Concentration: Concentration

Parameters
TypeName
Meadow.Units.Voltagevoltage

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
Declaration
public void Dispose()

Dispose(bool)

Dispose of the object

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs 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