How do i enable XInput in Raspberry Pi?
Enabling XInput on the Raspberry Pi allows it to properly recognize modern game controllers (like Xbox and PlayStation controllers) as "XInput devices," which ensures they work correctly with many games and emulators that expect that standard.
Here's a complete guide on how to do it.
What is XInput?
XInput: A Microsoft API for PC gaming that became the standard with the Xbox 360 controller. Games designed for XInput expect buttons and triggers to be laid out in a specific way.
The Alternative (DInput): The older DirectInput API, used by many PlayStation and generic controllers.
Many Linux games and emulators (like RetroPie) can work with both, but some work much better with XInput. Enabling it ensures your controller is seen as an Xbox-compatible gamepad.
Method 1: For Wired Xbox 360 & Xbox One Controllers (The xpad
driver)
This is the most common scenario. The Linux kernel already includes the xpad
driver for these controllers, but it might not be loaded by default or might be blocked by another driver.
Connect your controller via USB.
Check if it's already working. Run
lsusb
in the terminal. You should see a line for "Xbox" or "Microsoft Corp." If it works in games already, you're done!If it's not working, check what driver is being used. Run:
lsmod | grep xpad
If you see no output, the
xpad
module is not loaded. If you see output, it is loaded.Check for conflicting drivers. The
xtrig
driver can sometimes interfere. Check with:lsmod | grep xtrig
If this returns a result, you need to blacklist it.
Enable the
xpad
driver.Open the modules file for editing:
sudo nano /etc/modules
Add a new line with just
xpad
on it. If it's already there, you're good.Press
Ctrl+X
, thenY
, thenEnter
to save and exit.
Blacklist the conflicting driver (if necessary).
If
xtrig
was loaded, create a new blacklist file:sudo nano /etc/modprobe.d/blacklist-xtrig.conf
Add the following line:
blacklist xtrig
Save and exit the file (
Ctrl+X
,Y
,Enter
).
Reboot your Raspberry Pi.
sudo reboot
After the reboot, your wired Xbox controller should be recognized as an XInput device. You can verify by running lsmod | grep xpad
again or checking in a game.
Method 2: For Other Controllers & Advanced Mapping (using xboxdrv
)
xboxdrv
is a more powerful, userspace driver that can make any controller (PlayStation, Nintendo Switch Pro, generic USB) appear as an XInput device. It's highly recommended for RetroPie and other emulation setups.
Install
xboxdrv
:sudo apt update sudo apt install xboxdrv
Test it temporarily. Run the following command and then plug in your controller:
sudo xboxdrv --silent --detach-kernel-driver
--silent
: Suppresses the on-screen log.--detach-kernel-driver
: Detaches the default kernel driver (likehid-generic
) to letxboxdrv
take over.Now test your controller in a game or with
jstest
(install withsudo apt install joystick
). It should now be seen as an Xbox controller.
Make it permanent with a service.
Create a systemd service file:
sudo nano /etc/systemd/system/xboxdrv.service
Paste the following configuration. This is a common setup that works for many controllers:
[Unit] Description=Xbox Drv service After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/xboxdrv --silent --detach-kernel-driver --dbus disabled [Install] WantedBy=multi-user.target
Save and exit the file.
Enable and start the service:
sudo systemctl enable xboxdrv.service sudo systemctl start xboxdrv.service
Reboot to test.
sudo reboot
Your controller should now work as an XInput device every time you boot.
Method 3: For Bluetooth Controllers (e.g., PS4, PS5, Xbox One S)
For Bluetooth controllers, you need to pair them first, and then they will often be picked up correctly by the system.
Install necessary tools:
sudo apt install pi-bluetooth bluez
Pair your controller.
Put your controller into pairing mode.
PS4: Hold the PS Button and Share button until the light bar flashes.
PS5: Hold the PS Button and Create button until the light blinks.
Xbox One S: Press the Pairing button on the top.
Use
bluetoothctl
to scan and pair:bluetoothctl # Inside the bluetoothctl shell: agent on scan on # Wait for your controller to appear (e.g., "Wireless Controller"). trust [MAC-ADDRESS] pair [MAC-ADDRESS] connect [MAC-ADDRESS] quit
The controller should now be connected. By default, recent versions of the kernel and BlueZ will often use the
hid-sony
orhid-generic
driver, which may already emulate XInput. If it doesn't work perfectly, you can use Method 2 (xboxdrv
) to force it to be an XInput device, even over Bluetooth.You would run
xboxdrv
with the--detach-kernel-driver
option and specify the device by its ID if you have multiple controllers. This is best done through the systemd service file created in Method 2.
Verification
To confirm your controller is being seen as an XInput device, you can use the jstest
tool or check the /dev/input
directory.
Install
joystick
package:sudo apt install joystick
Run
jstest
:jstest /dev/input/js0
(If you have multiple controllers, it might be
js1
, etc.). Press buttons and see if the inputs are registered correctly. The button layout should correspond to the Xbox standard (A, B, X, Y, etc.).
By following the method appropriate for your controller, you should now have XInput successfully enabled on your Raspberry Pi.
评论
发表评论