GroveMD Class
- 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.
An example showing the use of a DC motor An example showing the use of a 4-wire stepper
Item Index
Methods
Methods
GroveMD
-
bus
-
address
GroveMD constructor
Parameters:
-
bus
NumberI2C bus to use
-
address
NumberI2C address to use
Returns:
writePacket
-
reg
-
data1
-
data2
Composes and writes a 3-byte packet to the controller
Parameters:
-
reg
REG_TRegister location
-
data1
NumberFirst byte of data
-
data2
NumberSecond byte of data
Returns:
True if successful
setMotorSpeeds
-
speedA
-
speedB
To control DC motors, sets the speed of motors A & B. Valid values are 0-255.
Parameters:
-
speedA
NumberSpeed of motor A
-
speedB
NumberSpeed of motor B
Returns:
True if successful
setPWMFrequencyPrescale
-
freq
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
NumberPWM prescale frequency; default is 0x03
Returns:
True if successful
setMotorDirections
-
dirA
-
dirB
To control DC motors, sets the directions of motors A & B
Parameters:
-
dirA
DC_DIRECTION_TDirection for motor A, DIR_CW or DIR_CCW
-
dirB
DC_DIRECTION_TDirection for motor B, DIR_CW or DIR_CCW
Returns:
True if successful
enableStepper
-
dir
-
speed
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_TDirection, STEP_DIR_CW or STEP_DIR_CCW
-
speed
NumberMotor 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:
True if successful
disableStepper
()
Boolean
To control a stepper motor, stops the stepper motor.
Returns:
True if successful
setStepperSteps
-
steps
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
NumberNumber of steps to execute. 255 (only in Mode2) means continuous rotation.
Returns:
True if successful
configStepper
-
stepsPerRev
-
mode
Configure the initial Stepper parameters. This should be called before any other stepper method.
Parameters:
-
stepsPerRev
NumberThe number of steps required to complete one full revolution.
-
mode
STEP_MODE_TThe stepper operating mode, default STEP_MODE1