Skip to content

Conversation

@pjbRPF
Copy link
Contributor

@pjbRPF pjbRPF commented Oct 16, 2025

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

@pjbRPF pjbRPF requested a review from MarcScott October 16, 2025 13:25
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
pjbRPF and others added 5 commits October 17, 2025 16:42
- 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.
Base automatically changed from dev to main November 5, 2025 15:20
@grega grega self-requested a review as a code owner November 5, 2025 15:20
@pjbRPF pjbRPF changed the base branch from main to dev November 25, 2025 14:28
Copy link
Contributor

@MarcScott MarcScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. For current rotate method:
  • Change name to turn
  • Force positional argument of direction of turn (cw/ccw).
  1. For current revolution method:
  • Change name to rotate
  • Force positional arguments for number of rotations and direction.
  1. Remove methods for revolving and rotating in a specific direction
  2. stepper.angle should return an angle between 0 and 359
  3. Additional method rotate_to with positional arguments of angle and direction
  4. Additional method step_to with positional argument of steps and direction
  5. Additional method set_speed with positional argument of rotations per minute
  6. Additional method run_continuous with positional argument of seconds and defaulting to running until stopped.

@pjbRPF pjbRPF removed the request for review from grega November 25, 2025 15:39
@pjbRPF pjbRPF self-assigned this Nov 25, 2025
@pjbRPF pjbRPF added the enhancement New feature or request label Nov 25, 2025
@pjbRPF pjbRPF linked an issue Nov 25, 2025 that may be closed by this pull request
@pjbRPF pjbRPF removed a link to an issue Nov 25, 2025
pjbRPF and others added 9 commits November 25, 2025 16:08
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
@pjbRPF pjbRPF linked an issue Nov 26, 2025 that may be closed by this pull request
@pjbRPF pjbRPF merged commit c8c3c54 into dev Nov 28, 2025
@pjbRPF pjbRPF deleted the feature/stepper branch November 28, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Stepper class

3 participants