This is a Python class for stepper motors: works with the current version of gpiozero; works with 2-pin, 4-pin, 5-pin motors. The module is completely open-source and published here:
How does it work? Place the stepper.py file containing the Stepper class in your project directory (or, for the async version, the async_stepper.py file with AsyncStepper class). No need to install this library via pip. However, gpiozero shall be already installed in your system.
The library provides a class to control these motors.
For instance, to rotate the motor 1024 steps, call: motor.step(1024) (where motor is your step motor object).
There is a non-blocking version that could be started before a loop or in a loop: motor.start(steps_to_move). Then each time in the loop call: step_motor.tick().
Other methods set the speed, initialize the motor object, stop it. Async version can work in asynchronous programs.
Below is an example of the code to control a stepper motor in a simple manner.
# Non-blocking stepper example
from stepper import Stepper
motor = Stepper(2048, 5, 6, 13, 19)
motor.set_speed(10)
motor.start(1024) # can call in the main loop as well on certain event
while True:
t = motor.tick()
# run other commands while the motor works
# or sleep(max(t, 0.0001))
if motor.steps_left <= 0:
break
This page (Step Motor Library for Raspberry Pi) was last updated on August 14, 2026.
Text editor powered by tinymce.