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.

L298 Class

Module: l298

It was developed using the RobotBase Dual H-Bridge module.
This module can support 2 DC motors, or one 2-phase stepper motor. It requires 3 pins per DC motor (or H-bridge), or 4 pins for the stepper motor (uses both H-bridges).
l298.jpg
Example driving a DC motor Example driving a stepper motor

Methods

L298

(
  • pwm
  • dir1
  • dir2
)
Number

L298 constructor for DC motor(s) connected.

Parameters:

  • pwm Number

    Digital pin to use for a DC motor - must be PWM-capable

  • dir1 Number

    Digital pin to use for motor direction pin 1

  • dir2 Number

    Digital pin to use for motor direction pin 2

Returns:

Number:

L298

(
  • stepsPerRev
  • en
  • i1
  • i2
  • i3
  • i4
)
Number

L298 constructor for a 4-wire stepper motor

Parameters:

  • stepsPerRev Number

    Number of steps per full revolution

  • en Number

    Enables the pin

  • i1 Number

    Digital pin to use for stepper input 1

  • i2 Number

    Digital pin to use for stepper input 2

  • i3 Number

    Digital pin to use for stepper input 3

  • i4 Number

    Digital pin to use for stepper input 4

Returns:

Number:

getMillis

() Number

Returns the number of milliseconds elapsed since initClock() was last called.

Returns:

Number:

Elapsed milliseconds

initClock

()

Resets the clock

setPeriodMS

(
  • ms
)

Sets the period in milliseconds

Parameters:

  • ms Number

    Period in milliseconds

enable

(
  • enable
)

Enables the PWM output for a motor

Parameters:

  • enable Boolean

    Enables the PWM output if true, disables if false

setSpeed

(
  • speed
)

Sets the speed of a DC or stepper motor. For a DC motor, values can range from 0 (off) to 100 (full speed). For a stepper motor, specify the desired RPM.

Parameters:

  • speed Number

    Speed to set the motor to

setDirection

(
  • dir
)

Sets the direction of the motor, clockwise or counterclockwise

Parameters:

  • dir L298_DIRECTION_T

    Direction to set the motor to

stepperSteps

(
  • steps
)

Steps the stepper motor a specified number of steps

Parameters:

  • steps Number

    Number of steps to move the stepper motor

Properties

DIR_NONE

Enum L298_DIRECTION_T

DIR_CW

Enum L298_DIRECTION_T

DIR_CCW

Enum L298_DIRECTION_T