A web-controlled stepper motor interface that integrates with the MotorControl library to provide a user-friendly web interface for controlling stepper motors.
- Web Interface: Modern, responsive web form for motor control
- MotorControl Integration: Uses the universal MotorControl library
- Real-time Control: Direct control of stepper motor direction, speed, and steps
- Status Monitoring: Real-time motor status and position tracking
- Configurable: Easy configuration through JSON files
- RESTful API: Clean API endpoints for integration
The SmartStepper module consists of:
- SmartStepper Class: Main controller that integrates MotorControl with web server
- Web Interface: JSON-based form layout served to the WebTester
- API Endpoints: RESTful endpoints for motor control and status
- Configuration: JSON-based configuration system
- Ensure you have the MotorControl library in the parent directory
- Ensure you have the MicroPyServer library in the MicroPyServer directory
- Install required Python dependencies:
pip install typingfrom SmartStepper.src.SmartStepper import SmartStepper
# Create and start the server
stepper = SmartStepper(host="0.0.0.0", port=8080)
stepper.start()Or run directly:
cd SmartStepper
python src/SmartStepper.py- Start the SmartStepper server
- Open the WebTester application
- Enter the layout URL:
http://localhost:8080/api/layout - Click "Load Layout" to load the motor control form
- Initialize the motor using the API endpoint
- Use the form to control the motor
Returns the JSON layout for the web form.
Response:
{
"title": "SmartStepper Control",
"description": "Control your stepper motor with direction and speed settings",
"submitUrl": "/api/control",
"elements": [...]
}Initialize the stepper motor.
Request Body:
{
"step_pin": 18,
"dir_pin": 19,
"enable_pin": 20
}Response:
{
"status": "success",
"message": "Stepper motor initialized successfully"
}Control the stepper motor.
Request Body:
{
"direction": "forward",
"speed": 60,
"steps": 200
}Response:
{
"status": "success",
"message": "Motor moved 200 steps forward at 60 RPM",
"position": 200
}Get current motor status.
Response:
{
"status": "initialized",
"message": "Motor is ready",
"position": 200,
"speed": 60,
"initialized": true
}The module uses config.json for configuration:
{
"server": {
"host": "0.0.0.0",
"port": 8080
},
"motor": {
"default_pins": {
"step_pin": 18,
"dir_pin": 19,
"enable_pin": 20
},
"default_settings": {
"microsteps": 1,
"default_speed": 60,
"default_steps": 200
}
}
}The web interface provides:
- Direction Control: Forward/Backward selection
- Speed Control: RPM setting with validation
- Step Control: Number of steps to move
- Real-time Feedback: Status and position updates
- Error Handling: Clear error messages
The SmartStepper module is designed to work seamlessly with the WebTester application:
- Dynamic Form Loading: The WebTester loads the form layout from
/api/layout - Form Submission: User inputs are sent to
/api/control - Response Display: Results are displayed in the WebTester interface
- Error Handling: Errors are properly formatted and displayed
- Direction Control: Forward and backward movement
- Speed Control: Adjustable RPM from 0-1000
- Step Control: Precise step-by-step movement
- Position Tracking: Real-time position monitoring
- Safety Features: Input validation and error handling
- New API Endpoints: Add routes in
setup_routes() - Form Elements: Modify the layout JSON in
get_layout() - Motor Functions: Extend the SmartStepper class with new methods
- Start the SmartStepper server
- Use the WebTester to test the interface
- Test API endpoints directly with curl or Postman
- Verify motor responses and error handling
- Motor Not Initialized: Call
/api/initfirst - Import Errors: Check MotorControl and MicroPyServer paths
- Port Conflicts: Change port in config.json
- GPIO Errors: Verify pin assignments and permissions
Enable debug output by modifying the SmartStepper class:
import logging
logging.basicConfig(level=logging.DEBUG)This module is part of the ROSMicroPy-Devices project and follows the same licensing terms.