-
Notifications
You must be signed in to change notification settings - Fork 34
Add Stepper motor class #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Core Implementation: • Complete Stepper class supporting 4-pin stepper motors (28BYJ-48 + ULN2003) • Three step sequences: wave, full, half-step for different torque/smoothness needs • Position tracking with step counting and angle calculation • Configurable steps-per-revolution and step delays for different motors API Design Philosophy - Four Complementary Approaches: 1. DEFAULT DIRECTION (Simplest) • step(10) - Uses default clockwise direction • Minimizes cognitive load for basic use cases 2. CONVENIENCE METHODS (Explicit Intent) • step_clockwise(10), step_counterclockwise(10) • rotate_clockwise(90), rotate_counterclockwise(90) • revolve_clockwise(2), revolve_counterclockwise(2) • Short aliases: step_cw(), rotate_ccw(), revolve_cw() • Clear, readable, self-documenting code 3. PARAMETERIZED METHODS (Flexible Control) • step(10, direction='cw'|'ccw'|1|-1) • rotate(90, direction='clockwise'|'counter-clockwise') • revolution(2, direction=1|-1) • Supports both string and numeric direction parameters • Flexible _normalize_direction() handles multiple formats 4. ALIAS SUPPORT (Compatibility) • revolve() as alias for revolution() • StepperMotor as backward-compatible class alias • Maintains consistency with existing picozero patterns Technical Features: • Polymorphic direction parameters (string/numeric) with validation • Real-time speed control via step_delay property • Position reset capability for homing/calibration • Proper resource management with off() and close() methods • Comprehensive error handling with descriptive messages Testing Strategy: • Validates all API approaches for consistency • Covers edge cases and error conditions Documentation: • Added Stepper class to API documentation • Exported in __init__.py for public access • Comprehensive docstrings with parameter details • Usage examples showing all API patterns
19956d7 to
3204985
Compare
- Add MotionSensor section to recipes.rst (missing from previous merge) - Add Stepper section to recipes.rst with comprehensive examples - Update changelog.rst with v0.5.0 entries for both classes - Organize motor sections together for better flow
Core Implementation: • Complete Stepper class supporting 4-pin stepper motors (28BYJ-48 + ULN2003) • Three step sequences: wave, full, half-step for different torque/smoothness needs • Position tracking with step counting and angle calculation • Configurable steps-per-revolution and step delays for different motors API Design Philosophy - Four Complementary Approaches: 1. DEFAULT DIRECTION (Simplest) • step(10) - Uses default clockwise direction • Minimizes cognitive load for basic use cases 2. CONVENIENCE METHODS (Explicit Intent) • step_clockwise(10), step_counterclockwise(10) • rotate_clockwise(90), rotate_counterclockwise(90) • revolve_clockwise(2), revolve_counterclockwise(2) • Short aliases: step_cw(), rotate_ccw(), revolve_cw() • Clear, readable, self-documenting code 3. PARAMETERIZED METHODS (Flexible Control) • step(10, direction='cw'|'ccw'|1|-1) • rotate(90, direction='clockwise'|'counter-clockwise') • revolution(2, direction=1|-1) • Supports both string and numeric direction parameters • Flexible _normalize_direction() handles multiple formats 4. ALIAS SUPPORT (Compatibility) • revolve() as alias for revolution() • StepperMotor as backward-compatible class alias • Maintains consistency with existing picozero patterns Technical Features: • Polymorphic direction parameters (string/numeric) with validation • Real-time speed control via step_delay property • Position reset capability for homing/calibration • Proper resource management with off() and close() methods • Comprehensive error handling with descriptive messages Testing Strategy: • Validates all API approaches for consistency • Covers edge cases and error conditions Documentation: • Added Stepper class to API documentation • Exported in __init__.py for public access • Comprehensive docstrings with parameter details • Usage examples showing all API patterns
- Add MotionSensor section to recipes.rst (missing from previous merge) - Add Stepper section to recipes.rst with comprehensive examples - Update changelog.rst with v0.5.0 entries for both classes - Organize motor sections together for better flow
After rebase onto dev branch that includes MotionSensor docs from PR #131, remove the duplicate MotionSensor section that was incorrectly positioned after temperature sensor. MotionSensor documentation now correctly appears only once after Buttons section, maintaining proper input device grouping.
MarcScott
requested changes
Nov 25, 2025
Contributor
MarcScott
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- For current
rotatemethod:
- Change name to
turn - Force positional argument of direction of turn (
cw/ccw).
- For current
revolutionmethod:
- Change name to rotate
- Force positional arguments for number of rotations and direction.
- Remove methods for revolving and rotating in a specific direction
stepper.angleshould return an angle between 0 and 359- Additional method
rotate_towith positional arguments of angle and direction - Additional method
step_towith positional argument of steps and direction - Additional method
set_speedwith positional argument of rotations per minute - Additional method
run_continuouswith positional argument ofsecondsand defaulting to running until stopped.
Closed
Closed
Use debounced last_state instead of re-reading pin after bounce_time wait. The bounce_time loop stabilizes the value in last_state, but the code was re-reading the pin which could return a transient/unstable value, causing valid state changes to be missed. This fixes sound sensors and other fast-pulsing inputs with bounce_time enabled. Fixes issue: Sound Sensor with bounce_time=1 not detecting signals
…ation/picozero into feature/stepper
Closed
MarcScott
approved these changes
Nov 28, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Core Implementation:
• Complete Stepper class supporting 4-pin stepper motors (28BYJ-48 + ULN2003)
• Three step sequences: wave, full, half-step for different torque/smoothness needs
• Position tracking with step counting and angle calculation
• Configurable steps-per-revolution and step delays for different motors
API Design Philosophy - Four Complementary Approaches:
DEFAULT DIRECTION (Simplest)
• step(10) - Uses default clockwise direction
• Minimizes cognitive load for basic use cases
CONVENIENCE METHODS (Explicit Intent)
• step_clockwise(10), step_counterclockwise(10)
• rotate_clockwise(90), rotate_counterclockwise(90)
• revolve_clockwise(2), revolve_counterclockwise(2)
• Short aliases: step_cw(), rotate_ccw(), revolve_cw()
• Clear, readable, self-documenting code
PARAMETERIZED METHODS (Flexible Control)
• step(10, direction='cw'|'ccw'|1|-1)
• rotate(90, direction='clockwise'|'counter-clockwise')
• revolution(2, direction=1|-1)
• Supports both string and numeric direction parameters
• Flexible _normalize_direction() handles multiple formats
ALIAS SUPPORT (Compatibility)
• revolve() as alias for revolution()
• StepperMotor as backward-compatible class alias
• Maintains consistency with existing picozero patterns
Technical Features:
• Polymorphic direction parameters (string/numeric) with validation
• Real-time speed control via step_delay property
• Position reset capability for homing/calibration
• Proper resource management with off() and close() methods
• Comprehensive error handling with descriptive messages
Testing Strategy:
• Validates all API approaches for consistency
• Covers edge cases and error conditions
Documentation:
• Added Stepper class to API documentation
• Exported in init.py for public access
• Comprehensive docstrings with parameter details
• Usage examples showing all API patterns