nanoFramework.Iot.Device.ServoMotor 1.0.259

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.ServoMotor --version 1.0.259
                    
NuGet\Install-Package nanoFramework.Iot.Device.ServoMotor -Version 1.0.259
                    
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.ServoMotor" Version="1.0.259" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.ServoMotor" Version="1.0.259" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.ServoMotor" />
                    
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.ServoMotor --version 1.0.259
                    
#r "nuget: nanoFramework.Iot.Device.ServoMotor, 1.0.259"
                    
#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.
#addin nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.0.259
                    
Install nanoFramework.Iot.Device.ServoMotor as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.0.259
                    
Install nanoFramework.Iot.Device.ServoMotor as a Cake Tool

Servo Motor

This is a generic binding to control many servo motors using a hardware or software PwmChannel. Servo motors are usually based on a signal frequency of 50Hz. They also require a minimum/maximum pulse width to determine the position. The pulse width is generally between 1 and 2 milliseconds, where 1ms is approximately 0 degrees, 1.5ms is the rest position, and 2ms is 180 degrees. This information can be found in each servo motor's datasheet.

One thing to be aware of is the wiring as the servo motor connector is usually a 3-pin connector. The pinout is shown below where colors can vary.

Pin Number Signal Color
1 Ground Black or Brown
2 Power Supply Brown or Red
3 Control Signal Orange or White or Yellow

Documentation

There are many servo motor sizes available that offer both standard and continuous rotation. Below are a few links where to purchase servo motors.

Board

schema

Usage

The ServoMotor binding offers an easy way to begin controlling a servo motor. The quickest approach is to provide the ServoMotor object a PwmChannel using the default values for other optional arguments.

// Example of hardware PWM using chip 0 and channel 0 on a dev board.
ServoMotor servoMotor = new ServoMotor(PwmChannel.Create(0, 0, 50));
servoMotor.Start();  // Enable control signal.

// Move position.  Pulse width argument is in microseconds.
servoMotor.WritePulseWidth(1000); // 1ms; Approximately 0 degrees.
servoMotor.WritePulseWidth(1500); // 1.5ms; Approximately 90 degrees.
servoMotor.WritePulseWidth(2000); // 2ms; Approximately 180 degrees.

servoMotor.Stop(); // Disable control signal.

The position of servo motor can also be adjusted by the angle. The ServoMotor constructor's optional arguments must be set according to device's specs. NOTE: These are usually an approximation, so you may need to manually tweak to determine exact values.

For example, the Hitec HS-300BB servo has the following specifications:

  • MaximumAngle = 180
  • MinimumPulseWidthMicroseconds = 900
  • MaximumPulseWidthMicroseconds = 2100
  • Frequency 50Hz; Period 20000uS

// When using an ESP32, you have to setup the pin function then create the PWM channel
Configuration.SetPinFunction(21, DeviceFunction.PWM1);

using PwmChannel pwmChannel = PwmChannel.CreateFromPin(21, 50);
ServoMotor servoMotor = new ServoMotor(
    PwmChannel,
    180,
    900,
    2100);

servoMotor.Start();  // Enable control signal.

// Move position.
servoMotor.WriteAngle(0); // ~0.9ms; Approximately 0 degrees.
servoMotor.WritePulseWidth(90); // ~1.5ms; Approximately 90 degrees.
servoMotor.WritePulseWidth(180); // ~2.1ms; Approximately 180 degrees.

servoMotor.Stop(); // Disable control signal.

Calibration

Calibration or finding minimum and maximum pulse width and angle range WritePulseWidth method should be used. To make it easier to write applications which allow calibration method Calibrate can be used to change calibration parameters.

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.ServoMotor:

Package Downloads
nanoFramework.MagicBit

This package includes nanoFramework.MagicBit, a board package library for MagicBit in .NET nanoFramework C# projects.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on nanoFramework.Iot.Device.ServoMotor:

Repository Stars
nanoframework/Samples
🍬 Code samples from the nanoFramework team used in testing, proof of concepts and other explorational endeavours
Version Downloads Last updated
1.2.864 307 4/2/2025
1.2.852 242 3/11/2025
1.2.822 247 2/26/2025
1.2.772 272 2/4/2025
1.2.755 208 1/31/2025
1.2.737 307 1/13/2025
1.2.696 325 12/16/2024
1.2.673 205 10/23/2024
1.2.631 359 8/28/2024
1.2.570 473 6/14/2024
1.2.436 869 11/10/2023
1.2.329 1,335 5/26/2023
1.2.313 429 5/12/2023
1.2.297 367 5/3/2023
1.2.203 2,129 12/28/2022
1.2.158 1,162 11/13/2022
1.2.141 2,021 10/25/2022
1.2.82 3,676 9/14/2022
1.1.113.2032 7,461 6/23/2022
1.1.58.10097 1,807 5/23/2022
1.1.1 636 4/14/2022
1.0.288-preview.113 177 3/25/2022
1.0.288-preview.20 301 1/27/2022
1.0.272 612 1/10/2022
1.0.263 407 12/24/2021
1.0.259 220 12/9/2021
1.0.218 277 10/18/2021
1.0.207 241 10/11/2021
1.0.191 220 9/29/2021
1.0.185 209 9/22/2021
1.0.181 227 9/22/2021