nanoFramework.Iot.Device.ServoMotor
1.2.696
Prefix Reserved
dotnet add package nanoFramework.Iot.Device.ServoMotor --version 1.2.696
NuGet\Install-Package nanoFramework.Iot.Device.ServoMotor -Version 1.2.696
<PackageReference Include="nanoFramework.Iot.Device.ServoMotor" Version="1.2.696" />
paket add nanoFramework.Iot.Device.ServoMotor --version 1.2.696
#r "nuget: nanoFramework.Iot.Device.ServoMotor, 1.2.696"
// Install nanoFramework.Iot.Device.ServoMotor as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.2.696 // Install nanoFramework.Iot.Device.ServoMotor as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.2.696
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
- Wikipedia Servo Motor
- Hobby Servo Tutorial
- How Servo Motors Work & How To Control Servos Using Arduino
- Arduino Servo Library
- Raspberry Pi Lesson 28: Controlling a Servo on Raspberry Pi with Python
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
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.System.Device.Pwm (>= 1.1.10)
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
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.696 | 136 | 12/16/2024 |
1.2.673 | 176 | 10/23/2024 |
1.2.631 | 337 | 8/28/2024 |
1.2.570 | 454 | 6/14/2024 |
1.2.436 | 859 | 11/10/2023 |
1.2.329 | 1,317 | 5/26/2023 |
1.2.313 | 411 | 5/12/2023 |
1.2.297 | 349 | 5/3/2023 |
1.2.203 | 2,107 | 12/28/2022 |
1.2.158 | 1,135 | 11/13/2022 |
1.2.141 | 1,998 | 10/25/2022 |
1.2.82 | 3,654 | 9/14/2022 |
1.1.113.2032 | 7,437 | 6/23/2022 |
1.1.58.10097 | 1,781 | 5/23/2022 |
1.1.1 | 608 | 4/14/2022 |
1.0.288-preview.113 | 143 | 3/25/2022 |
1.0.288-preview.20 | 269 | 1/27/2022 |
1.0.272 | 580 | 1/10/2022 |
1.0.263 | 373 | 12/24/2021 |
1.0.259 | 187 | 12/9/2021 |
1.0.218 | 244 | 10/18/2021 |
1.0.207 | 206 | 10/11/2021 |
1.0.191 | 186 | 9/29/2021 |
1.0.185 | 176 | 9/22/2021 |
1.0.181 | 193 | 9/22/2021 |