Emulate Nintendo Switch USB Controller with Raspberry Pi
Credit: This project heavily relies on https://github.com/mzyy94/nscon.
- Raspberry Pi. Tested with Zero W and Pi 4. Not sure if Pi 5 works. (Saw an page saying 5 doesn't support the usb "gadget" mode?)
Tested on Ubuntu 24 (on Pi 4) and the latest Raspberry Pi OS (on Zero W 2) on 2024-12-31.
-
Install libcomposites for the USB gadget mode. (From https://github.com/milador/RaspberryPi-Joystick)
# Needed this on Raspberry Pi OS (?). Not needed on Ubuntu. echo "dtoverlay=dwc2" | sudo tee -a /boot/firmware/config.txt echo "dwc2" | sudo tee -a /etc/modules echo "libcomposite" | sudo tee -a /etc/modules reboot
-
Install binary on the Raspberry Pi.
# Install commands apt install -y golang xxd git go install -v github.com/omakoto/raspberry-switch-control/nscontroller/cmd/...@latest
-
Download source for the following script.This step is no longer needed. Now you can use the following sudo command to run the script.
-
Create the USB gadget by running the
switch-controller-gadget
script.The path to this script is not stable. Run
nsbackend usb-init-script-path
to get the path.sudo bash "$($HOME/go/bin/nsbackend usb-init-script-path)"
Or, add the following entry to root's
crontabe
(i.e.sudo crontab -e
and add it) Change/home/pi/
as needed.@reboot bash -c ". $(/home/pi/go/bin/nsbackend usb-init-script-path)"
-
Connect the Raspberry Pi to the Nintendo Switch
-
If it's a Pi 4 or 5, use the USB-C port.
My configuration: connect the Switch to a powered USB hub, then connect it to the Pi's C port. Make sure the Pi can draw enough power.
-
If it's a Zero, use the micro USB port.
-
Connect the Raspberry Pi to the Switch.
-
If using a Pi Zero, connect via the micro-USB port.
-
If using a Pi 4, connect to the USB C port. (aka the power port)
-
Either way, to make sure the Pi keeps running even when not connected to the switch, use a powered USB hub.
(So, ideally, use a hub with a usb C output and connect it to the Pi, rather than using an A port.)
-
-
Connect a joystick to a host PC. (only the following ones are supported and tested)
- Nintendo Pro controller
- X-Box One controller
- PS4 controller
-
On the host PC, install the software:
apt install -y golang go install -v github.com/omakoto/raspberry-switch-control/nscontroller/cmd/...@latest
-
On the host PC, run it:
nsfrontend -j /dev/input/js0 -o >(ssh pi@$PI_ADDRESS go/bin/nsbackend)
-
Press
[enter]
on the console to finish.
-
Auto start
nsbackend
as a daemon. Add this toroot
's crontab.$ sudo crontab -l # ... @reboot bash -c ". $(/home/pi/go/bin/nsbackend usb-init-script-path); /home/pi/go/bin/nsbackend -x"
-
Then write to
/tmp/nsbackend.fifo
fromnsfrontend
instead:nsfrontend -j /dev/input/js0 -o >(ssh pi@$PI_ADDRESS 'echo "SSH Connected."; cat > /tmp/nsbackend.fifo')
- Autofire on/off
- Macro
- Control switch from a smart phone
- https://www.kernel.org/doc/html/v4.13/driver-api/usb/gadget.html
- https://github.com/milador/RaspberryPi-Joystick
- https://www.rmedgar.com/blog/using-rpi-zero-as-keyboard-setup-and-device-definition
- https://github.com/wchill/SwitchInputEmulator
- https://sourceforge.net/projects/linuxconsole/
- https://github.com/progmem/Switch-Fightstick
- https://sourceforge.net/p/linuxconsole/code/ci/master/tree/utils/jstest.c
- http://www.fourwalledcubicle.com/files/LUFA/Doc/120219/html/group___group___std_descriptors.html