Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Sample project(s) available on GitHub
Syntax
public class MiniPID2 : SamplingSensorBase<Concentration>, IObservable<IChangeResult<Concentration>>, IConcentrationSensor, ISamplingSensor<Concentration>, ISensor<Concentration>
Constructors
MiniPID2(IAnalogInputPort, MiniPID2Type)
Create a new MiniPID2 object
Declaration
public MiniPID2(IAnalogInputPort analogInputPort, MiniPID2.MiniPID2Type pid2Type)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | analogInputPort | The analog port connected to the sensor |
MiniPID2.MiniPID2Type | pid2Type | The MiniPID sensor type |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
MiniPID2(IPin, MiniPID2Type, int, TimeSpan?)
Create a new MiniPID2 object
Declaration
public MiniPID2(IPin analogPin, MiniPID2.MiniPID2Type pid2Type, int sampleCount = 5, TimeSpan? sampleInterval = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | analogPin | The analog data pin connected to the sensor |
MiniPID2.MiniPID2Type | pid2Type | The MiniPID sensor type |
int | sampleCount | How many samples to take during a given reading. These are automatically averaged to reduce noise |
TimeSpan? | sampleInterval | The time between sample readings |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Properties
AnalogInputPort
Represents an IonScience MiniPID2 analog photoionisation (PID) Volatile Organic Compounds (VOC) sensor
Declaration
protected IAnalogInputPort AnalogInputPort { get; }
Property Value
Type | Description |
---|---|
IAnalogInputPort |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Concentration
The current VOC concentration value
Declaration
public Concentration? Concentration { get; protected set; }
Property Value
Type | Description |
---|---|
Concentration? |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
MiniPID2DeviceType
The MiniPID2 device type
Declaration
public MiniPID2.MiniPID2Type MiniPID2DeviceType { get; protected set; }
Property Value
Type | Description |
---|---|
MiniPID2.MiniPID2Type |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Methods
GetOffsetForSensor(MiniPID2Type)
Get the voltage offset for a sensor
Declaration
public Voltage GetOffsetForSensor(MiniPID2.MiniPID2Type sensorType)
Parameters
Type | Name | Description |
---|---|---|
MiniPID2.MiniPID2Type | sensorType | The sensor |
Returns
Type | Description |
---|---|
Voltage | The offset as voltage |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
RaiseEventsAndNotify(IChangeResult<Concentration>)
Method to notify subscribers to ConcentrationUpdated event handler
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Concentration> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<Concentration> | changeResult |
Overrides
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
ReadSensor()
Convenience method to get the current concentration. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.
Declaration
protected override Task<Concentration> ReadSensor()
Returns
Type | Description |
---|---|
Task<Concentration> | The concentration averages of the given sample count |
Overrides
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
SetOffsetForSensor(Voltage, MiniPID2Type)
Set the sensor voltage offset Useful for compensating for air conditions
Declaration
public void SetOffsetForSensor(Voltage offset, MiniPID2.MiniPID2Type sensorType)
Parameters
Type | Name | Description |
---|---|---|
Voltage | offset | Offset voltage |
MiniPID2.MiniPID2Type | sensorType | The sensor to change |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
StartUpdating(TimeSpan?)
Starts updating the sensor on the updateInterval frequency specified
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan? | updateInterval |
Overrides
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
StopUpdating()
Stops sampling the concentration
Declaration
public override void StopUpdating()
Overrides
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
VoltageToConcentration(Voltage)
Converts voltage to Concentration
Declaration
protected Concentration VoltageToConcentration(Voltage voltage)
Parameters
Type | Name | Description |
---|---|---|
Voltage | voltage |
Returns
Type | Description |
---|---|
Concentration | Concentration |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
Events
ConcentrationUpdated
Raised when the VOC concentration changes
Declaration
public event EventHandler<IChangeResult<Concentration>> ConcentrationUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Concentration>> |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}
VOCConcentrationUpdated
Raised when the VOC concentration changes
Declaration
public event EventHandler<IChangeResult<Concentration>> VOCConcentrationUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Concentration>> |
Remarks
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 Concentraion: {result.New.PartsPerMillion:N1}ppm");
};
}
sensor?.StartUpdating(TimeSpan.FromSeconds(2));
return base.Initialize();
}