High-Precision Quadrature Encoder Position Tracking System
Features β’ Hardware β’ Installation β’ Documentation β’ Testing
PEARL is a professional-grade position encoder system built on the Raspberry Pi Pico, designed for industrial precision applications. It combines PIO-accelerated quadrature decoding, multicore processing, and comprehensive menu-driven configuration to deliver sub-micron accuracy in position tracking.
- 64-bit Position Tracking: Prevents integer overflow for extended operation
- PIO Hardware Acceleration: High-speed quadrature decoding using programmable I/O
- Multicore Processing: Dedicated Core1 for encoder processing, Core0 for UI/display
- Security Hardened: Production-ready with buffer overflow protection and mutex safety
- Real-time Performance: <1ms main loop, <10ΞΌs encoder response
- Comprehensive Testing: Web-based and automated test framework included
- Precision Measurement: Sub-micron accuracy with configurable pitch calibration
- Dual Mode Operation: PIO hardware or GPIO software fallback
- Live Display: 20x4 LCD with big font display mode
- Configuration Persistence: EEPROM-style flash storage for settings
- Engineering Menu: Password-protected access to advanced configuration
- Performance Monitoring: Real-time benchmarking and profiling (commands
B,W) - Web Testing Interface: Browser-based menu system testing at
localhost:8080 - Security Framework: Debug-only authentication bypass, buffer overflow protection
- AI-Powered Development: Integrated Claude Agents for security, testing, and performance analysis
| Component | Specification | Purpose |
|---|---|---|
| Raspberry Pi Pico | RP2040 @ 133MHz | Main controller |
| Quadrature Encoder | Any standard encoder | Position sensing |
| LCD Display | 20x4 I2C (PCF8574) | User interface |
| HW-040 Encoder | Rotary encoder w/ button | Menu navigation |
Quadrature Encoder:
- Channel A: GPIO 10
- Channel B: GPIO 11
- Index: GPIO 12 (optional)
LCD Display (I2C):
- SDA: GPIO 4
- SCL: GPIO 5
- Address: 0x27
HW-040 Menu Encoder:
- CLK: GPIO 16
- DT: GPIO 17
- SW: GPIO 18
See electronics/schematic/PEARL_Schematic.kicad_sch for complete wiring diagram.
- Raspberry Pi Pico SDK v2.1.1 or later
- CMake 3.13+
- Ninja build system
- Python 3.9+ (for testing tools)
# Clone the repository
git clone https://github.com/DirtyDerv/PEARL.git
cd PEARL
# Configure CMake build
mkdir build
cd build
cmake -G Ninja ..
# Build firmware
ninja
# Flash to Pico (BOOTSEL mode)
# Copy build/PEARL.uf2 to your Pico drive- Connect Hardware: Wire encoder, LCD, and menu encoder per pinout
- Flash Firmware: Copy
PEARL.uf2to Pico in BOOTSEL mode - Power On: System boots and displays position immediately
- Calibrate: Triple-click menu encoder to access calibration wizard
| Document | Description |
|---|---|
| User Manual | Complete operating instructions |
| API Reference | Developer API documentation |
| Engineering Menu | Advanced configuration guide |
| Calibration Guide | Step-by-step calibration process |
| Troubleshooting | Common issues and solutions |
| Electronics Guide | Hardware design documentation |
# Run comprehensive menu system tests
python test_menu_system.py
# Output: 8 test cases covering edge cases and integration# Start web server
cd "Web Test"
python -m http.server 8080
# Open browser to http://localhost:8080
# Connect via Web Serial API and run testsConnect via USB serial (115200 baud):
R - Reset position to zero
S - Scan I2C bus
P - Toggle PIO/GPIO mode
V - Show velocity & performance info
D - Toggle display mode
C - Clear performance counters
M - Show menu encoder status
I - Show version info
H - Show help
Performance Commands:
B - Run performance benchmark
W - Start continuous monitoring
Menu Test Commands:
T - Test menu system status
U - Force user menu activation
Q - Force menu exit
- β Buffer Overflow Protection: All display functions bounds-checked
- β Integer Overflow Prevention: 64-bit position tracking
- β Race Condition Safety: Multicore mutex synchronization
- β Debug-Only Bypass: Engineering menu bypass disabled in production builds
- Security Analysis Report - Vulnerability assessment
- Performance Analysis Report - Optimization guide
| Metric | Target | Achieved |
|---|---|---|
| Main Loop | <1ms | β ~100ΞΌs |
| Encoder Response | <10ms | β <1ms |
| Display Update | <50ms | β ~20ms |
| Menu Navigation | <100ms | β <50ms |
- Event-driven menu updates (90% CPU reduction when idle)
- Adaptive encoder sampling (50% Core1 efficiency gain)
- Buffered LCD updates (80% faster screen refresh)
PEARL includes the complete AI Powerhouse framework with specialized Claude Agents:
- π Security Agent: Vulnerability scanning and hardening
- π§ͺ Testing Agent: Automated test generation
- β‘ Performance Agent: Bottleneck analysis and optimization
- π Documentation Agent: API and user documentation
- π Debug Agent: Systematic issue resolution
See AI Integration Guide for details.
PEARL/
βββ src/ # Source code
β βββ Bg_Reader.cpp # Main application
β βββ engineering_menu.cpp # Menu system
β βββ quadrature_encoder.cpp # Encoder driver
β βββ lcd_i2c.cpp # Display driver
β βββ performance_monitor.cpp # Performance tools
βββ include/ # Header files
βββ docs/ # Documentation
βββ tests/ # Test suite
βββ electronics/ # Hardware schematics
βββ Web Test/ # Web testing interface
βββ ai_integration/ # AI Powerhouse framework
βββ build/ # Compiled binaries
// Encoder Configuration
ENCODER_PITCH = 2.0mm // Lead screw pitch
ENCODER_PPR = 600 // Pulses per revolution
QUADRATURE_MODE = 4X // Quadrature multiplication
// Display Settings
LCD_ADDRESS = 0x27 // I2C address
LCD_SIZE = 20x4 // Character display
UPDATE_RATE = 100ms // Refresh interval
// Performance
CORE1_PRIORITY = HIGH // Encoder processing priority
DISPLAY_BUFFER = ENABLED // Buffered updatesAccess via engineering menu (triple-click + long-press):
- Pitch calibration
- Display modes
- Performance tuning
- System diagnostics
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
See CHANGELOG.md for version history.
- π Critical security fixes (buffer overflow, race conditions)
- β‘ Performance monitoring system
- π§ͺ Comprehensive test framework
- π€ AI Powerhouse integration
- π Complete documentation overhaul
This project is licensed under the MIT License - see the LICENSE file for details.
- Raspberry Pi Foundation for the Pico SDK
- Community contributors and testers
- AI Powerhouse framework developers
- Author: DirtyDerv
- Repository: https://github.com/DirtyDerv/PEARL
- Issues: https://github.com/DirtyDerv/PEARL/issues
Built with β€οΈ using Raspberry Pi Pico and AI Powerhouse