High-resolution rotary scroll wheel using an AS5600 magnetic encoder on a Raspberry Pi Pico RP2040. Emulates a multi-touch trackpad via USB HID for smooth, inertial scrolling on any OS.
output.mp4
- Raspberry Pi Pico RP2040 (earlephilhower core)
- AS5600 Magnetic Encoder with diametric magnet
- I2C Connection: GPIO 4 (SDA), GPIO 5 (SCL)
RP2040 Pico AS5600
---------- ------
GPIO 4 --> SDA
GPIO 5 --> SCL
3.3V --> VCC
GND --> GND
- Install PlatformIO
- Open this project in VS Code with PlatformIO extension
- Build and upload to your Pico
- Connect USB — device enumerates as a trackpad
The AS5600 magnetic sensor tracks rotation at 12-bit (4096 position) precision. Instead of sending mouse wheel events, the firmware reports a virtual two-finger swipe on a touchpad HID device. Rotating the encoder moves a simulated finger up/down, which the OS interprets as smooth scrolling.
- Hysteresis noise window — deadband absorbs jitter (no drift when idle)
- Quadratic acceleration — fast spins produce proportionally faster scroll
- Momentum / inertia — velocity decays gradually (configurable friction) for a trackpad-like coasting feel
- Boundary reset — when the virtual finger reaches the trackpad edge, it lifts and re-centers, allowing continuous scrolling
Key constants in include/AS5600ScrollWheel.h:
| Constant | Default | Description |
|---|---|---|
RESOLUTION |
4096 | AS5600 ticks per revolution (12-bit) |
THRESHOLD |
2048 | Wrap-around detection midpoint |
SCALE |
4 | Base sensitivity divisor (lower = faster) |
NOISE_WINDOW |
8 | Hysteresis deadband (raw ticks absorbed) |
ACCEL_THRESHOLD |
4 | Movement threshold before acceleration kicks in |
ACCEL_DIVISOR |
512 | Acceleration curve steepness (lower = sharper) |
MAX_MOVE |
4096 | Per-frame displacement safety clamp |
MOMENTUM_GAIN |
10 | Velocity multiplier from raw movement |
FRICTION_NUM/DEN |
99/100 | Velocity retention per frame (99%) |
VELOCITY_THRESHOLD |
4 | Velocity floor — below this, snap to 0 |
BOUNDARY_LOW |
5000 | Virtual trackpad Y lower bound (reset point) |
BOUNDARY_HIGH |
27000 | Virtual trackpad Y upper bound (reset point) |
TOUCH_CENTER |
16384 | Y-center of virtual finger |
- If AS5600 is not detected, check I2C address (default 0x36)
- Ensure the magnet is properly positioned over the sensor
- Verify wiring connections