Skip to main content

Meadow.Foundation.Sensors.Environmental.DFRobotGravityDOMeter

DFRobotGravityDOMeter
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Environmental.DFRobotGravityDOMeter

Code Example

DFRobotGravityDOMeter sensor;

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

sensor = new DFRobotGravityDOMeter(Device.Pins.A01);

// Example that uses an IObservable subscription to only be notified when the saturation changes
var consumer = DFRobotGravityDOMeter.CreateObserver(
handler: result =>
{
string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter:n0}" : "n/a";
string newValue = $"{result.New.MilligramsPerLiter:n0}";
Resolver.Log.Info($"New: {newValue}mg/l, Old: {oldValue}mg/l");
},
filter: null
);
sensor.Subscribe(consumer);

// optional classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
string oldValue = (result.Old is { } old) ? $"{old.MilligramsPerLiter}mg/l" : "n/a";
Resolver.Log.Info($"Updated - New: {result.New.MilligramsPerLiter:n0}mg/l, Old: {oldValue}");
};

return Task.CompletedTask;
}

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

await ReadSensor();

sensor.StartUpdating(TimeSpan.FromSeconds(2));
}

protected async Task ReadSensor()
{
var concentration = await sensor.Read();
Resolver.Log.Info($"Initial concentration: {concentration.MilligramsPerLiter:N0}mg/l");
}

Sample project(s) available on GitHub

Class DFRobotGravityDOMeter

DFRobot Analog Gravity Dissolved Oxygen Meter

Assembly: DFRobotGravityDOMeter.dll
View Source
Declaration
public class DFRobotGravityDOMeter : SamplingSensorBase<ConcentrationInWater>, IObservable<IChangeResult<ConcentrationInWater>>, IDissolvedOxygenConcentrationSensor, ISamplingSensor<ConcentrationInWater>, ISensor<ConcentrationInWater>, ISensor, ISamplingSensor

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

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.ConcentrationInWater>>, Meadow.Peripherals.Sensors.Environmental.IDissolvedOxygenConcentrationSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.ConcentrationInWater>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.ConcentrationInWater>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor

Properties

WaterTemperature

The current water temperature (default 25C)

View Source
Declaration
public Temperature WaterTemperature { get; set; }

CalibrationAt25C

The calibration value for the sensor at 25C (default 1.6V)

View Source
Declaration
public Voltage CalibrationAt25C { get; set; }

AnalogInputPort

Returns the analog input port

View Source
Declaration
protected IAnalogInputPort AnalogInputPort { get; }

Concentration

Last concentration value read from the sensor

View Source
Declaration
public ConcentrationInWater? Concentration { get; protected set; }

Methods

GetCurrentVoltage()

Get the current voltage, useful for calibration

View Source
Declaration
public Task<Voltage> GetCurrentVoltage()
Returns

System.Threading.Tasks.Task<Meadow.Units.Voltage>

ReadSensor()

Reads data from the sensor

View Source
Declaration
protected override Task<ConcentrationInWater> ReadSensor()
Returns

System.Threading.Tasks.Task<Meadow.Units.ConcentrationInWater>: The latest sensor reading### StartUpdating(TimeSpan?) Starts continuously sampling the sensor

View Source
Declaration
public override void StartUpdating(TimeSpan? updateInterval)
Parameters
TypeName
System.Nullable<System.TimeSpan>updateInterval

StopUpdating()

Stops sampling the sensor

View Source
Declaration
public override void StopUpdating()

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Units.ConcentrationInWater>>
  • Meadow.Peripherals.Sensors.Environmental.IDissolvedOxygenConcentrationSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.ConcentrationInWater>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.ConcentrationInWater>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor