nanoFramework.Iot.Device.DCMotor 1.0.288-preview.3

Prefix Reserved
This is a prerelease version of nanoFramework.Iot.Device.DCMotor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.DCMotor --version 1.0.288-preview.3
                    
NuGet\Install-Package nanoFramework.Iot.Device.DCMotor -Version 1.0.288-preview.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.DCMotor" Version="1.0.288-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.DCMotor" Version="1.0.288-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.DCMotor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.Iot.Device.DCMotor --version 1.0.288-preview.3
                    
#r "nuget: nanoFramework.Iot.Device.DCMotor, 1.0.288-preview.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nanoFramework.Iot.Device.DCMotor@1.0.288-preview.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.Iot.Device.DCMotor&version=1.0.288-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.DCMotor&version=1.0.288-preview.3&prerelease
                    
Install as a Cake Tool

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);
        }
    }
}

schematics

BiDirectional Pin schematics

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.907 214 10/2/2025
1.2.864 476 4/2/2025
1.2.852 342 3/11/2025
1.2.822 357 2/26/2025
1.2.775 396 2/4/2025
1.2.772 244 2/4/2025
1.2.755 348 1/31/2025
1.2.737 393 1/13/2025
1.2.696 400 12/16/2024
1.2.673 319 10/23/2024
1.2.631 550 8/28/2024
1.2.570 777 6/14/2024
1.2.560 295 5/29/2024
1.2.548 341 5/15/2024
1.2.436 874 11/10/2023
1.2.329 1,818 5/26/2023
1.2.313 500 5/12/2023
1.2.297 445 5/3/2023
1.2.203 2,387 12/28/2022
1.2.141 2,916 10/25/2022
1.2.122 2,068 10/12/2022
1.2.114 1,127 10/8/2022
1.2.95 868 9/22/2022
1.2.87 1,241 9/15/2022
1.2.73 1,234 9/8/2022
1.1.113.2032 7,487 6/23/2022
1.1.58.10097 1,931 5/23/2022
1.1.3 668 4/15/2022
1.1.1 578 4/14/2022
1.0.300 585 3/31/2022
1.0.288-preview.114 234 3/25/2022
1.0.288-preview.113 217 3/25/2022
1.0.288-preview.100 258 3/19/2022
1.0.288-preview.99 224 3/18/2022
1.0.288-preview.98 220 3/18/2022
1.0.288-preview.94 244 3/15/2022
1.0.288-preview.93 244 3/15/2022
1.0.288-preview.86 238 3/8/2022
1.0.288-preview.65 268 2/18/2022
1.0.288-preview.48 275 2/4/2022
1.0.288-preview.42 271 1/31/2022
1.0.288-preview.41 264 1/31/2022
1.0.288-preview.29 249 1/28/2022
1.0.288-preview.22 240 1/27/2022
1.0.288-preview.20 250 1/27/2022
1.0.288-preview.19 266 1/27/2022
1.0.288-preview.18 232 1/27/2022
1.0.288-preview.5 246 1/24/2022
1.0.288-preview.3 258 1/21/2022
1.0.288-preview.1 225 1/21/2022
1.0.272 309 1/10/2022
1.0.263 444 12/24/2021
1.0.260 288 12/10/2021
1.0.259 279 12/9/2021
1.0.218 341 10/18/2021
1.0.183 308 9/22/2021