nanoFramework.Iot.Device.ServoMotor
1.1.1
Prefix Reserved
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.ServoMotor --version 1.1.1
NuGet\Install-Package nanoFramework.Iot.Device.ServoMotor -Version 1.1.1
<PackageReference Include="nanoFramework.Iot.Device.ServoMotor" Version="1.1.1" />
paket add nanoFramework.Iot.Device.ServoMotor --version 1.1.1
#r "nuget: nanoFramework.Iot.Device.ServoMotor, 1.1.1"
// Install nanoFramework.Iot.Device.ServoMotor as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.1.1 // Install nanoFramework.Iot.Device.ServoMotor as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.ServoMotor&version=1.1.1
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.12.0)
- nanoFramework.System.Device.Pwm (>= 1.0.1)
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.673 | 112 | 10/23/2024 |
1.2.631 | 327 | 8/28/2024 |
1.2.570 | 441 | 6/14/2024 |
1.2.436 | 846 | 11/10/2023 |
1.2.329 | 1,309 | 5/26/2023 |
1.2.313 | 403 | 5/12/2023 |
1.2.297 | 340 | 5/3/2023 |
1.2.203 | 2,098 | 12/28/2022 |
1.2.158 | 1,127 | 11/13/2022 |
1.2.141 | 1,992 | 10/25/2022 |
1.2.82 | 3,644 | 9/14/2022 |
1.1.113.2032 | 7,427 | 6/23/2022 |
1.1.58.10097 | 1,773 | 5/23/2022 |
1.1.1 | 596 | 4/14/2022 |
1.0.288-preview.113 | 139 | 3/25/2022 |
1.0.288-preview.20 | 265 | 1/27/2022 |
1.0.272 | 572 | 1/10/2022 |
1.0.263 | 365 | 12/24/2021 |
1.0.259 | 177 | 12/9/2021 |
1.0.218 | 234 | 10/18/2021 |
1.0.207 | 196 | 10/11/2021 |
1.0.191 | 176 | 9/29/2021 |
1.0.185 | 168 | 9/22/2021 |
1.0.181 | 183 | 9/22/2021 |