diff --git a/devices/Drv8825/Direction.cs b/devices/Drv8825/Direction.cs new file mode 100644 index 0000000000..6abfc9d314 --- /dev/null +++ b/devices/Drv8825/Direction.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Drv8825 +{ + /// + /// Motor rotation direction. + /// + public enum Direction + { + /// + /// Rotation in the same direction as a clock's hands. + /// + Clockwise, + + /// + /// Rotation in the opposite direction to the movement of the hands of a clock. + /// + Counterclockwise + } +} diff --git a/devices/Drv8825/Drv8825.cs b/devices/Drv8825/Drv8825.cs new file mode 100644 index 0000000000..e64f469887 --- /dev/null +++ b/devices/Drv8825/Drv8825.cs @@ -0,0 +1,194 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Device; +using System.Device.Gpio; +using System.Threading; +using UnitsNet; + +namespace Iot.Device.Drv8825 +{ + /// + /// Class for controlling Drv8825 stepper motor driver. + /// + public class Drv8825 : IDisposable + { + private readonly ushort _fullStepsPerRotation; + private readonly GpioPin _stepPin; + private readonly GpioPin _dirPin; + private readonly GpioPin? _sleepPin; + private readonly bool _shouldDisposeGpioController; + private readonly MicrostepsController _microstepsController; + + private GpioController? _gpioController; + + /// + /// Gets or sets the delay that allows the driver to recognize a step. By default, it is 5 microseconds. + /// It is not recommended to set this delay less than 2 microseconds, + /// otherwise the motor will "miss"(skip) some steps. + /// And it is not recommended to set this delay more than 50 microseconds, + /// otherwise the morot will stop recognize steps. + /// + public TimeSpan StepDelay { get; set; } = TimeSpan.FromTicks(5 * 10L); + + /// + /// Gets or sets delay between each step (or microstep). + /// + public TimeSpan DelayBetweenSteps { get; set; } = TimeSpan.Zero; + + /// + /// Initializes a new instance of the class. + /// + /// Microcontroller pin connected to STEP driver pin. Used to set steps count. + /// Microcontroller pin connected to DIR driver pin. Used to set rotation direction. + /// Microcontroller pin connected to SLP driver pin. Used to wake up and put the driver to sleep. Usually SLP need to connect with RST pin. + /// How many steps your motor need to make full rotation. For example, Nema 17 takes 200 full steps to complete full rotation. + /// GPIO controller. If it not passed, then it be created here. + /// True to dispose the Gpio Controller when this class wiill be disposed. + /// Microcontroller pin connected to M0 driver pin. Can be used to microsteps control. 0 if not connected. + /// Microcontroller pin connected to M1 driver pin. Can be used to microsteps control. 0 if not connected. + /// Microcontroller pin connected to M2 driver pin. Can be used to microsteps control. 0 if not connected. + public Drv8825( + byte stepPin, + byte dirPin, + byte sleepPin = 0, + ushort fullStepsPerRotation = 200, + GpioController? gpioController = null, + bool shouldDisposeGpioController = true, + byte m0Pin = 0, + byte m1Pin = 0, + byte m2Pin = 0) + { + _fullStepsPerRotation = fullStepsPerRotation; + _gpioController = gpioController ?? new GpioController(); + _shouldDisposeGpioController = shouldDisposeGpioController || gpioController is null; + _stepPin = _gpioController.OpenPin(stepPin, PinMode.Output); + _dirPin = _gpioController.OpenPin(dirPin, PinMode.Output); + + if (sleepPin > 0) + { + _sleepPin = _gpioController.OpenPin(sleepPin, PinMode.Output); + } + + _microstepsController = new MicrostepsController(_gpioController, m0Pin, m1Pin, m2Pin); + } + + /// + /// Switch driver to working mode. + /// + /// Throws when sleep pin doesn't passed. + public void WakeUp() + { + if (_sleepPin == null) + { + throw new InvalidOperationException("Sleep pin does not passed. Try to create driver class with sleepPin param"); + } + + _sleepPin.Write(PinValue.High); + } + + /// + /// Switch driver to sleep mode. + /// + /// The number of milliseconds to wait before going to sleep. Use if you want give to driver time to process all previously sent steps. + /// Throws when sleep pin doesn't passed. + public void Sleep(int millisecondsDelay = 0) + { + if (_sleepPin == null) + { + throw new InvalidOperationException("Sleep pin does not passed. Try to create driver class with sleepPin param"); + } + + if (millisecondsDelay > 0) + { + Thread.Sleep(millisecondsDelay); + } + + _sleepPin.Write(PinValue.Low); + } + + /// + /// Rotates a stepper motor. + /// + /// Angle to rotate. + /// Step size. + public void Rotate(Angle angle, StepSize stepSize = StepSize.FullStep) + { + if (angle.Degrees == 0) + { + return; + } + + _dirPin.Write(angle.Degrees > 0 ? PinValue.High : PinValue.Low); + var degreeForStepsCalculation = angle.Degrees < 0 ? -angle.Degrees : angle.Degrees; + var pulses = degreeForStepsCalculation / 360 * _fullStepsPerRotation * (byte)stepSize; + + _microstepsController.Set(stepSize); + Rotate((int)pulses); + } + + /// + /// Rotates a stepper motor. + /// + /// Steps count. + /// True to go forward, false to go back(or vice versa if you connect the motor in the opposite direction). + /// Step size. + public virtual void Rotate( + int steps, + Direction direction = Direction.Clockwise, + StepSize size = StepSize.FullStep) + { + if (steps == 0) + { + return; + } + + _microstepsController.Set(size); + _dirPin.Write(direction == Direction.Clockwise ? PinValue.High : PinValue.Low); + + Rotate(steps); + } + + /// + /// + /// + public void Dispose() + { + if (_shouldDisposeGpioController) + { + _gpioController?.Dispose(); + } + + _gpioController = null; + } + + /// + /// Controls the speed of rotation. + /// + private void SleepBetweenSteps() + { + if (DelayBetweenSteps == TimeSpan.Zero) + { + return; + } + + Thread.Sleep(DelayBetweenSteps); + } + + /// + /// Rotates a stepper motor. + /// + /// Steps count. + private void Rotate(int steps) + { + for (var i = 0; i < steps; i++) + { + _stepPin.Write(PinValue.High); + Thread.Sleep(StepDelay); + _stepPin.Write(PinValue.Low); + SleepBetweenSteps(); + } + } + } +} \ No newline at end of file diff --git a/devices/Drv8825/Drv8825.nfproj b/devices/Drv8825/Drv8825.nfproj new file mode 100644 index 0000000000..83f75c8af9 --- /dev/null +++ b/devices/Drv8825/Drv8825.nfproj @@ -0,0 +1,72 @@ + + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + enable + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 5aae94ba-29f0-4004-8404-1a5095698531 + Library + Properties + 512 + Iot.Device.Drv8825 + Iot.Device.Drv8825 + v1.0 + bin\$(Configuration)\Iot.Device.Drv8825.xml + 9.0 + false + true + true + true + ..\key.snk + false + + + + + packages\nanoFramework.CoreLibrary.1.17.11\lib\mscorlib.dll + + + packages\nanoFramework.Runtime.Events.1.11.32\lib\nanoFramework.Runtime.Events.dll + + + packages\nanoFramework.System.Device.Gpio.1.1.57\lib\System.Device.Gpio.dll + + + packages\nanoFramework.System.Math.1.5.116\lib\System.Math.dll + + + packages\UnitsNet.nanoFramework.Angle.5.75.0\lib\UnitsNet.Angle.dll + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + \ No newline at end of file diff --git a/devices/Drv8825/Drv8825.nuspec b/devices/Drv8825/Drv8825.nuspec new file mode 100644 index 0000000000..c6bb775b94 --- /dev/null +++ b/devices/Drv8825/Drv8825.nuspec @@ -0,0 +1,39 @@ + + + + nanoFramework.Iot.Device.Drv8825 + $version$ + nanoFramework.Iot.Device.Drv8825 + nanoframework + false + LICENSE.md + + + docs\README.md + false + https://github.com/nanoframework/nanoFramework.IoT.Device + images\nf-logo.png + + Copyright (c) .NET Foundation and Contributors + This package includes the .NET IoT Core binding Iot.Device.Drv8825 for .NET nanoFramework C# projects. + Iot.Device.Drv8825 assembly for .NET nanoFramework C# projects + nanoFramework C# csharp netmf netnf Iot.Device.Drv8825 Drv8825 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/devices/Drv8825/Drv8825.sln b/devices/Drv8825/Drv8825.sln new file mode 100644 index 0000000000..090ea34a40 --- /dev/null +++ b/devices/Drv8825/Drv8825.sln @@ -0,0 +1,35 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36203.30 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Drv8825", "Drv8825.nfproj", "{5AAE94BA-29F0-4004-8404-1A5095698531}" +EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Drv8825.samples", "samples\Drv8825.samples.nfproj", "{E8798205-E0D7-443F-B96A-8F752B7EF454}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5AAE94BA-29F0-4004-8404-1A5095698531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5AAE94BA-29F0-4004-8404-1A5095698531}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5AAE94BA-29F0-4004-8404-1A5095698531}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5AAE94BA-29F0-4004-8404-1A5095698531}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5AAE94BA-29F0-4004-8404-1A5095698531}.Release|Any CPU.Build.0 = Release|Any CPU + {5AAE94BA-29F0-4004-8404-1A5095698531}.Release|Any CPU.Deploy.0 = Release|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Release|Any CPU.Build.0 = Release|Any CPU + {E8798205-E0D7-443F-B96A-8F752B7EF454}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {724AA4FB-36FD-46CB-ADB0-63E6CA4C322F} + EndGlobalSection +EndGlobal diff --git a/devices/Drv8825/Drv8825_circuit_bb.jpeg b/devices/Drv8825/Drv8825_circuit_bb.jpeg new file mode 100644 index 0000000000..a081e10dc5 Binary files /dev/null and b/devices/Drv8825/Drv8825_circuit_bb.jpeg differ diff --git a/devices/Drv8825/MicrostepsController.cs b/devices/Drv8825/MicrostepsController.cs new file mode 100644 index 0000000000..add5520750 --- /dev/null +++ b/devices/Drv8825/MicrostepsController.cs @@ -0,0 +1,134 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Device.Gpio; + +namespace Iot.Device.Drv8825 +{ + /// + /// Class for microstepping control. + /// + internal class MicrostepsController + { + private readonly GpioPin? _m0Pin; + private readonly GpioPin? _m1Pin; + private readonly GpioPin? _m2Pin; + + /// + /// Initializes a new instance of the class. + /// + /// GPIO controller. If it not passed, then it be created here. + /// Microcontroller pin connected to M0 driver pin. Can be used to microsteps control. 0 if not connected. + /// Microcontroller pin connected to M1 driver pin. Can be used to microsteps control. 0 if not connected. + /// Microcontroller pin connected to M2 driver pin. Can be used to microsteps control. 0 if not connected. + public MicrostepsController( + GpioController gpio, + byte m0Pin, + byte m1Pin, + byte m2Pin) + { + if (m0Pin > 0) + { + _m0Pin = gpio.OpenPin(m0Pin, PinMode.Output); + } + + if (m1Pin > 0 && m1Pin != m0Pin) + { + _m1Pin = gpio.OpenPin(m1Pin, PinMode.Output); + } + + if (m2Pin > 0 && m2Pin != m1Pin && m2Pin != m0Pin) + { + _m2Pin = gpio.OpenPin(m2Pin, PinMode.Output); + } + } + + /// + /// Sets the values of M0, M1, M2 to go to the desired step size. + /// + /// Step size. + public void Set(StepSize size) + { + switch (size) + { + case StepSize.FullStep: + UpdateM0(PinValue.Low); + UpdateM1(PinValue.Low); + UpdateM2(PinValue.Low); + break; + + case StepSize.HalfStep: + UpdateM0(PinValue.High); + UpdateM1(PinValue.Low); + UpdateM2(PinValue.Low); + break; + + case StepSize.QuaterStep: + UpdateM0(PinValue.Low); + UpdateM1(PinValue.High); + UpdateM2(PinValue.Low); + break; + + case StepSize.EightStep: + UpdateM0(PinValue.High); + UpdateM1(PinValue.High); + UpdateM2(PinValue.Low); + break; + + case StepSize.SixteenStep: + UpdateM0(PinValue.Low); + UpdateM1(PinValue.Low); + UpdateM2(PinValue.High); + break; + + case StepSize.ThirtyTwoStep: + UpdateM0(PinValue.High); + UpdateM1(PinValue.Low); + UpdateM2(PinValue.High); + break; + } + } + + /// + /// Sets the value of M0. + /// + /// Pin value (Low or High). + private void UpdateM0(PinValue value) + { + if (_m0Pin == null) + { + return; + } + + _m0Pin.Write(value); + } + + /// + /// Sets the value of M1. + /// + /// Pin value (Low or High). + private void UpdateM1(PinValue value) + { + if (_m1Pin == null) + { + return; + } + + _m1Pin.Write(value); + } + + /// + /// Sets the value of M2. + /// + /// Pin value (Low or High). + private void UpdateM2(PinValue value) + { + if (_m2Pin == null) + { + return; + } + + _m2Pin.Write(value); + } + } +} diff --git a/devices/Drv8825/Properties/AssemblyInfo.cs b/devices/Drv8825/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..f525ef1774 --- /dev/null +++ b/devices/Drv8825/Properties/AssemblyInfo.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Iot.Device.Drv8825")] +[assembly: AssemblyCompany("nanoFramework Contributors")] +[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")] + +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/devices/Drv8825/README.md b/devices/Drv8825/README.md new file mode 100644 index 0000000000..875cd23493 --- /dev/null +++ b/devices/Drv8825/README.md @@ -0,0 +1,108 @@ +# 4-Wire stepper motor & Drv8825 driver board + +A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. +The shaft or spindle of a stepper motor rotates in discrete step increments when electrical command pulses +are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied +input pulses. The sequence of the applied pulses is directly related to the direction of motor shafts rotation. +The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length +of rotation is directly related to the number of input pulses applied. One of the most significant advantages of +a stepper motor is its ability to be accurately controlled in an open loop system. Open loop control means +no feedback information about position is needed. This type of control eliminates the need for +expensive sensing and feedback devices such as optical encoders. Your position is known simply by +keeping track of the input step pulses. + +## Documentation + +You can find the [DRV8825 chip](https://www.ti.com/lit/ds/symlink/drv8825.pdf) or +[DRV8825 module](https://www.tme.eu/Document/1dd18faf1196df48619105e397146fdf/POLOLU-2133.pdf) datasheet here. + +## Connections + +VMOT - connect to 8-35V (motor supply voltage). + +GND - connect to GND. + +1A, 1B, 2A, 2B - connect to the 4 coils of motor. + +DIR - connect to microcontroller output pin to control direction of stepping. Internal pulldown. + +STEP - connect to microcontroller output pin to be able to perform the steps. Internal pulldown. + +RST — connect to microcontroller output pin or to 3.3-5V, active-low, reinitializes the indexer logic +and disables H-bridge outputs. Internal pulldown. + +SLP - can be joined with RST, connect it to microcontroller output pin or to 3.3-5V. +Logic high to enable driver, logic low to enter low-power sleep mode. Internal pulldown. + +FAULT — can be connected to microcontroller input pin with pullup. +Logic low when driver in fault condition(overtemp, overcurrent). Not necessary connection. + +M0, M1, M2 — can be connected to microcontroller output pins to use microsteps, +it takes smoother movement of motor, but it not necessary connections. + +![circuit](./Drv8825_circuit_bb.jpeg) + +### Advices + +If you have DRV8825 module (not only chip), it is pin-compatible A4988 carrier. +It means for example that you can connect logic power supply to FAULT pin. +It will work for DRV8825 module (not just the chip!), but it is useless. If possible, try to avoid it. + +If you have long wires (more that few centimeters), it is recommended using a minimum +47uF electrolytic capacitor as close as possible to the VMOT and GND. + +Use a heat sink. The chip can get very hot before the temperature limiter kicks in. + +## Usage + +```csharp +const byte stepPin = 26; +const byte dirPin = 25; +const byte sleepPin = 27; +const ushort fullStepsPerRotation = 200; +const int fullRotationDegree = 360; +const int sleepDelayInMilliseconds = 100; +const int delayPerRotationsInMilliseconds = 5000; + +using (var motor = new Drv8825(stepPin, dirPin, sleepPin, fullStepsPerRotation)) +{ + var direction = true; + motor.WakeUp(); + for(var i = 1; i <= 10; i++) + { + var rotationDegree = (direction ? 1 : -1) * (fullRotationDegree * i); + motor.Rotate(UnitsNet.Angle.FromDegrees(rotationDegree)); + direction = !direction; + Thread.Sleep(delayPerRotationsInMilliseconds); + } + motor.Sleep(sleepDelayInMilliseconds); +} +``` + +So, you can rotate the motor not only with angle, but with steps too: + +```csharp +var steps = 100; +motor.Rotate(steps, Direction.Clockwise); +``` + +Also you can use microsteps. To do this you need to connect M0, M1 and M2 pins to microcontroller +and pass it to constructor: + +```csharp +const byte stepPin = 26; +const byte dirPin = 25; +const byte sleepPin = 27; +const byte m0Pin = 10; +const byte m1Pin = 11; +const byte m2Pin = 12; +const ushort fullStepsPerRotation = 200; +using (var motor = new Drv8825(stepPin, dirPin, sleepPin, fullStepsPerRotation, m0Pin: m0Pin, m1Pin: m1Pin, m2Pin: m2Pin)) +{ + var direction = true; + var steps = 3200; + motor.WakeUp(); + motor.Rotate(steps, Direction.Clockwise, StepSize.ThirtyTwoStep); + motor.Sleep(sleepDelayInMilliseconds); +} +``` \ No newline at end of file diff --git a/devices/Drv8825/Settings.StyleCop b/devices/Drv8825/Settings.StyleCop new file mode 100644 index 0000000000..b28d1f8bfd --- /dev/null +++ b/devices/Drv8825/Settings.StyleCop @@ -0,0 +1,112 @@ + + + + + + + False + + + + + False + + + + + False + + + + + True + + + + + True + + + + + True + + + + + False + + + + + False + + + + + False + + + + + False + + + + + True + True + + + + + + + False + + + + + False + + + + + + + + + + False + + + + + False + + + + + False + + + + + + + + + + False + + + + + False + + + + + + + diff --git a/devices/Drv8825/StepSize.cs b/devices/Drv8825/StepSize.cs new file mode 100644 index 0000000000..1953c49e2e --- /dev/null +++ b/devices/Drv8825/StepSize.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Iot.Device.Drv8825 +{ + /// + /// Enum for microsteps settings. + /// + public enum StepSize : byte + { + /// + /// No microsteps (full step). + /// + FullStep = 1, + + /// + /// 1/2 step. + /// + HalfStep = 2, + + /// + /// 1/4 step. + /// + QuaterStep = 4, + + /// + /// 1/8 step. + /// + EightStep = 8, + + /// + /// 1/16 step. + /// + SixteenStep = 16, + + /// + /// 1/32 step. + /// + ThirtyTwoStep = 32, + } +} diff --git a/devices/Drv8825/category.txt b/devices/Drv8825/category.txt new file mode 100644 index 0000000000..f6e39dfdd5 --- /dev/null +++ b/devices/Drv8825/category.txt @@ -0,0 +1 @@ +motor diff --git a/devices/Drv8825/packages.config b/devices/Drv8825/packages.config new file mode 100644 index 0000000000..2d1f6f23ee --- /dev/null +++ b/devices/Drv8825/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/devices/Drv8825/packages.lock.json b/devices/Drv8825/packages.lock.json new file mode 100644 index 0000000000..4384d9ba36 --- /dev/null +++ b/devices/Drv8825/packages.lock.json @@ -0,0 +1,49 @@ +{ + "version": 1, + "dependencies": { + ".NETnanoFramework,Version=v1.0": { + "nanoFramework.CoreLibrary": { + "type": "Direct", + "requested": "[1.17.11, 1.17.11]", + "resolved": "1.17.11", + "contentHash": "HezzAc0o2XrSGf85xSeD/6xsO6ohF9hX6/iMQ1IZS6Zw6umr4WfAN2Jv0BrPxkaYwzEegJxxZujkHoUIAqtOMw==" + }, + "nanoFramework.Runtime.Events": { + "type": "Direct", + "requested": "[1.11.32, 1.11.32]", + "resolved": "1.11.32", + "contentHash": "NyLUIwJDlpl5VKSd+ljmdDtO2WHHBvPvruo1ccaL+hd79z+6XMYze1AccOVXKGiZenLBCwDmFHwpgIQyHkM7GA==" + }, + "nanoFramework.System.Device.Gpio": { + "type": "Direct", + "requested": "[1.1.57, 1.1.57]", + "resolved": "1.1.57", + "contentHash": "Es7jHRrT/+0Ty9uJNzJUcTn+aCpjkxXnmsaM+g9HXvLZ8k4SDCCqmO9pT317nX+9ehmgGo2JKrtmkekgbOp+Pw==" + }, + "nanoFramework.System.Math": { + "type": "Direct", + "requested": "[1.5.116, 1.5.116]", + "resolved": "1.5.116", + "contentHash": "0S05UKcoI9Ukz9cMNPC9huFW9vSL42/4gIh4fw8ou8HkcFmTYb0OL8VF2Ah94hEDW5mqcYAVr0ipuGWPzIRqaA==" + }, + "Nerdbank.GitVersioning": { + "type": "Direct", + "requested": "[3.7.115, 3.7.115]", + "resolved": "3.7.115", + "contentHash": "EpXamaAdRfG/BMxGgvZlTM0npRnkmXUjAj8OdNKd17t4oN+2nvjdv/KnFmzOOMDqvlwB49UCwtOHJrAQTfUBtQ==" + }, + "StyleCop.MSBuild": { + "type": "Direct", + "requested": "[6.2.0, 6.2.0]", + "resolved": "6.2.0", + "contentHash": "6J51Kt5X+Os+Ckp20SFP1SlLu3tZl+3qBhCMtJUJqGDgwSr4oHT+eg545hXCdp07tRB/8nZfXTOBDdA1XXvjUw==" + }, + "UnitsNet.nanoFramework.Angle": { + "type": "Direct", + "requested": "[5.75.0, 5.75.0]", + "resolved": "5.75.0", + "contentHash": "AGKmNhDJNB16zlwPbPeMzVd/kbG2a4Pgxukm4mDdPV/oRNVPNc+V3lelurEFYFE5wyy3Kpu1F7JYQv6cq9jMsQ==" + } + } + } +} \ No newline at end of file diff --git a/devices/Drv8825/samples/Drv8825.samples.nfproj b/devices/Drv8825/samples/Drv8825.samples.nfproj new file mode 100644 index 0000000000..4dfc541e72 --- /dev/null +++ b/devices/Drv8825/samples/Drv8825.samples.nfproj @@ -0,0 +1,51 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + e8798205-e0d7-443f-b96a-8f752b7ef454 + Exe + Properties + 512 + Drv8825.samples + Drv8825.samples + v1.0 + + + + + ..\packages\nanoFramework.CoreLibrary.1.17.11\lib\mscorlib.dll + + + ..\packages\nanoFramework.Runtime.Events.1.11.32\lib\nanoFramework.Runtime.Events.dll + + + ..\packages\nanoFramework.System.Device.Gpio.1.1.57\lib\System.Device.Gpio.dll + + + ..\packages\nanoFramework.System.Math.1.5.116\lib\System.Math.dll + + + ..\packages\UnitsNet.nanoFramework.Angle.5.75.0\lib\UnitsNet.Angle.dll + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/devices/Drv8825/samples/Program.cs b/devices/Drv8825/samples/Program.cs new file mode 100644 index 0000000000..73ddaf8a51 --- /dev/null +++ b/devices/Drv8825/samples/Program.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Iot.Device.Drv8825; +using System.Threading; + +const byte StepPin = 26; +const byte DirPin = 25; +const byte SleepPin = 27; +const ushort FullStepsPerRotation = 200; +const int FullRotationDegree = 360; +const int SleepDelayInMilliseconds = 100; +const int DelayPerRotationsInMilliseconds = 5000; +Thread.Sleep(10000); + +using (var motor = new Drv8825(StepPin, DirPin, SleepPin, FullStepsPerRotation)) +{ + var boolDirection = true; + for(var i = 1; i <= 10; i++) + { + motor.WakeUp(); + var rotationDegree = (boolDirection ? 1 : -1) * (FullRotationDegree * i); + motor.Rotate(UnitsNet.Angle.FromDegrees(rotationDegree)); + boolDirection = !boolDirection; + motor.Sleep(SleepDelayInMilliseconds); + Thread.Sleep(DelayPerRotationsInMilliseconds); + } + + Thread.Sleep(DelayPerRotationsInMilliseconds); + + var direction = Direction.Clockwise; + motor.WakeUp(); + for (var steps = 1; steps <= FullStepsPerRotation; steps++) + { + motor.Rotate(steps, direction); + + if (direction == Direction.Clockwise) + { + direction = Direction.Counterclockwise; + } + else + { + direction = Direction.Clockwise; + } + } + motor.Sleep(); +} + +Thread.Sleep(Timeout.Infinite); \ No newline at end of file diff --git a/devices/Drv8825/samples/Properties/AssemblyInfo.cs b/devices/Drv8825/samples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..58c5a81e02 --- /dev/null +++ b/devices/Drv8825/samples/Properties/AssemblyInfo.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Iot.Device.Drv8825.Samples")] +[assembly: AssemblyCompany("nanoFramework Contributors")] +[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")] + +[assembly: ComVisible(false)] diff --git a/devices/Drv8825/samples/packages.config b/devices/Drv8825/samples/packages.config new file mode 100644 index 0000000000..5d1219276c --- /dev/null +++ b/devices/Drv8825/samples/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/devices/Drv8825/version.json b/devices/Drv8825/version.json new file mode 100644 index 0000000000..047be3367f --- /dev/null +++ b/devices/Drv8825/version.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", + "version": "1.1", + "semVer1NumericIdentifierPadding": 3, + "nuGetPackageVersion": { + "semVer": 2.0 + }, + "publicReleaseRefSpec": [ + "^refs/heads/develop$", + "^refs/heads/main$", + "^refs/heads/v\\d+(?:\\.\\d+)?$" + ], + "cloudBuild": { + "setAllVariables": true + } +} \ No newline at end of file