Complete installation guide for setting up your Raspberry Pi Zero as a USB audio device.
- Raspberry Pi Zero W (recommended) or Raspberry Pi Zero 2 W
- MicroSD card (8GB or larger, Class 10 recommended)
- USB data cable (NOT power-only) - usually the cable that comes with phones
- Audio output hardware - one of:
- Audio HAT (HiFiBerry, Merus, etc.)
- USB audio interface
- 3.5mm audio jack (basic quality)
- I2S DAC
- Raspberry Pi OS (latest version recommended)
- SSH access or direct terminal access to Pi
- Internet connection during installation
- Flash Raspberry Pi OS to SD card using Raspberry Pi Imager
- Enable SSH (if using headless setup):
# Create empty ssh file in boot partition touch /boot/ssh - Configure WiFi (if needed):
# Create wpa_supplicant.conf in boot partition cat > /boot/wpa_supplicant.conf << EOF country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="YourNetworkName" psk="YourPassword" } EOF
- Boot the Pi and connect via SSH or direct terminal
- Update the system:
sudo apt update && sudo apt upgrade -y - Install git (if not already installed):
sudo apt install git -y
-
Clone the repository:
git clone https://github.com/yourusername/raspberry-pi-zero-as-usb-audio-device.git cd raspberry-pi-zero-as-usb-audio-device -
Run the installation script:
chmod +x install.sh ./install.sh
-
Reboot the Pi:
sudo reboot
- Wait for Pi to boot completely (about 30-60 seconds)
- Connect USB cable:
- Use the center micro USB port on Pi Zero (DATA port)
- Connect to your host computer
- Do NOT use the power port (outer micro USB)
-
On the Pi, check services:
./validate-setup.sh
Or manually:
systemctl status usb-gadget-audio.service systemctl status usb-audio-routing.service
-
On the host, check device detection:
# Linux lsusb | grep -i audio aplay -l | grep -i "pi zero" # macOS system_profiler SPUSBDataType | grep -A 10 -i audio # Windows # Check Device Manager → Sound, video and game controllers # or Control Panel → Sound
# Check service status
systemctl status usb-gadget-audio.service
systemctl status usb-audio-routing.service
# Check logs
journalctl -u usb-gadget-audio.service -n 20
journalctl -u usb-audio-routing.service -n 20
# Restart services
sudo systemctl restart usb-gadget-audio.service
sudo systemctl restart usb-audio-routing.service- Verify USB cable - must be data cable, not power-only
- Check correct port - center micro USB on Pi Zero (not power port)
- Wait after boot - services take 30-60 seconds to fully initialize
- Try different host port - some USB ports have power limitations
- Check audio hardware:
aplay -l # Should show your audio device - Test audio output directly:
speaker-test -D plughw:CARD=sndrpimerusamp,DEV=0 -c 2
- Check audio routing:
pgrep alsaloop # Should show a process ID
If the Pi won't boot after installation:
- Remove SD card and mount on another computer
- Edit /boot/config.txt and remove the line:
dtoverlay=dwc2 - Boot Pi normally and retry installation
If automatic installation fails, you can clean up and retry:
# Clean up previous installation
./cleanup.sh
# Retry installation
./install.sh
sudo reboot- Both work identically
- Pi Zero 2W has better performance but same USB OTG capability
The installation script is optimized for Merus audio HATs. For other hardware:
-
Check your audio device:
aplay -l
-
Update routing command in
/etc/systemd/system/usb-audio-routing.service:# Replace the ExecStart line with your audio device ExecStart=/usr/bin/alsaloop -C plughw:2,0 -P plughw:YOUR_CARD,0 -t 50000 -r 48000 -
Restart service:
sudo systemctl daemon-reload sudo systemctl restart usb-audio-routing.service
Edit /usr/local/bin/usb-gadget-audio.sh and modify:
MANUFACTURER="Your Company Name"
PRODUCT="Your Audio Device Name"Modify the UAC2 configuration in the gadget script:
# Higher sample rates (if supported by hardware)
echo 96000 > c_srate
echo 96000 > p_srate
# Higher bit depth
echo 3 > c_ssize # 24-bit
echo 3 > p_ssize # 24-bitAdjust audio latency vs stability in the routing service:
# Lower latency (may cause dropouts)
-t 25000
# Higher stability (more latency)
-t 100000After successful installation:
- Test basic functionality - play audio from host
- Configure host audio settings - set Pi as default device if desired
- Check audio quality - verify no dropouts or distortion
- Read Configuration Guide for advanced options
- See Troubleshooting Guide for common issues