stepper

Connection to stepper motor on Adafruit Motor Shield V2 for Arduino

Description

A stepper object represents a connection to a stepper motor on an Adafruit® Motor Shield V2 connected to Arduino® hardware. Attach a motor shield to the Arduino hardware, and connect a stepper motor to the appropriate pins on the motor shield. Create a motor shield object using the addon function, and create a stepper object using the stepper function. You can control your stepper motor in MATLAB® using the object functions.

Creation

Description

example

sm = stepper(shield,motornum,sprev) creates a stepper motor connection with the specified motor number and steps per revolution on an Adafruit Motor Shield.

example

sm = stepper(shield,motornum,sprev,Name,Value) adds additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Adafruit Motor Shield connection on Arduino hardware, specified as an adafruit motor shield object created using the addon function.

Example: sm = stepper(shield,1,200) creates a connection to a stepper motor on the specified adafruit motor shield object shield.

Stepper motor number where the motor is connected on the Adafruit Motor Shield, specified as a number. Valid values are 1 and 2. If you are using ports M1 and M2 on the shield, set motor number to 1. If you are using M3 and M4, set motor number to 2.

Example: sm = stepper(shield,1,200) creates a connection to a stepper motor on port M1 or M2 on the motor shield.

Steps per revolution of the stepper motor, specified as a number. Steps per revolution depend on your motor. For example, a 7.5 degree/step stepper motor has 360/7.5 = 48 steps.

Example: sm = stepper(shield,1,200) creates a connection to a stepper motor with 200 steps per revolution, or a 1.8 degree/step stepper motor.

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: sm = stepper(shield,1,200,'RPM',10,'StepType','interleave')

Revolutions per minute, specified as the comma-separated pair consisting of 'RPM' and a number. RPM determines the speed of the motor.

Example: sm = stepper(shield,1,200,'RPM',10) creates a stepper motor connection with an RPM of 10.

Coil activation type, specified as the comma-separated pair consisting of 'StepType' and a character vector. The default value is 'Single'. Valid character vectors are:

  • 'Single'

  • 'Double'

  • 'Interleave'

  • 'Microstep'

Example: sm = stepper(shield,1,200,'stepType','interleave') creates a stepper motor connection with an interleaved step type.

Properties

expand all

Revolutions per minute, specified as a number. RPM determines the speed of the motor. You can specify the revolutions per minute when you create the stepper object or after you create the stepper object.

Example:

>> sm.RPM = 10

sm = 

  stepper with properties:

           MotorNumber: 2              
    StepsPerRevolution: 200            
                   RPM: 10             
              StepType: Single ('Single', 'Double', 'Interleave', 'Microstep')

Data Types: double

This property is read-only.

Coil activation type, specified as the comma-separated pair consisting of 'StepType' and a character vector. The default value is 'Single'. Valid character vectors are:

  • 'Single'

  • 'Double'

  • 'Interleave'

  • 'Microstep'

Example:

>> sm.StepType

ans =

    'Single'

Data Types: char

This property is read-only.

Motor shield port number that displays the number of the port on the Adafruit Motor Shield to which the stepper motor is connected, specified as a number during the stepper motor object creation. Valid port values are 1 and 2.

Example:

>> sm.MotorNumber

ans =

     2

Data Types: double

This property is read-only.

Number of steps that the stepper motor rotates each revolution, specified as a number during the stepper motor object creation.

Example:

>> sm.StepsPerRevolution

ans =

   200

Data Types: double

Object Functions

Use these object functions to control your stepper motor.

moveRotate stepper motor connected to Adafruit Motor Shield
releaseRelease stepper motor connected to Adafruit Motor Shield

Examples

collapse all

Create a stepper motor connection to an Adafruit Motor Shield attached to Arduino hardware.

a = arduino('COM4','Uno','Libraries','Adafruit/MotorShieldV2');
shield = addon(a,'Adafruit/MotorShieldV2');

Create a stepper motor connection to motor number 1 on the shield, with steps per revolution of 200 and an RPM of 10.

sm = stepper(shield,1,200,'RPM',10)
sm = 
  stepper with properties:

           MotorNumber: 1              
    StepsPerRevolution: 200            
                   RPM: 10             
              StepType: Single ('Single', 'Double', 'Interleave', 'Microstep')

Create a stepper motor connection to an Adafruit Motor Shield attached to Arduino hardware.

a = arduino('COM4','Uno','Libraries','Adafruit/MotorShieldV2');
shield = addon(a,'Adafruit/MotorShieldV2');

Create a stepper motor connection to motor number 1 on the shield, with the steps per revolution of 200, an RPM of 10, and 'steptype' set to 'Interleave'.

sm = stepper(shield,1,200,'RPM',10,'stepType','Interleave')
sm = 
  stepper with properties:

           MotorNumber: 1              
    StepsPerRevolution: 200            
                   RPM: 10             
              StepType: Interleave ('Single', 'Double', 'Interleave', 'Microstep')

Introduced in R2014b