Overview
By default, thesetup() and loop() functions execute on core0. On Pico/RP2040, you can add setup1() and loop1() functions to run tasks on core1.
Core0
Main firmware logic, mode selection, and communication backends
Core1
Input reading, especially slow input sources like Nunchuk or GameCube controllers
Why Use Dual-Core?
Some input sources have a “slow” scan speed, meaning they take considerable time to read:- NunchukInput - I2C communication is relatively slow
- GamecubeControllerInput - Controller polling takes time
Basic Structure
Core0 (Main)
config.cpp
Core1 (Secondary)
config.cpp
Core Synchronization
Core1 must wait for core0 to finish initialization before accessing shared resources:The
tight_loop_contents() function is a Pico SDK function that executes a minimal wait loop without wasting power.Examples
Reading GPIO Buttons on Core1
The default Pico config reads GPIO buttons on core1 for optimal latency:Reading GameCube Controller on Core1
This example shows how to read GameCube controller inputs on core1:When using both
GamecubeControllerInput and GamecubeBackend, make sure they use different PIO instances (pio0 and pio1) to avoid conflicts.Reading Nunchuk on Core1
The README example shows how to read Wii Nunchuk inputs on core1:Two-Player Arcade Cabinet
As a hypothetical example, you could even power all the controls for a two-player arcade cabinet using a single Pico:This example demonstrates the power of dual-core processing - you can run completely independent controller setups on each core!
Best Practices
Identify Slow Input Sources
Check the
ScanSpeed() of your input sources. Use core1 for InputScanSpeed::SLOW sources.Wait for Initialization
Always use
while (backends == nullptr) in setup1() to ensure core0 has finished initialization.Avoid Resource Conflicts
When using PIO-based inputs (GameCube, N64), ensure different instances use different PIOs or the same memory offset.
Limitations
The Possibilities Are Endless
The dual-core architecture of the RP2040 opens up many creative possibilities:- Mixed input controllers (Nunchuk + buttons)
- Multiple controller support from a single Pico
- Parallel processing of different input methods
- Background tasks like LED animations or display updates
- Complex input processing without affecting main loop timing
For more information on input sources and their scan speeds, see Input Sources.
