-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47281b3
commit cb07039
Showing
4 changed files
with
292 additions
and
6 deletions.
There are no files selected for viewing
195 changes: 195 additions & 0 deletions
195
Source/Meadow.Foundation.Peripherals/Motors.GpioStepper/Driver/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# Meadow.Foundation.Motors.Stepper.GpioStepper | ||
|
||
**Digital input stepper motor controller** | ||
|
||
The **GpioStepper** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). | ||
|
||
The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. | ||
|
||
For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). | ||
|
||
To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). | ||
|
||
## Usage | ||
|
||
```csharp | ||
private IPositionalMotor stepper; | ||
|
||
private bool UseStepDirConfiguration { get; set; } = true; | ||
|
||
public override Task Initialize() | ||
{ | ||
if (UseStepDirConfiguration) | ||
{ | ||
// use a drive configured for STEP/DIR GPIOs | ||
stepper = new StepDirStepper( | ||
Device.Pins.D15.CreateDigitalOutputPort(), | ||
Device.Pins.D14.CreateDigitalOutputPort(), | ||
stepsPerRevolution: 200); | ||
} | ||
else | ||
{ | ||
// use a drive configured for CW/CCW GPIOs | ||
stepper = new CwCcwStepper( | ||
Device.Pins.D15.CreateDigitalOutputPort(), | ||
Device.Pins.D14.CreateDigitalOutputPort(), | ||
stepsPerRevolution: 200); | ||
} | ||
|
||
return base.Initialize(); | ||
} | ||
|
||
public override Task Run() | ||
{ | ||
// return RunUntilCancelled(); | ||
// return RunForSpecifiedTime(); | ||
// return RunToSpecificPositions(); | ||
return RotateSpecifiedAmount(); | ||
} | ||
|
||
private async Task RunUntilCancelled() | ||
{ | ||
var direction = RotationDirection.Clockwise; | ||
var rate = new AngularVelocity(1, AngularVelocity.UnitType.RevolutionsPerSecond); | ||
|
||
while (true) | ||
{ | ||
var tokenSource = new CancellationTokenSource(); | ||
|
||
Resolver.Log.Info($"Start running..."); | ||
var task = stepper.Run(direction, rate, tokenSource.Token); | ||
|
||
Resolver.Log.Info($"wait for 3 seconds..."); | ||
await Task.Delay(3000); | ||
|
||
Resolver.Log.Info($"cancelling motion..."); | ||
tokenSource.Cancel(); | ||
|
||
Resolver.Log.Info($"wait for motion to stop"); | ||
task.Wait(); | ||
|
||
Resolver.Log.Info($"motion stopped"); | ||
|
||
direction = direction switch | ||
{ | ||
RotationDirection.CounterClockwise => RotationDirection.Clockwise, | ||
_ => RotationDirection.CounterClockwise | ||
}; | ||
|
||
await Task.Delay(500); | ||
} | ||
} | ||
|
||
private async Task RunForSpecifiedTime() | ||
{ | ||
while (true) | ||
{ | ||
var direction = RotationDirection.Clockwise; | ||
var rate = new AngularVelocity(1, AngularVelocity.UnitType.RevolutionsPerSecond); | ||
|
||
Resolver.Log.Info($"Run for 2 seconds..."); | ||
await stepper.RunFor(TimeSpan.FromSeconds(2), direction, rate); | ||
|
||
direction = RotationDirection.CounterClockwise; | ||
rate = new AngularVelocity(2, AngularVelocity.UnitType.RevolutionsPerSecond); | ||
|
||
await stepper.RunFor(TimeSpan.FromSeconds(2), direction, rate); | ||
} | ||
} | ||
|
||
private async Task RotateSpecifiedAmount() | ||
{ | ||
while (true) | ||
{ | ||
for (var turns = 0.5d; turns <= 5; turns += 0.5) | ||
{ | ||
Resolver.Log.Info($"Moving {turns:0.0} revolutions"); | ||
|
||
var direction = RotationDirection.Clockwise; | ||
var rate = new AngularVelocity(4, AngularVelocity.UnitType.RevolutionsPerSecond); | ||
|
||
await stepper.Rotate(new Angle(turns, Angle.UnitType.Revolutions), direction, rate); | ||
|
||
await Task.Delay(1000); | ||
} | ||
} | ||
} | ||
|
||
private async Task RunToSpecificPositions() | ||
{ | ||
RotationDirection direction; | ||
|
||
var rate = new AngularVelocity(2, AngularVelocity.UnitType.RevolutionsPerSecond); | ||
|
||
// turn in smaller and smaller degree increments | ||
var increments = new double[] { 180, 90, 60, 45, 30 }; | ||
|
||
while (true) | ||
{ | ||
direction = RotationDirection.Clockwise; | ||
|
||
Resolver.Log.Info($"{direction}"); | ||
|
||
foreach (var increment in increments) | ||
{ | ||
Resolver.Log.Info($"Moving in increments of {increment} degrees"); | ||
|
||
await stepper.GoTo(Angle.Zero, direction, rate); | ||
await Task.Delay(1000); | ||
|
||
var nextPosition = 0d; | ||
|
||
while (nextPosition < 360) | ||
{ | ||
Resolver.Log.Info($"Moving to {nextPosition} degrees"); | ||
|
||
nextPosition += increment; | ||
|
||
await stepper.GoTo(new Angle(nextPosition, Meadow.Units.Angle.UnitType.Degrees), direction, rate); | ||
await Task.Delay(1000); | ||
} | ||
} | ||
|
||
await Task.Delay(3000); | ||
|
||
direction = RotationDirection.CounterClockwise; | ||
|
||
Resolver.Log.Info($"{direction}"); | ||
|
||
foreach (var increment in increments) | ||
{ | ||
Resolver.Log.Info($"Moving in increments of {increment} degrees"); | ||
|
||
var nextPosition = 360d; | ||
|
||
await stepper.GoTo(Angle.Zero, direction, rate); | ||
await Task.Delay(1000); | ||
|
||
while (nextPosition > 0) | ||
{ | ||
Resolver.Log.Info($"Moving to {nextPosition} degrees"); | ||
|
||
nextPosition -= increment; | ||
|
||
await stepper.GoTo(new Angle(nextPosition, Meadow.Units.Angle.UnitType.Degrees), direction, rate); | ||
await Task.Delay(1000); | ||
} | ||
} | ||
|
||
await Task.Delay(3000); | ||
|
||
Resolver.Log.Info($"--- Cycle complete ---"); | ||
} | ||
} | ||
|
||
``` | ||
## How to Contribute | ||
|
||
- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch | ||
|
||
|
||
## Need Help? | ||
|
||
If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 78 additions & 1 deletion
79
...eripherals/Sensors.Environmental.AtlasScientificGravityDOMeter/Driver/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,78 @@ | ||
# Meadow.Foundation.Sensors.Environmental.AltasScientificGravityDOMeter | ||
# Meadow.Foundation.Sensors.Environmental.AtlasScientificGravityDOMeter | ||
|
||
**Atlas Scientific analog gravity dissolved oxygen sensor** | ||
|
||
The **AtlasScientificGravityDOMeter** library is designed for the [Wilderness Labs](www.wildernesslabs.co) Meadow .NET IoT platform and is part of [Meadow.Foundation](https://developer.wildernesslabs.co/Meadow/Meadow.Foundation/). | ||
|
||
The **Meadow.Foundation** peripherals library is an open-source repository of drivers and libraries that streamline and simplify adding hardware to your C# .NET Meadow IoT application. | ||
|
||
For more information on developing for Meadow, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/). | ||
|
||
To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/). | ||
|
||
## Usage | ||
|
||
```csharp | ||
AtlasScientificGravityDOMeter sensor; | ||
|
||
public override Task Initialize() | ||
{ | ||
Resolver.Log.Info("Initialize..."); | ||
|
||
sensor = new AtlasScientificGravityDOMeter(Device.Pins.A01); | ||
sensor.CalibrationInAir = new Voltage(0.04, Voltage.UnitType.Volts); | ||
|
||
// Example that uses an IObservable subscription to only be notified when the saturation changes | ||
var consumer = AtlasScientificGravityDOMeter.CreateObserver( | ||
handler: result => | ||
{ | ||
string oldValue = (result.Old is { } old) ? $"{old * 100:n1}" : "n/a"; | ||
string newValue = $"{result.New * 100:n1}"; | ||
Resolver.Log.Info($"New: {newValue}%, Old: {oldValue}%"); | ||
}, | ||
filter: null | ||
); | ||
sensor.Subscribe(consumer); | ||
|
||
// optional classical .NET events can also be used: | ||
sensor.SaturationUpdated += (sender, result) => | ||
{ | ||
// string oldValue = (result.Old is { } old) ? $"{old * 100:n0}%" : "n/a"; | ||
// Resolver.Log.Info($"Updated - New: {result.New * 100:n0}%, Old: {oldValue}"); | ||
}; | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public override async Task Run() | ||
{ | ||
Resolver.Log.Info("Run..."); | ||
|
||
await ReadSensor(); | ||
|
||
//example calibration setting, ensure the sensor is set up for calibration | ||
var calibrationVoltage = await sensor.GetCurrentVoltage(); | ||
sensor.CalibrationInAir = calibrationVoltage; | ||
|
||
Resolver.Log.Info($"Calibration voltage: {calibrationVoltage.Volts}V"); | ||
|
||
sensor.StartUpdating(TimeSpan.FromSeconds(2)); | ||
} | ||
|
||
protected async Task ReadSensor() | ||
{ | ||
var saturation = await sensor.Read(); | ||
Resolver.Log.Info($"Initial saturation: {saturation * 100:N1}%"); | ||
} | ||
|
||
``` | ||
## How to Contribute | ||
|
||
- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch | ||
|
||
|
||
## Need Help? | ||
|
||
If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters