Skip to main content

Meadow.Foundation.Sensors.Environmental.NextPm

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

Code Example

NextPm nextPm;

public override Task Initialize()
{
var port = Device
.PlatformOS
.GetSerialPortName("COM1")
.CreateSerialPort();

nextPm = new NextPm(port);

nextPm.Readings10sUpdated += NextPm_Readings10sUpdated;

return Task.CompletedTask;
}

private void NextPm_Readings10sUpdated(object sender, IChangeResult<ParticulateReading> e)
{
Resolver.Log.Info($"Past 10 seconds");
Resolver.Log.Info($" {e.New.CountOf1micronParticles.ParticlesPerLiter:0} 1 micron particles per liter");
Resolver.Log.Info($" {e.New.CountOf2_5micronParticles.ParticlesPerLiter:0} 2.5 micron particles per liter");
Resolver.Log.Info($" {e.New.CountOf10micronParticles.ParticlesPerLiter:0} 10 micron particles per liter");
Resolver.Log.Info($" {e.New.EnvironmentalPM_1micron.MicroGramsPerMetersCubed:0} ug/L^3 1 micron particles");
Resolver.Log.Info($" {e.New.EnvironmentalPM_2_5micron.MicroGramsPerMetersCubed:0} ug/L^3 1 micron particles");
Resolver.Log.Info($" {e.New.EnvironmentalPM_10micron.MicroGramsPerMetersCubed:0} ug/L^3 1 micron particles");
}

public override async Task Run()
{
Resolver.Log.Info("Run...");

var firmware = await nextPm.GetFirmwareVersion();
Resolver.Log.Info($"Firmware: 0x{firmware:X4}");

var tempAndHumidity = await nextPm.GetTemperatureAndHumidity();
Resolver.Log.Info($"Temp: {tempAndHumidity.temperature:0.0}C Humidity: {tempAndHumidity.humidity}%");

nextPm.StartUpdating();
}


Sample project(s) available on GitHub

Class NextPm

Represents a TERA Sensor NextPM serial particulate matter sensor

Assembly: NextPm.dll
View Source
Declaration
public class NextPm : PollingSensorBase<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)>, IObservable<IChangeResult<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)>>, ISamplingSensor<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)>, ISensor<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)>, ISensor, ISamplingSensor, IDisposable, IPowerControllablePeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, System.IDisposable, Meadow.IPowerControllablePeripheral

Properties

IsDisposed

Returns true if the object is disposed, otherwise false

View Source
Declaration
public bool IsDisposed { get; }

Methods

GetFirmwareVersion()

Gets the sensor's firmware

View Source
Declaration
public Task<short> GetFirmwareVersion()
Returns

System.Threading.Tasks.Task<System.Int16>: The sensor's firmware version### IsAsleep() Checks to see if the sensor is in Sleep mode

View Source
Declaration
public Task<bool> IsAsleep()
Returns

System.Threading.Tasks.Task<System.Boolean>: <b>True</b> if the sensor is in Sleep mode### PowerOff() Puts the device into Sleep mode

View Source
Declaration
public Task PowerOff()
Returns

System.Threading.Tasks.Task

PowerOn()

Wakes the device from Sleep mode

View Source
Declaration
public Task PowerOn()
Returns

System.Threading.Tasks.Task

GetFanSpeed()

Gets the fan speed (in percentage)

View Source
Declaration
public Task<int> GetFanSpeed()
Returns

System.Threading.Tasks.Task<System.Int32>

SetFanSpeed(int)

Sets the sensor fan speed (in percentage)

View Source
Declaration
public Task SetFanSpeed(int speedPercent)
Returns

System.Threading.Tasks.Task

Parameters
TypeName
System.Int32speedPercent
Exceptions

System.ArgumentOutOfRangeException

GetTemperatureAndHumidity()

Gets the sensor's current Temperature and Humidity readings

View Source
Declaration
public Task<(Temperature temperature, RelativeHumidity humidity)> GetTemperatureAndHumidity()
Returns

System.Threading.Tasks.Task<System.ValueTuple<Meadow.Units.Temperature,Meadow.Units.RelativeHumidity>>

Get10SecondAverageReading()

Gets the average particulate reading for the past 10 seconds

View Source
Declaration
public Task<ParticulateReading> Get10SecondAverageReading()
Returns

System.Threading.Tasks.Task<Meadow.Foundation.Sensors.Environmental.ParticulateReading>

Get1MinuteAverageReading()

Gets the average particulate reading for the past 60 seconds

View Source
Declaration
public Task<ParticulateReading> Get1MinuteAverageReading()
Returns

System.Threading.Tasks.Task<Meadow.Foundation.Sensors.Environmental.ParticulateReading>

Get15MinuteAverageReading()

Gets the average particulate reading for the past 15 minutes

View Source
Declaration
public Task<ParticulateReading> Get15MinuteAverageReading()
Returns

System.Threading.Tasks.Task<Meadow.Foundation.Sensors.Environmental.ParticulateReading>

RaiseEventsAndNotify(IChangeResult<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)>)

Notify observers

View Source
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)> changeResult)
Parameters
TypeNameDescription
Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>changeResultprovides new and old values

ReadSensor()

Read value from sensor

View Source
Declaration
protected override Task<(ParticulateReading? reading10s, ParticulateReading? reading1min, ParticulateReading? reading15min, Temperature? temperature, RelativeHumidity? humidity)> ReadSensor()
Returns

System.Threading.Tasks.Task<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>: unitized value### Dispose(bool) Dispose of the object

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Dispose()

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

View Source
Declaration
public void Dispose()

Events

Readings10sUpdated

Raised when a new 10-second average reading is taken

View Source
Declaration
public event EventHandler<IChangeResult<ParticulateReading>> Readings10sUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Foundation.Sensors.Environmental.ParticulateReading>>

Readings1minUpdated

Raised when a new 1-minute average reading is taken

View Source
Declaration
public event EventHandler<IChangeResult<ParticulateReading>> Readings1minUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Foundation.Sensors.Environmental.ParticulateReading>>

Readings15minUpdated

Raised when a new 15-minute average reading is taken

View Source
Declaration
public event EventHandler<IChangeResult<ParticulateReading>> Readings15minUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Foundation.Sensors.Environmental.ParticulateReading>>

TemperatureUpdated

Raised when a new temperature reading is taken

View Source
Declaration
public event EventHandler<IChangeResult<Temperature>> TemperatureUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Units.Temperature>>

HumidityUpdated

Raised when a new humidity reading is taken

View Source
Declaration
public event EventHandler<IChangeResult<RelativeHumidity>> HumidityUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Units.RelativeHumidity>>

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Foundation.Sensors.Environmental.ParticulateReading>,System.Nullable<Meadow.Units.Temperature>,System.Nullable<Meadow.Units.RelativeHumidity>>>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • System.IDisposable
  • Meadow.IPowerControllablePeripheral