MicroPython MOTOR Library¶
Motor Library
motor
¶
MicroPython Helper for controlling PWM based motors
Author(s): Scott Shawcroft, Jose D. Montoya
-
micropython_motor.motor.FAST_DECAY =
0
¶ Recirculation current fast decay mode (coasting)
- class micropython_motor.motor.MOTOR(positive_pwm, negative_pwm)[source]¶
DC motor driver.
positive_pwm
andnegative_pwm
can be swapped if the motor runs in the opposite direction from what was expected for “forwards”.Motor controller recirculation current decay mode is selectable and defaults to
motor.FAST_DECAY
(coasting).motor.SLOW_DECAY
is recommended to improve spin threshold, speed-to-throttle linearity, and PWM frequency sensitivity.Decay mode settings only effect the operational performance of controller chips such as the DRV8833, DRV8871, and TB6612. Either decay mode setting is compatible with discrete h-bridge controller circuitry such as the L9110H and L293D; operational performance is not altered.
- Parameters:¶
- property decay_mode : int¶
Motor controller recirculation current decay mode. A value of
motor.FAST_DECAY
sets the motor controller to the default fast recirculation current decay mode (coasting);motor.SLOW_DECAY
sets slow decay (braking) mode.
- property throttle¶
Motor speed, ranging from -1.0 (full speed reverse) to 1.0 (full speed forward), or
None
(controller off). IfNone
, both PWMs are turned full off. If0.0
, both PWMs are turned full on.
-
micropython_motor.motor.SLOW_DECAY =
1
¶ Recirculation current slow decay mode (braking)
servo
¶
MicroPython Helper for controlling PWM based servos
Author(s): Scott Shawcroft, Jose D. Montoya
-
class micropython_motor.servo.Servo(pwm_out, *, actuation_range: int =
180
, min_pulse: int =750
, max_pulse: int =2250
)[source]¶ Control the position of a servo.
- Parameters:¶
actuation_range
is an exposed property and can be changed at any time:servo = Servo(pwm) servo.actuation_range = 135
The specified pulse width range of a servo has historically been 1000-2000us, for a 90 degree range of motion. But nearly all modern servos have a 170-180 degree range, and the pulse widths can go well out of the range to achieve this extended motion. The default values here of
750
and2250
typically give 135 degrees of motion. You can setactuation_range
to correspond to the actual range of motion you observe with your givenmin_pulse
andmax_pulse
values.Warning
You can extend the pulse width above and below these limits to get a wider range of movement. But if you go too low or too high, the servo mechanism may hit the end stops, buzz, and draw extra current as it stalls. Test carefully to find the safe minimum and maximum.
- property angle¶
The servo angle in degrees. Must be in the range
0
toactuation_range
. Is None when servo is disabled.
stepper
¶
MicroPython Helper for controlling stepper motors with microstepping support.
Author(s): Tony DiCola, Scott Shawcroft, Jose D. Montoya
-
class micropython_motor.stepper.StepperMotor(ain1, ain2, bin1, bin2, *, microsteps=
16
)[source]¶ A bipolar stepper motor or four coil unipolar motor. The use of microstepping requires pins that can output PWM. For non-microstepping, can set microsteps to None and use digital out pins.
- Parameters:¶
- ain1¶
machine.PWM
ormachine.Pin
-compatible output connected to the driver for the first coil (unipolar) or first input to first coil (bipolar).- ain2¶
machine.PWM
ormachine.Pin
-compatible output connected to the driver for the third coil (unipolar) or second input to first coil (bipolar).- bin1¶
machine.PWM
ormachine.Pin
-compatible output connected to the driver for the second coil (unipolar) or second input to second coil (bipolar).- bin2¶
machine.PWM
ormachine.Pin
-compatible output connected to the driver for the fourth coil (unipolar) or second input to second coil (bipolar).- microsteps : int¶
Number of microsteps between full steps. Must be at least 2 and even.
-
onestep(*, direction: int =
FORWARD
, style: int =SINGLE
) None [source]¶ Performs one step of a particular style. The actual rotation amount will vary by style.
SINGLE
andDOUBLE
will normal cause a full step rotation.INTERLEAVE
will normally do a half step rotation.MICROSTEP
will perform the smallest configured step.When step styles are mixed, subsequent
SINGLE
,DOUBLE
orINTERLEAVE
steps may be less than normal in order to align to the desired style’s pattern.