nanoFramework.Iot.Device.DCMotor
1.0.288-preview.100
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.DCMotor --version 1.0.288-preview.100
NuGet\Install-Package nanoFramework.Iot.Device.DCMotor -Version 1.0.288-preview.100
<PackageReference Include="nanoFramework.Iot.Device.DCMotor" Version="1.0.288-preview.100" />
paket add nanoFramework.Iot.Device.DCMotor --version 1.0.288-preview.100
#r "nuget: nanoFramework.Iot.Device.DCMotor, 1.0.288-preview.100"
// Install nanoFramework.Iot.Device.DCMotor as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.DCMotor&version=1.0.288-preview.100&prerelease // Install nanoFramework.Iot.Device.DCMotor as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.DCMotor&version=1.0.288-preview.100&prerelease
DC Motor Controller
This is a generic class to control any DC motor.
DC motors are controlled by simply providing voltage on the inputs (inverted voltage inverts the direction).
DC motors can be controlled with 1, 2 or 3 pins. Please refer to the sample to see how to connect it.
Never connect DC motor directly to your board, instead use i.e. H-bridge
3- vs 1/2-pin mode
2/1-pin mode should be used only if H-bridge allows the inputs to be changed frequently otherwise excessive heat or damage may occur which may reduce life-time of the H-bridge. It may also cause increased energy consumption due to energy being converted into heat.
Usage
See full sample for more details.
static void Main(string[] args)
{
const double Period = 10.0;
Stopwatch sw = Stopwatch.StartNew();
// 1 pin mode
// using (DCMotor motor = DCMotor.Create(6))
// using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50)))
// 2 pin mode
// using (DCMotor motor = DCMotor.Create(27, 22))
// using (DCMotor motor = DCMotor.Create(new SoftwarePwmChannel(27, frequency: 50), 22))
// 2 pin mode with BiDirectional Pin
// using (DCMotor motor = DCMotor.Create(19, 26, null, true, true))
// using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 1, 100, 0.0), 26, null, true, true))
// 3 pin mode
// using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50), 23, 24))
// Start Stop mode - wrapper with additional methods to disable/enable output regardless of the Speed value
// using (DCMotorWithStartStop motor = new DCMotorWithStartStop(DCMotor.Create( _any version above_ )))
using (DCMotor motor = DCMotor.Create(6, 27, 22))
{
bool done = false;
string lastSpeedDisp = null;
while (!done)
{
double time = sw.ElapsedMilliseconds / 1000.0;
// Note: range is from -1 .. 1 (for 1 pin setup 0 .. 1)
motor.Speed = Math.Sin(2.0 * Math.PI * time / Period);
string disp = $"Speed = {motor.Speed:0.00}";
if (disp != lastSpeedDisp)
{
lastSpeedDisp = disp;
Debug.WriteLine(disp);
}
Thread.Sleep(1);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.12.0-preview.19)
- nanoFramework.Runtime.Events (>= 1.10.0-preview.4)
- nanoFramework.System.Device.Gpio (>= 1.0.3-preview.18)
- nanoFramework.System.Device.Pwm (>= 1.0.1-preview.13)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on nanoFramework.Iot.Device.DCMotor:
Package | Downloads |
---|---|
nanoFramework.MagicBit
This package includes nanoFramework.MagicBit, a board package library for MagicBit in .NET nanoFramework C# projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.673 | 118 | 10/23/2024 |
1.2.631 | 330 | 8/28/2024 |
1.2.570 | 455 | 6/14/2024 |
1.2.560 | 181 | 5/29/2024 |
1.2.548 | 211 | 5/15/2024 |
1.2.436 | 649 | 11/10/2023 |
1.2.329 | 1,228 | 5/26/2023 |
1.2.313 | 353 | 5/12/2023 |
1.2.297 | 308 | 5/3/2023 |
1.2.203 | 2,035 | 12/28/2022 |
1.2.141 | 2,631 | 10/25/2022 |
1.2.122 | 1,874 | 10/12/2022 |
1.2.114 | 981 | 10/8/2022 |
1.2.95 | 742 | 9/22/2022 |
1.2.87 | 1,106 | 9/15/2022 |
1.2.73 | 1,059 | 9/8/2022 |
1.1.113.2032 | 7,062 | 6/23/2022 |
1.1.58.10097 | 1,724 | 5/23/2022 |
1.1.3 | 553 | 4/15/2022 |
1.1.1 | 461 | 4/14/2022 |
1.0.300 | 477 | 3/31/2022 |
1.0.288-preview.114 | 138 | 3/25/2022 |
1.0.288-preview.113 | 119 | 3/25/2022 |
1.0.288-preview.100 | 136 | 3/19/2022 |
1.0.288-preview.99 | 128 | 3/18/2022 |
1.0.288-preview.98 | 117 | 3/18/2022 |
1.0.288-preview.94 | 148 | 3/15/2022 |
1.0.288-preview.93 | 121 | 3/15/2022 |
1.0.288-preview.86 | 144 | 3/8/2022 |
1.0.288-preview.65 | 156 | 2/18/2022 |
1.0.288-preview.48 | 178 | 2/4/2022 |
1.0.288-preview.42 | 144 | 1/31/2022 |
1.0.288-preview.41 | 137 | 1/31/2022 |
1.0.288-preview.29 | 142 | 1/28/2022 |
1.0.288-preview.22 | 141 | 1/27/2022 |
1.0.288-preview.20 | 134 | 1/27/2022 |
1.0.288-preview.19 | 145 | 1/27/2022 |
1.0.288-preview.18 | 136 | 1/27/2022 |
1.0.288-preview.5 | 149 | 1/24/2022 |
1.0.288-preview.3 | 132 | 1/21/2022 |
1.0.288-preview.1 | 130 | 1/21/2022 |
1.0.272 | 205 | 1/10/2022 |
1.0.263 | 299 | 12/24/2021 |
1.0.260 | 170 | 12/10/2021 |
1.0.259 | 176 | 12/9/2021 |
1.0.218 | 220 | 10/18/2021 |
1.0.183 | 194 | 9/22/2021 |