Main Content

Servo

Create connection to servo motor

Description

servo(mypi,pinNumber)creates a servo motor object connected to the specified pin on the Raspberry Pi™.

servo(mypi,pinNumber,Name,Value)creates a servo motor object with additional options specified by one or more Name, Value pair arguments.

Input Arguments

collapse all

Connection to a specific Raspberry Pi hardware board, specified as araspiobject.

GPIO pin number, specified as a scalar. This argument does not accept vectors because the hardware cannot access multiple pins simultaneously.

To get a list of valid pin numbers, entermypi.AvailableDigitalPins.

Example:12

Data Types:double

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:s= servo(a, 7, 'MaxPulseDuration', 2e-3, 'MinPulseDuration', 1e-3);

Minimum pulse duration specified as the comma-separated pair consisting of'MinPulseDuration'and a number, which represents the duration in seconds. Specified value must be equal to the width of the pulse the motor needs to be at the minimum angle. Refer to your device data sheet for valid values.

Maximum pulse duration specified as the comma-separated pair consisting of'MaxPulseDuration'and a number, which represents the duration in seconds. Specified value must be equal to width of the pulse the motor needs to be at the maximum angle. Refer to your device data sheet for valid values.

Output Arguments

collapse all

Servo object returned as an object.

Examples

collapse all

Create anraspiobject, and attach the servo object to pin 12.

mypi = raspi() s = servo(mypi,12)
s = Servo with properties: Pins: 12 MinPulseDuration: 5.44e-04 (s) MaxPulseDuration: 2.40e-03 (s)

Set the minimum duration to 7e-4 and maximum to 2.3e-3 seconds.

Create anraspiobject and attach the servo object to digital pin 12 and specify

mypi = raspi() s = servo(mypi,12,'MinPulseDuration',7.00e-4,'MaxPulseDuration',2.3e-3)
s = Servo with properties: Pins: 12 MinPulseDuration: 7.00e-04 (s) MaxPulseDuration: 2.30e-03 (s)

Extended Capabilities

版本历史

Introduced in R2016b

See Also

|

Topics