import stepper
The stepper module drives common stepper motor hardware directly from GPIO. Use ``driver`` for STEP/DIR boards such as A4988, DRV8825, or TMC-style drivers. Use ``four_wire`` for simple four-coil motors through a transistor driver such as ULN2003. The calls are blocking: while a move is running, your script waits until the requested number of steps has been sent. For repeated movement, schedule small moves with ``system.schedule``.
Quick example
import stepper
axis = stepper.driver(
step_pin=18,
dir_pin=19,
enable_pin=21,
steps_per_rev=200,
microsteps=16,
rpm=120,
)
axis.step(3200)
axis.move_to(0)
axis.release()
import stepper
motor = stepper.four_wire(14, 27, 26, 25, steps_per_rev=2048, rpm=12)
motor.step(512)
motor.release()
importstepper
Stepper motor control module.
The stepper module drives common stepper motor hardware directly from GPIO. Use ``driver`` for STEP/DIR boards such as A4988, DRV8825, or TMC-style drivers. Use ``four_wire`` for simple four-coil motors through a transistor driver such as ULN2003. The calls are blocking: while a move is running, your script waits until the requested number of steps has been sent. For repeated movement, schedule small moves with ``system.schedule``.
stepper.driver(step_pin: int, dir_pin: int, enable_pin: int = None, steps_per_rev: int = None, microsteps: int = None, rpm: float = None, pulse_us: int = None, inverted: bool = None) -> stepper_motor
stepper.driver(step_pin: int, dir_pin: int, enable_pin: int = None, steps_per_rev: int = None, microsteps: int = None, rpm: float = None, pulse_us: int = None, inverted: bool = None) -> stepper_motorCreate a STEP/DIR stepper controller.
Use this with driver boards that expose STEP and DIR pins. The optional enable pin is active-low: Studio drives it low while enabled and high when disabled or released.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
step_pin |
int |
positional or keyword | Yes | GPIO output pin connected to the driver's STEP input. |
dir_pin |
int |
positional or keyword | Yes | GPIO output pin connected to the driver's DIR input. |
enable_pin |
int |
positional or keyword | No | Optional active-low enable GPIO. Defaults to -1, meaning no enable pin is controlled. |
steps_per_rev |
int |
positional or keyword | No | Optional full steps per motor revolution. Defaults to 200 for common 1.8 degree motors. |
microsteps |
int |
positional or keyword | No | Optional configured microstep multiplier on the driver. Defaults to 1. Set this to match your MS pins or driver settings. |
rpm |
float |
positional or keyword | No | Optional default movement speed in revolutions per minute. Defaults to 60. |
pulse_us |
int |
positional or keyword | No | Optional STEP pulse high time in microseconds. Defaults to 4. |
inverted |
bool |
positional or keyword | No | Optional bool that flips direction. Defaults to False. |
stepper_motor stepper_motor object.
stepper.driver().step(steps, rpm=None) -> bool
stepper.driver().step(steps, rpm=None) -> boolBlocking relative move. Positive and negative step counts select direction.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
steps |
int |
positional or keyword | Yes | Required value. |
rpm |
float |
positional or keyword | No | Optional value. Defaults to None. |
stepper.driver().move_to(position, rpm=None) -> bool
stepper.driver().move_to(position, rpm=None) -> boolBlocking absolute move to a logical step position.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
position |
int |
positional or keyword | Yes | Required value. |
rpm |
float |
positional or keyword | No | Optional value. Defaults to None. |
stepper.driver().set_position(position) -> bool
stepper.driver().set_position(position) -> boolSet the current logical position without moving the motor.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
position |
int |
positional or keyword | Yes | Required value. |
stepper.driver().position() -> int
stepper.driver().position() -> intReturn the current logical step position.
stepper.driver().set_rpm(rpm) -> bool
stepper.driver().set_rpm(rpm) -> boolChange the default movement speed.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
rpm |
float |
positional or keyword | Yes | Required value. |
stepper.driver().rpm() -> float
stepper.driver().rpm() -> floatReturn the current default movement speed.
stepper.driver().enable() -> bool
stepper.driver().enable() -> boolEnable holding torque. For STEP/DIR drivers, the enable pin is active-low.
stepper.driver().disable() -> bool
stepper.driver().disable() -> boolDisable holding torque and leave the controller object usable.
stepper.driver().release() -> bool
stepper.driver().release() -> boolAlias for disable.
stepper.driver().info() -> dict
stepper.driver().info() -> dictReturn pins, mode, speed, position, and enabled state.
stepper.driver().close() -> bool
stepper.driver().close() -> boolDisable outputs and close the native controller object.
stepper.four_wire(in1: int, in2: int, in3: int, in4: int, steps_per_rev: int = None, rpm: float = None, sequence: str = None, inverted: bool = None) -> stepper_motor
stepper.four_wire(in1: int, in2: int, in3: int, in4: int, steps_per_rev: int = None, rpm: float = None, sequence: str = None, inverted: bool = None) -> stepper_motorCreate a direct four-wire stepper controller.
Use this for small steppers wired through a transistor array or bridge, such as a 28BYJ-48 with ULN2003. The firmware energizes the four outputs in a full-step or half-step sequence.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
in1 |
int |
positional or keyword | Yes | GPIO output pin connected to coil driver input 1. |
in2 |
int |
positional or keyword | Yes | GPIO output pin connected to coil driver input 2. |
in3 |
int |
positional or keyword | Yes | GPIO output pin connected to coil driver input 3. |
in4 |
int |
positional or keyword | Yes | GPIO output pin connected to coil driver input 4. |
steps_per_rev |
int |
positional or keyword | No | Optional logical steps per revolution. Defaults to 2048 for common half-step 28BYJ-48 setups. |
rpm |
float |
positional or keyword | No | Optional default movement speed in revolutions per minute. Defaults to 10. |
sequence |
str |
positional or keyword | No | Optional coil sequence. Use "half_step" or "full_step". Defaults to "half_step". |
inverted |
bool |
positional or keyword | No | Optional bool that flips direction. Defaults to False. |
stepper_motor stepper_motor object.
stepper.four_wire().step(steps, rpm=None) -> bool
stepper.four_wire().step(steps, rpm=None) -> boolBlocking relative move. Positive and negative step counts select direction.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
steps |
int |
positional or keyword | Yes | Required value. |
rpm |
float |
positional or keyword | No | Optional value. Defaults to None. |
stepper.four_wire().move_to(position, rpm=None) -> bool
stepper.four_wire().move_to(position, rpm=None) -> boolBlocking absolute move to a logical step position.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
position |
int |
positional or keyword | Yes | Required value. |
rpm |
float |
positional or keyword | No | Optional value. Defaults to None. |
stepper.four_wire().set_position(position) -> bool
stepper.four_wire().set_position(position) -> boolSet the current logical position without moving the motor.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
position |
int |
positional or keyword | Yes | Required value. |
stepper.four_wire().position() -> int
stepper.four_wire().position() -> intReturn the current logical step position.
stepper.four_wire().set_rpm(rpm) -> bool
stepper.four_wire().set_rpm(rpm) -> boolChange the default movement speed.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
rpm |
float |
positional or keyword | Yes | Required value. |
stepper.four_wire().rpm() -> float
stepper.four_wire().rpm() -> floatReturn the current default movement speed.
stepper.four_wire().enable() -> bool
stepper.four_wire().enable() -> boolRe-energize the current coil phase.
stepper.four_wire().disable() -> bool
stepper.four_wire().disable() -> boolTurn all coil outputs off and leave the controller object usable.
stepper.four_wire().release() -> bool
stepper.four_wire().release() -> boolAlias for disable.
stepper.four_wire().info() -> dict
stepper.four_wire().info() -> dictReturn pins, mode, sequence, speed, position, and enabled state.
stepper.four_wire().close() -> bool
stepper.four_wire().close() -> boolDisable outputs and close the native controller object.