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 a raspi object.

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, enter mypi.AvailableDigitalPins.

Example: 12

Data Types: double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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 a servo object using pin 3.

Create an raspi object, 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 an raspi object 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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

|

Introduced in R2016b