Show:

BO.io.Stepper Class

Creates an interface to a Stepper motor. Use this object to set the direction and number of steps for the motor to rotate. See Breakout/examples/actuators/stepper_2wire.html, stepper_4wire.html, stepper_easydriver.html and stepper_simple.html for example applications.

Constructor

BO.io.Stepper

(
  • board
  • driverType.
  • numStepsPerRev
  • directionPin
  • stepPin
  • motorPin3
  • motorPin4
)

Parameters:

  • board IOBoard

    A reference to the IOBoard instance that the stepper is attached to.

  • driverType. Number

    The type of driver (Stepper.DRIVER, Stepper.DRIVER_HIGH_CURRENT, Stepper.TWO_WIRE, or Stepper.FOUR_WIRE).

  • numStepsPerRev Number

    The number of steps to make 1 revolution.

  • directionPin Pin

    If dirver interface, the pin used to control the direction. If 2-wire or 4-wire interface, the 1st moter pin.

  • stepPin Pin

    If dirver interface, the pin used to control the steps. If 2-wire or 4-wire interface, the 2nd moter pin.

  • motorPin3 Pin

    [optional] Only required for a 4-wire interface.

  • motorPin4 Pin

    [optional] Only required for a 4-wire interface.

Example:

var Stepper = BO.io.Stepper,
    Event = JSUTILS.Event;

var stepper,
    stepsPerRev = 200,           // update this for your stepper
    numSteps = stepsPerRev * 10, // 10 revolutions (+ CW, - CCW)
    speed = 15.0,                // rad/sec (RPM = speed * 9.55)
    acceleration = 20.0,         // rad/sec^2
    deceleration = 20.0;         // rad/sec^2

stepper = new Stepper(arduino,
             Stepper.TWO_WIRE, // or Stepper.DRIVER or Stepper.FOUR_WIRE
             stepsPerRev,
             arduino.getDigitalPin(2),
             arduino.getDigitalPin(3));

stepper.addEventListener(Event.COMPLETE, onStepperComplete);

// acceleration and deceleration parameters are optional
stepper.step(numSteps, speed, acceleration, deceleration);

function onStepperComplete(event) {
    // each stepper is assigned a read-only id value when instantiated
    console.log("stepper " + event.target.id + " sequence complete");
}

Methods

addEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

dispatchEvent

(
  • type
  • optionalParams
)

Parameters:

  • type Event

    The Event object.

  • optionalParams Object

    Optional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.

hasEventListener

(
  • type
)

Parameters:

  • type String

    The event type return {boolean} True is listener exists for this type, false if not.

onSysExMessage

() private

Listen for stepping complete event

removeEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

step

(
  • numSteps
  • speed
  • accel
  • decel
)

Move the stepper a given number of steps at the specified speed (rad/sec), acceleration (rad/sec^2) and deceleration (rad/sec^2). The accel and decel parameters are optional but if using, both values must be passed to the function.

Parameters:

  • numSteps Number

    The number ofsteps to move the motor (max = +/-2097151 (21 bits)). Positive value is clockwise, negative value is counter clockwise.

  • speed Number

    Max speed in rad/sec (1 rad/sec = 9.549 RPM) (max precision of 2 decimal places)

  • accel Number

    [optional] Acceleration in rad/sec^2 (max precision of 2 decimal places)

  • decel Number

    [optional] Deceleration in rad/sec^2 (max precision of 2 decimal places)

Properties

id

Number

[read-only] The id of the Stepper object instance. Each stepper motor is given a unique id upon initialization.

Stepper.CLOCKWISE

Unknown static

Stepper.COUNTER_CLOCKWISE

Unknown static

Stepper.DRIVER

Unknown static

Uses 1 microsecond delay between steps

Stepper.DRIVER_HIGH_CURRENT

Unknown static

Uses 2 microsecond delay between steps

Stepper.FOUR_WIRE

Unknown static

Stepper.TWO_WIRE

Unknown static