UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

StepMotor Class

Module: stepmotor

This module defines the Stepper Motor interface. It is compatible with stepper motor drivers that use 2 pins to control the motor, like an Easy Driver from Brian Schmalz or the STR driver series from Applied Motion. It can also control an enable pin if one is available and connected.
The implementation is synchronous and thus blocking while the stepper motor is in motion. However it is possible to send the commands via threading and the performance of the library will be very good given a low CPU load. On a busy system though you will notice some jitter especially at higher speeds. It is possible to reduce this effect to some extent by using smoothing and/or microstepping on stepper drivers that support such features.
stepmotor.jpg

Methods

StepMotor

(
  • dirPin
  • stePin
  • steps
  • enPin
)
Number

Instantiates a StepMotor object.

Parameters:

  • dirPin Number

    Direction GPIO pin

  • stePin Number

    Stepper pulse GPIO pin

  • steps Number

    Number of steps per revolution (Default 200)

  • enPin Number

    Enable pin if connected (Optional)

Returns:

Number:

enable

(
  • flag
)

Can be used to enable/disable the stepper driver if an enable pin is available and connected. Check your data sheet as some drivers might have the enable logic inverted.

Parameters:

  • flag Boolean

    true to enable or false to disable

setSpeed

(
  • speed
)

Sets the rotation speed in rpm. Default 60 rpm.

Parameters:

  • speed Number

    Rotation speed in rpm

step

(
  • ticks
)
Mraa::Result

Rotates the motor by the specified number of steps. Positive values rotate clockwise and negative values rotate counter-clockwise.

Parameters:

  • ticks Number

    Number of steps the motor moves

Returns:

Mraa::Result:

stepForward

(
  • ticks
)
Mraa::Result

Rotates the motor forward (clockwise).

Parameters:

  • ticks Number

    Number of steps the motor moves

Returns:

Mraa::Result:

stepBackward

(
  • ticks
)
Mraa::Result

Rotates the motor backward (counter-clockwise).

Parameters:

  • ticks Number

    Number of steps the motor moves

Returns:

Mraa::Result:

setPosition

(
  • pos
)

Sets the current position. Useful if the motor is not at 0 when the driver is initialized.

Parameters:

  • pos Number

    Current position

getPosition

() Number

Gets the current position. This is cumulative and the result of all the step commands sent to the motor.

Returns:

Number:

Stepper's position.

getStep

() Number

Gets the current step. This is relative to one revolution.

Returns:

Number:

Current step, ranges from 0 to number of steps per revolution.