Supported AVR Microcontrollers
ATMega32U4
USB-capable AVR (Leonardo, Pro Micro, Teensy 2.0)
- 16 MHz
- 2.5 KB RAM
- 32 KB Flash
- Native USB
- Most common for controllers
ATMega328P
Classic Arduino (Uno, Nano)
- 16 MHz
- 2 KB RAM
- 32 KB Flash
- No native USB (requires USB-serial adapter)
- Good for console-only builds
ATMega2560
Arduino Mega
- 16 MHz
- 8 KB RAM
- 256 KB Flash
- More GPIO pins
- Used in Smash Box
ATMega16U2
USB-to-Serial Chip
- Often found on Arduino Uno/Mega
- Can be reprogrammed for USB HID
- Advanced use case
Why Choose AVR?
Despite being older and slower than RP2040, AVR has advantages: ✅ Mature and proven - Decades of development and testing✅ Widely available - Easy to source, even during chip shortages
✅ Extensive ecosystem - Huge Arduino community and libraries
✅ Lower cost - Pro Micro clones as cheap as $3-4
✅ Compatibility - Works with existing B0XX, LBX, GCCPCB designs
✅ Sufficient for most users - 1-2ms latency is excellent for competitive play
Controllers Using AVR
Many popular controllers use ATMega32U4:- B0XX R1 - Original B0XX (Leonardo)
- B0XX R2 - Second-gen B0XX (Leonardo)
- LBX - Low Budget Box (Leonardo or Pro Micro)
- GCCPCB1 & GCCPCB2 - Crane’s GameCube PCB (Leonardo)
- GCCMX - MX-switch GameCube PCB (Leonardo)
- Smash Box - Hit Box Arcade Smash Box (Mega)
AVR Platform Variants
HayBox defines two AVR platform configurations:AVR USB (avr_usb)
For microcontrollers with native USB (ATMega32U4, ATMega16U2)
- ✅ USB gamepad (DInput, XInput via software)
- ✅ USB keyboard
- ✅ GameCube/N64 console
- ✅ Mode switching
- ✅ B0XX input viewer
AVR No-USB (avr_nousb)
For microcontrollers without native USB (ATMega328P, ATMega2560)
- ✅ GameCube/N64 console (via Joybus)
- ✅ NES console
- ❌ USB (unless using custom USB-serial firmware)
- ❌ Mode switching (single mode compiled in)
The Mega has USB hardware but requires special configuration to use it for HID. By default, it uses
avr_nousb and the USB port is only for programming.Building for AVR
PlatformIO Configuration
Fromplatformio.ini:
Compiling an AVR Config
- PlatformIO IDE
- Command Line
- Open HayBox project in VS Code with PlatformIO
- Select your environment from the bottom toolbar:
b0xx_r1,b0xx_r2(Leonardo)gccpcb1,gccpcb2(Leonardo)lbx(Leonardo/Pro Micro)arduino_leonardo,arduino_micro, etc.
- Click Build (checkmark icon)
- Output
.hexfile will be in.pio/build/[env_name]/
Memory Usage
AVR has strict memory limits. After building, check the output:Flashing AVR Firmware
Using QMK Toolbox (Recommended)
- Download QMK Toolbox
- Open QMK Toolbox
- Load your
.hexfile - Select ATmega32U4 (or your chip) from dropdown
- Put board into bootloader mode:
- Leonardo/Pro Micro: Press reset button twice quickly
- Teensy: Press the button on the board
- Click Flash when device is detected
Using avrdude (Command Line)
Bootloader Entry
HayBox includes safe bootloader entry:- Hold RT2 (or configured button)
- Plug in controller
- Controller enters bootloader automatically
- Flash with QMK Toolbox or avrdude
On AVR, this feature requires starting the Serial interface, which adds a small amount of latency. Some competitive players disable this feature for minimal latency gains.
AVR Limitations
Be aware of these constraints when using AVR:Memory Constraints
| Resource | ATMega32U4 | Impact |
|---|---|---|
| RAM | 2.5 KB | Limits game modes, configs, features |
| Flash | 32 KB | Tight fit with all features enabled |
| EEPROM | 1 KB | Limited config storage |
build_src_filter):
- Integrated display support (
-<src/comms/IntegratedDisplay.cpp>) - Mode selection (on
avr_nousbonly)
Performance Limitations
- Single core - All processing on one 16 MHz core
- Bit-banging Joybus - GameCube/N64 uses CPU, not hardware PIO
- Lower polling precision - USB timing less consistent than RP2040
- Higher latency - 1-2ms typical (vs 0.5-1ms on RP2040)
Pin Limitations
| Board | Usable GPIO | Notes |
|---|---|---|
| Pro Micro | ~18 pins | Compact but fewer pins |
| Leonardo | ~20 pins | Standard choice |
| Mega | ~54 pins | Many pins but no native USB |
AVR Pin Mapping Example
From B0XX R1 configuration:Input Sources on AVR
AVR configs typically use simpler input handling:Nunchuk Support
AVR boards can use Wii Nunchuk for analog input:The Nunchuk uses I2C on pins A4 (SDA) and A5 (SCL). These pins cannot be used for buttons when Nunchuk is enabled.
Optimizing for AVR
To maximize performance and minimize memory usage:Reduce Game Modes
Editconfig_defaults.hpp to include only needed modes:
Disable Unused Features
Compiler Optimizations
Already included inplatformio.ini:
-Os- Optimize for size-flto- Link-time optimization (removes unused code)-Wl,--gc-sections- Garbage collection of unused functions-fshort-enums- Use smallest integer type for enums
Troubleshooting
”Not enough memory” error
- Remove unused game modes
- Disable mode selection (compile single mode)
- Use
avr_nousbif you don’t need USB - Simplify SOCD configurations
Bootloader won’t activate
- Press reset button twice quickly (Leonardo/Pro Micro)
- Check if bootloader entry code is enabled
- Verify button held is correct (usually RT2)
- Try manual reset button on board
Joybus unreliable on console
- Verify joybus_data pin is correct
- Use shorter wires (under 6 inches)
- Add 100Ω series resistor on data line
- Check GameCube cable pinout
- Test with different polling rate settings
USB not detected
- Verify you’re using
avr_usbconfig (notavr_nousb) - Check USB cable supports data (not charge-only)
- Try different USB port
- Reflash bootloader if corrupted
Comparison: AVR vs RP2040
| Feature | AVR (ATMega32U4) | RP2040 |
|---|---|---|
| Clock speed | 16 MHz | 133-200 MHz |
| Cores | 1 | 2 |
| RAM | 2.5 KB | 264 KB |
| Flash | 32 KB | 2 MB |
| GPIO | ~20 pins | 26+ pins |
| Input latency | 1-2 ms | 0.5-1 ms |
| Price | $3-8 | $4-6 |
| Availability | Excellent | Good |
| Joybus | Bit-bang | PIO (hardware) |
| Display support | No | Yes |
| RGB LED | Limited | Full FastLED |
| Config storage | 1KB EEPROM | Flash filesystem |
When to Use AVR
✅ Use AVR if:- You’re building for an existing AVR-based design (B0XX R1/R2, LBX, GCCPCB)
- You want maximum compatibility with existing hardware
- You’re on a tight budget
- You don’t need advanced features (display, RGB, many modes)
- Your button count is ≤20
- You want the lowest possible latency
- You need many game modes or configurations
- You want OLED display or RGB LED support
- You’re designing new hardware from scratch
- You need >20 buttons
