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.

GroveMD Class

Module: grovemd
  • ID: grovemd
  • Name: I2C Motor Driver
  • Category: motor
  • Manufacturer: seeed
  • Connection: i2c
  • Kit: robok

This class implements support for the Grove I2C Motor Driver. This device can support a single 4-wire stepper motor, or two 2-wire DC motors. The device contains an Atmel* ATmega8L microcontroller that manages an L298N H-bridge driver chip.
This device supports an I2C bus speed of 100Khz only.
The module does not provide any telemetry or status - it only accepts I2C commands for its various operations.
This module was tested with version 1.3 of the Grove I2C Motor Driver.
For stepper operation, this driver can run in one of two modes - Mode 1, where this driver handles the stepping operation, and Mode 2, where this driver simply sends commands to the Grove Motor Driver, and it handles the stepping operation. Mode2 requires updated (and working) firmware to be loaded onto the device.
The default stepper operation mode is Mode1, which is generally more flexible and is supported on all firmware revisions.
grovemd.jpg An example showing the use of a DC motor An example showing the use of a 4-wire stepper

Methods

GroveMD

(
  • bus
  • address
)
Number

GroveMD constructor

Parameters:

  • bus Number

    I2C bus to use

  • address Number

    I2C address to use

Returns:

Number:

writePacket

(
  • reg
  • data1
  • data2
)
Boolean

Composes and writes a 3-byte packet to the controller

Parameters:

  • reg REG_T

    Register location

  • data1 Number

    First byte of data

  • data2 Number

    Second byte of data

Returns:

Boolean:

True if successful

setMotorSpeeds

(
  • speedA
  • speedB
)
Boolean

To control DC motors, sets the speed of motors A & B. Valid values are 0-255.

Parameters:

  • speedA Number

    Speed of motor A

  • speedB Number

    Speed of motor B

Returns:

Boolean:

True if successful

setPWMFrequencyPrescale

(
  • freq
)
Boolean

To control DC motors, sets the PWM frequency prescale factor. Note: this register is not ducumented other than to say the default value is 0x03. Presumably, this is the timer prescale factor used on the ATMega MCU timer driving the PWM.

Parameters:

  • freq Number

    PWM prescale frequency; default is 0x03

Returns:

Boolean:

True if successful

setMotorDirections

(
  • dirA
  • dirB
)
Boolean

To control DC motors, sets the directions of motors A & B

Parameters:

  • dirA DC_DIRECTION_T

    Direction for motor A, DIR_CW or DIR_CCW

  • dirB DC_DIRECTION_T

    Direction for motor B, DIR_CW or DIR_CCW

Returns:

Boolean:

True if successful

enableStepper

(
  • dir
  • speed
)
Boolean

To control a stepper motor, sets its direction and speed, and then starts operation. For Mode2, this method will return immediately. For Mode1 (the default) this method returns when the number of steps specified by setStepperSteps() has completed.

Parameters:

  • dir STEP_DIRECTION_T

    Direction, STEP_DIR_CW or STEP_DIR_CCW

  • speed Number

    Motor speed. Valid range is 1-255. For Mode 1 (default), this specifies the speed in RPM's. For Mode 2, speed is multiplied by 4ms by the board, so higher numbers will mean a slower speed.

Returns:

Boolean:

True if successful

disableStepper

() Boolean

To control a stepper motor, stops the stepper motor.

Returns:

Boolean:

True if successful

setStepperSteps

(
  • steps
)
Boolean

To control a stepper motor, specifies the number of steps to execute. For Mode2, valid values are between 1-255, 255 means continuous rotation.
For Mode1 (the default) steps can be any positive integer.

Parameters:

  • steps Number

    Number of steps to execute. 255 (only in Mode2) means continuous rotation.

Returns:

Boolean:

True if successful

configStepper

(
  • stepsPerRev
  • mode
)

Configure the initial Stepper parameters. This should be called before any other stepper method.

Parameters:

  • stepsPerRev Number

    The number of steps required to complete one full revolution.

  • mode STEP_MODE_T

    The stepper operating mode, default STEP_MODE1

Properties

SET_SPEED

Enum REG_T

SET_PWM_FREQ

Enum REG_T

SET_DIRECTION

Enum REG_T

SET_MOTOR_A

Enum REG_T

SET_MOTOR_B

Enum REG_T

STEPPER_ENABLE

Enum REG_T

STEPPER_DISABLE

Enum REG_T

STEPPER_NUM_STEPS

Enum REG_T

STEP_DIR_CCW

Enum STEP_DIRECTION_T

STEP_DIR_CW

Enum STEP_DIRECTION_T

DIR_CCW

Enum DC_DIRECTION_T

DIR_CW

Enum DC_DIRECTION_T

STEP_MODE1

Enum STEP_MODE_T

STEP_MODE2

Enum STEP_MODE_T