Main Content

servo

Create connection to servo motor

    Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.

    Description

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

    example

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

    example

    Examples

    collapse all

    Create an raspi object, and attach the servo object to pin 12.

    mypi = raspi()
    s = servo(mypi,12)
    s = 
    
      Servo with properties:
    
                     Pin: 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:
    
                     Pin: 12
        MinPulseDuration: 7.00e-04 (s)
        MaxPulseDuration: 2.30e-03 (s)

    Input Arguments

    collapse all

    Connection to the 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 Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is 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 enclose Name in 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. The value can lie in between the range 5.00e-04 and 1.50e-03.

    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. The value can lie in between the range 1.50e-03 and 2.50e-03.

    Output Arguments

    collapse all

    Servo object returned as an object.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2016b

    See Also