pyupm_grovemd module¶
-
class
pyupm_grovemd.
GroveMD
(bus=0, address=15)[source]¶ Bases:
object
API for the Grove I2C Motor Driver.
Deprecated This class is being replaced by MD
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 motorAn example showing the use of a 4-wire stepper
C++ includes: grovemd.hpp
-
DIR_CCW
= 2¶
-
DIR_CW
= 1¶
-
SET_DIRECTION
= 170¶
-
SET_MOTOR_A
= 161¶
-
SET_MOTOR_B
= 165¶
-
SET_PWM_FREQ
= 132¶
-
SET_SPEED
= 130¶
-
STEPPER_DISABLE
= 27¶
-
STEPPER_ENABLE
= 26¶
-
STEPPER_NUM_STEPS
= 28¶
-
STEP_DIR_CCW
= 1¶
-
STEP_DIR_CW
= 0¶
-
STEP_MODE1
= 0¶
-
STEP_MODE2
= 1¶
-
configStepper
(*args)[source]¶ void configStepper(unsigned int stepsPerRev, STEP_MODE_T mode=STEP_MODE1)
Configure the initial Stepper parameters. This should be called before any other stepper method.
stepsPerRev: The number of steps required to complete one full revolution.
mode: The stepper operating mode, default STEP_MODE1
Elapsed milliseconds
-
disableStepper
()[source]¶ bool disableStepper()
To control a stepper motor, stops the stepper motor.
True if successful
-
enableStepper
(dir, speed)[source]¶ bool enableStepper(STEP_DIRECTION_T dir, uint8_t 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.
dir: Direction, STEP_DIR_CW or STEP_DIR_CCW
speed: 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.
True if successful
-
setMotorDirections
(dirA, dirB)[source]¶ bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB)
To control DC motors, sets the directions of motors A & B
dirA: Direction for motor A, DIR_CW or DIR_CCW
dirB: Direction for motor B, DIR_CW or DIR_CCW
True if successful
-
setMotorSpeeds
(speedA, speedB)[source]¶ bool setMotorSpeeds(uint8_t speedA, uint8_t speedB)
To control DC motors, sets the speed of motors A & B. Valid values are 0-255.
speedA: Speed of motor A
speedB: Speed of motor B
True if successful
-
setPWMFrequencyPrescale
(freq=3)[source]¶ bool setPWMFrequencyPrescale(uint8_t freq=0x03)
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.
freq: PWM prescale frequency; default is 0x03
True if successful
-
setStepperSteps
(steps)[source]¶ bool setStepperSteps(unsigned int 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.
steps: Number of steps to execute. 255 (only in Mode2) means continuous rotation.
True if successful
-