Skip to content

Commit

Permalink
readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Dec 6, 2023
1 parent 47281b3 commit cb07039
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 6 deletions.
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/).
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public override Task Initialize()

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

var distance = await me007ys.Read();
Resolver.Log.Info($"Initial distance is: {distance.Centimeters:N1}cm / {distance.Inches:N1}in");

Expand Down
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/).
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To view all Wilderness Labs open-source projects, including samples, visit [gith
## Usage

```csharp
Tsl2591 sensor;
private Tsl2591 sensor;

public override Task Initialize()
{
Expand Down Expand Up @@ -41,10 +41,22 @@ public override Task Initialize()
// classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Lux:N2}Lux");
};

sensor.InfraredUpdated += (sender, result) =>
{
Resolver.Log.Info($" Infrared Light: {result.New.Lux:N2}Lux");
};

sensor.VisibleLightUpdated += (sender, result) =>
{
Resolver.Log.Info($" Visible Light: {result.New.Lux:N2}Lux");
};

sensor.FullSpectrumUpdated += (sender, result) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.Lux:N2}Lux");
};

return Task.CompletedTask;
Expand Down

0 comments on commit cb07039

Please sign in to comment.