Git Product home page Git Product logo

raspberrypi-joystick's Introduction

RaspberryPi-Joystick

The goal of this project is to create a virtual USB HID joystick which is able to convert BT mice/keyboard or USB mice/keyboard to joystick HID actions.

This Raspberry Pi joystick converter is based on RaspberryPi 4B/zero and can be used to operate Xbox Adaptive Controller or NS console for practical use cases.

Updates

January 2023: The software is now available as an OS image (BlueStick OS) and you can use RaspberryPi Imager to flash the image to the SD card. Visit BlueStick OS website for more information.

Setup

Here are the hardware and software setup process instructions:

Hardware requirements and setup ( HARDWARE_SETUP.md )

Software requirements and setup ( SOFTWARE_SETUP.md )

Manual setup instructions

The setup process for each gamepad configuration can be performed manually as well. You can chose the configuration that matches your needs and follow the steps.

  1. 8_Buttons ( 8 Buttons and a dual axis joystick )
  2. 16_Buttons ( 16 Buttons and a dual axis joystick )
  3. 32_Buttons ( 32 Buttons and a dual axis joystick )
  4. NSGamepad ( Nintendo Switch )
  5. PSGamepad ( PS3/PS4 )
  6. XACGamepad ( Xbox Adaptive Controller )

Please select the option based on your need and follow the instructions.

Collaborators

Thanks to all the developers and testers helping to create this project. Special thanks to gdsports for finding/fixing bugs and developing new features.

License

MIT License

Copyright (c) 2018 Milador

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

raspberrypi-joystick's People

Contributors

gdsports avatar milador 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  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

raspberrypi-joystick's Issues

Configuration

Hello!

I've stumbled upon this awesome project and I'd like some help with using it.

How do I configure the association between keyboard keys and gamepad buttons?

Thanks!

No reaction of the windows 10 host when using input_keyboard.py

Hi Milador,

Thank you for sharing this solution. I'm going to use it to simulate joystick buttons for a lap counter software (UR30) in a slot car projet.

The virtual joystick appears in WIndows 10 control panel but there is no reactions of the button when i use the small tests program input_keyboard.py. Whatever i type through my SSH session on the raspbeery PiZero, i've never seen the button light on in the windows 10 joystick control panel....

The /dev/hidg0 is here and no errors in dmesg and from input_keyboard.py
I'm using an Raspbian Buster.

Any ideas ?

Thank you for your help.
Jean-Christophe

Create IMG for easy distribution

The goal is to reduce the steps for the end user by creating an IMG file with all the changes specified in various README files. Perhaps one IMG for XAC BT and one for NSGamepad BT.

  • Create the ideal system with changes to usb_f_hid.ko, /etc/modules , /boot/config.txt, /etc/rc.local, etc.
  • Expire the pi password so it must be changed.
  • Remove SSH keys so they are regenerated?
  • Remove your SSID/PSK from /etc/wpa_supplicant.conf!
  • Shutdown and poweroff.
  • Mount the SD card on a Linux system as a data drive.
  • Shrink the ext4 partition using GParted.
  • Save the card image to an IMG file and zip it.

The end user instructions reduce to the following.

  • Download Raspberry Pi USB gadget BT zip file.
  • Unzip to extract IMG file created above.
  • Burn IMG to micro SD card.
  • An optional step is to customize WiFi SSID/PSK. Create wpa_supplicant.conf on the FAT32 partition with the desired SSID and PSK.
  • Plug SD Card into PiZW, Pi3A+, Pi4B, or Pi400.
  • Continue with instructions on BT pairing, etc.

It may be possible to run a shell script to create the ideal system instead of doing the steps by hand specified in the README files.

One interesting raspi-config option is the Overlay File System. This effectively makes the rootfs read-only so power off without shutdown will not corrupt the rootfs. Configuration files can be stored in the boot partition which is FAT32 so configuration options can be changed on Windows or Mac.

The following is an attempt at single script to create an ideal system but is currently incomplete.

#!/usr/bin/env bash
sudo apt update
sudo apt install -y python3-pip python3-gpiozero python3-evdev git

cd
git clone https://github.com/milador/RaspberryPi-Joystick
cd RaspberryPi-Joystick/NSGamepad

# Update system files to load the USB gadget drivers, if needed.
grep --quiet "^dtoverlay=dwc2$" /boot/config.txt
if [ $? -eq 1 ]
then
    echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
fi
grep --quiet "^dwc2$" /etc/modules
if [ $? -eq 1 ]
then
    echo "dwc2" | sudo tee -a /etc/modules
fi
grep --quiet "^libcomposite$" /etc/modules
if [ $? -eq 1 ]
then
    echo "libcomposite" | sudo tee -a /etc/modules
fi

# Install USB NS gadget on boot
chmod +x ns_gamepad_usb
sudo cp ns_gamepad_usb /usr/bin/
# Insert line in /etc/rc.local, if needed
grep --quiet "^/usr/bin/ns_gamepad_usb$" /etc/rc.local
if [ $? -eq 1 ]
then
    sudo sed -i '/^exit 0/i \
/usr/bin/ns_gamepad_usb' /etc/rc.local
fi

# TBD Update usb_f_hid.ko files. This required for XAC but not NS.

# TBD Install service?

# TBD Expire pi account password?

# TBD Remove SSH keys?

# Remove my SSID/PSK
sudo rm /etc/wpa_supplicant/wpa_supplicant.conf

#sudo raspi-config overlay-file-system turn on???
echo "Powering off so an IMG can be created from this microSD card."
sleep 1
sudo poweroff

Emulate a Nintendo Switch controller

NSGamepad configures the gadget device into a USB gamepad. With the help of a Mayflash Magic NS adapter (about $20), the Pi Zero gamepad can control a Nintendo Switch. See PR #5

Android compatibility

Hi, I'm trying to test it on android phone but the phone doesn't recognize it as a controller, it recognize it as a power charger. Running the demo python script i receive error 108. Is there a way to fix it?

How to creat virtual a Bluetooth HID Joystick?

Hi, milador!

I admire your work! Thanks!
I followed your tutorial and I successfully created a USB HID joystick on the raspberry pi 4B and made my windows pc successfully receive data from the USB port.

My questions are as follows:
I am working on a RaspberryPi 4B. Since the controller needs to be moved, it cannot be connected using a USB cable. I want the RaspberryPi to emulate a Bluetooth gamepad like a ps4 Bluetooth wireless controller.

I'm trying to change the class of my Pi4B hci0 device to make the pc think the device is a Bluetooth Joystick. But I didn't succeed. The link is broken as soon as it is established.

Do you know how to make RaspberryPi 4B virtual a Bluetooth Joystick?
Looking forward to your reply.

thanks again!

GuoFei

Rpi not being recognized as joystick

Hello,
After following the installation my rpi zero W is being recognized as serial COM device (RNDIS/Ethernet gadget).
Tried to install it several times and checked on two windows10 PCs.

Which version of raspbian did you use?
I'm not sure where the problem is

ls: cannot access '/dev/hidg*': No such file or directory

I have followed the tuts for NSGamePad, 32 button and 16 button (filling in TBD manually) but I can't seem to get the device to do anything other than show "Device Descriptor Request Failed" on my windows 10 computer. Am I missing something?

XAC left/right USB port at the same time

Hi there, great work!
I wonder if it's possibile to wireup to the Raspberry the two usb port on the XAC to be able to use all the "controller buttons".
Thankyou

Add possibility to use bluetooth controllers

I'm using the program & Pi Zero to connect wheelchairs with Bluetooth Mouse support to the XAC

Works like a charm after fiddling with the settings.

However, there are some very nice bluetooth "VR Controllers" that i would love to connect to the XAC without gutting it open.
Would it be possible to add support for gamepad joysticks to "passthrough" the joystick command to the XAC?

Starting out with python, so i'm not able to code this myself.

Add bluetooth connection applet

Create a bluetooth connection applet which allows user to scan , pair, connect to bluetooth mice and bluetooth keyboards. This will offer options to enter pins and authentication which is not offered by bluetooth tool from top taskbar.

Device unrecognized

Followed all the steps and after rebooting and plugging into a windows PC, it comes up as a unknown USB device. It states the "Device Descriptor Request Failed".

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.