Giter VIP home page Giter VIP logo

nsgadget_pi's Introduction

Raspberry Pi Impersonates Nintendo Switch Controller

Adapt various USB gamepads, flight control sticks, and fight sticks for use with the Nintendo Switch (NS) console. All controllers are active but are seen by the console as one controller so co-pilot mode is always active.

                  Buttons
                     |
                     v
USB Controllers -> Raspberry Pi -> NSGadget -> Nintendo Switch
                     ^
                     |
                  Buttons

See README_pinball.md for more details on this test configuration.

Pinball System

See README_fs17.md for a custom Farming Simulator controller using a MIDI keyboard.

USB MIDI keyboard controlling Farming Simulator on Nintendo Switch

See README_gpio.md for a GPIO break out board.

Pi2 with GPIO break out board

See README_voice.md for adding a voice assistant. The Speech-To-Text engine Deep Speech works offline so no Internet connection is needed. This also eliminates privacy concerns with a live microphone. The audio is never sent outside the Raspberry Pi. Deep Speech needs a fast CPU so a Raspberry Pi 4 is best. A Pi 3+ is about half as fast so the delays are noticeable.

USB Controllers

The following USB controllers are supported. The drivers are all included so nothing needs to be installed.

  • Hori HoriPad Nintendo Switch compatible gamepad
  • Microsoft Xbox One gamepad
  • Sony PS4 DS gamepad
  • Logitech Extreme 3D Pro flight control stick
  • Thrustmaster T.16000M flight control stick
  • Dragon Rise arcade fight stick/joystick

jstest-gtk is a very handy utility to understand controller axes and buttons numbering. This is essential to map axes and buttons to the NS controller.

sudo apt install jstest-gtk

USB NSGadget

NSGadget is an Adafruit Trinket M0 emulating an NS compatible gamepad. The UART connection between the Pi and NSGadget runs at 2 Mbits/sec. The UART device name is /dev/ttyAMA0.

Trinket M0 Raspberry Pi
BAT 5V0
Gnd Gnd
TX(4) D14(RXD)
RX(3) D15(TXD)

The firmware/ directory has the firmware.

Compiled programs can be burned into the Trinket M0 just by dragging and dropping a UF2 file on to the Trinket M0 USB drive. There is no need to install the Arduino IDE, source code, or USB serial device driver.

  • Download the UF2 file of your choice.
  • Plug in the Trinket M0 to the computer.
  • Double tap the Trinket M0 reset button.
  • When the TRINKETBOOT USB drive appears, drop the UF2 file on to the drive.
  • Wait a few seconds until the Trinket M0 reboots.

Prepare the Pi

Install Raspbian Buster Lite or Desktop. Update to the latest version.

sudo apt update
sudo apt full-upgrade
sudo reboot

Prepare /dev/ttyAMA0

If the Pi has built-in Bluetooth (Pi 3, Pi 3+, Pi 4, Pi zero W) disable Bluetooth to free up the PL011 UART.

The following is from /boot/overlays/README.

Name:   disable-bt
Info:   Disable onboard Bluetooth on Pi 3B, 3B+, 3A+, 4B and Zero W, restoring
        UART0/ttyAMA0 over GPIOs 14 & 15.
        N.B. To disable the systemd service that initialises the modem so it
        doesn't use the UART, use 'sudo systemctl disable hciuart'.
Load:   dtoverlay=disable-bt
sudo systemctl disable hciuart
sudo nano /boot/config.txt

Add dtoverlay=disable-bt as the last line of config.txt. Save and exit.

Turn off the login shell on /dev/ttyAMA0. This is necessary even if the Pi does not have Bluetooth.

sudo raspi-config
  • Select Interfacing Options.
  • Select P6 Serial.
  • Disable the login shell.
  • Enable the serial interface.
  • Exit raspi-config
sudo reboot

Software

The Python3 program nsac.py holds all the parts together. Once it opens the UART, it spins up a thread for each USB controller and a thread to monitor the buttons connected to GPIO pins.

sudo apt install python3 python3-pip python3-serial python3-gpiozero python3-mido
git clone https://github.com/gdsports/NSGadget_Pi
cd NSGadget_Pi
./nsac.py

nsgpadserial.py provides an interface to the NS Gadget device.

Appliance Mode

If you do not want to login to run nsac.py and are not interested in changing it, try appliance mode. In appliance mode, nsac.py runs on power up. Also the file system is set for read-only mode so powering off without shutting down should not corrupt the microSD card.

Automatically run nsac.py

crontab -e

Add the following line to the end of the file. The small shell script starts nsac.py at power/restart in a loop (just in case it crashes).

@reboot              nohup /home/pi/NSGadget_Pi/nsac.sh >/dev/null 2>&1 &

Enable read-only file system to prevent microSD card corruption

sudo raspi-config
  • Select 7 Advanced Options.
  • Select AB Overlay FS to enable overlay file system (read-only) and write-protect boot partition.
  • Exit and reboot

nsgadget_pi's People

Contributors

gdsports avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nsgadget_pi's Issues

Allow use or provide documentation of how to use without disabling Bluetooth

I need to leave Bluetooth enabled on my Raspberry Pi yet would like to use NSGadget on the same Pi. Looking into it, if your Pi has multiple PL011 UARTs, it seems like it should be possible to utilize one of those instead of the secondary one that the Bluetooth utilizes. If I find a way to get it working while keeping Bluetooth enabled, I will add it here. .

Allow multiple controllers to be used separately

The description mentions that, while multiple controllers can be used simultaneously, the Switch will see them all as a single controller. Would it be possible to emulate a USB hub with each virtual "controller" plugged into a separate port, so that the Switch would see each as a separate Pro Controller? That way, multiple people could use the NSGadget without needing multiple RasPis and Trinkets. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.