Connecting an Xbox Controller Directly to a Raspberry Pi
Table of Contents
An Xbox controller is just a Bluetooth HID device, so a Raspberry Pi with Bluetooth can talk to one directly — no dongle, no wireless receiver, and no extra driver package. That makes the controller a good fit for a robot, a media centre, or anything else where reaching for a keyboard is awkward.
I paired an Xbox One S controller with a Raspberry Pi 3B running 64-bit Raspberry Pi OS. It worked, but only after a few BlueZ tweaks; the default settings dropped the connection often enough to be useless. This is the sequence that ended up being reliable.
What you need #
- A Raspberry Pi with Bluetooth (onboard, or a supported USB Bluetooth adapter) running Raspberry Pi OS.
- A Bluetooth-capable Xbox controller with charged batteries.
- A terminal on the Pi, either locally or over SSH, and
sudoaccess.
Start by checking that the adapter exists and is not blocked:
rfkill list bluetooth
If Bluetooth is soft-blocked, unblock it:
sudo rfkill unblock bluetooth
Then check that BlueZ sees a powered adapter:
bluetoothctl show
Powered: yes is what you want. If it says no, run bluetoothctl power on.
1. Install the tools #
Raspberry Pi OS usually has Bluetooth and BlueZ installed already. The two
packages worth adding are evtest and joystick, which provide evtest and
jstest for checking that the controller actually produces input:
sudo apt update
sudo apt install -y bluetooth bluez evtest joystick
2. Disable ERTM #
ERTM (Enhanced Retransmission Mode) is a Bluetooth reliability feature that Xbox controllers handle badly on Linux. The usual symptom is a controller that pairs, works for a few seconds, then stutters or disconnects. Disable it for the running kernel:
echo 1 | sudo tee /sys/module/bluetooth/parameters/disable_ertm
sudo systemctl restart bluetooth
This setting is not persistent. To apply it at every boot, add a module option and reboot:
echo 'options bluetooth disable_ertm=1' | sudo tee /etc/modprobe.d/bluetooth.conf
sudo reboot
After the reboot, cat /sys/module/bluetooth/parameters/disable_ertm should
show Y. If it still shows N, the option did not take effect — check that
the Bluetooth driver is built as a module on your kernel.
3. Relax the input rules in BlueZ #
BlueZ has a separate configuration file for HID devices. Open
/etc/bluetooth/input.conf:
sudo nano /etc/bluetooth/input.conf
Set these keys under [General]:
[General]
UserspaceHID=true
ClassicBondedOnly=false
LEAutoSecurity=false
What each one does:
UserspaceHID=truehandles HID in BlueZ’s userspace process (via UHID) instead of the kernel’s HIDP module. This is the mode that tends to behave best with the Xbox controller.ClassicBondedOnly=falselets a device connect before a full bond exists. The default istrue, which can reject the controller during its just-works pairing.LEAutoSecurity=falsedisables automatic LE security upgrades. The controller is bonded explicitly withpairbelow, so BlueZ does not need to try to upgrade the connection on its own.
These settings are deliberately permissive. They are fine on a Pi on your own network, but do not treat Bluetooth pairing as a security boundary: a nearby device can attempt a connection with these defaults relaxed.
4. Tune the Bluetooth adapter #
Now edit /etc/bluetooth/main.conf:
sudo nano /etc/bluetooth/main.conf
Merge these keys into the existing [General] section. Do not add a second
[General] header if one is already there:
[General]
Privacy = device
JustWorksRepairing = always
ControllerMode = dual
[LE]
MinConnectionInterval = 7
MaxConnectionInterval = 9
ConnectionLatency = 0
ConnectionSupervisionTimeout = 200
Why these values:
ControllerMode = duallets the adapter run both Bluetooth Classic and LE. If it was set tobredrorleonly, the controller may pair but never connect.Privacy = deviceenables LE private addresses while still accepting a peer’s identity address, which is what lets a bonded controller reconnect.JustWorksRepairing = alwaysallows a device to pair again without deleting the old bond first. It needs BlueZ 5.55 or newer.- The
[LE]values ask for a short connection interval (7–9 units of 1.25 ms) and a 2-second supervision timeout. That trades a little power for a more responsive pad. If your controller connects over Classic instead of LE, these keys are simply ignored.
Restart Bluetooth to apply both files:
sudo systemctl restart bluetooth
5. Put the controller in pairing mode #
Turn the controller on with the Xbox button. Then hold the small pairing button until the Xbox logo flashes quickly. On an Xbox One S the button is on the top edge next to the USB port; on a Series controller it is on the top edge near the USB-C port. Slow blinking means the controller is on but not advertising; fast blinking means it is in pairing mode.
If the controller was previously paired with a console or phone, turn that device off or remove the controller from it first. Otherwise the controller may reconnect to the old host instead of the Pi.
6. Pair, trust, and connect #
Start the BlueZ shell:
bluetoothctl
Inside it, turn the adapter on and scan:
power on
agent on
default-agent
scan on
Wait for a line like this to appear:
[NEW] Device XX:XX:XX:XX:XX:XX Xbox Wireless Controller
That address is the controller’s MAC address; use yours everywhere below. Stop the scan and pair:
scan off
remove XX:XX:XX:XX:XX:XX
pair XX:XX:XX:XX:XX:XX
trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX
quit
A few notes on the order:
removeclears any stale bond from an earlier attempt. If it reportsDevice not available, that is fine — there was nothing to remove.pairperforms the just-works pairing. There is no PIN to enter.trustlets the controller reconnect automatically in future.connectopens the connection now. The Xbox logo should stay solid when it succeeds.
7. Verify that input arrives #
First check that the kernel created a joystick device:
ls /dev/input/js*
Then list the input devices and look for the controller:
cat /proc/bus/input/devices | grep -A 8 -i xbox
The most direct test is evtest:
sudo evtest
Pick the event device whose name contains Xbox Wireless Controller, then move
the sticks and press the buttons. You should see a stream of events. If you
prefer an axis/button view, use jstest:
sudo jstest /dev/input/js0
If /dev/input/js0 does not exist but evtest sees the controller, load the
joystick compatibility module:
sudo modprobe joydev
At this point the controller is connected directly to the Pi and can be read by
any joystick-aware program. In Python, for example, pygame.joystick will see
it as joystick 0. On a headless Pi, set the dummy SDL video driver before
importing pygame:
import os
os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
import pygame
pygame.init()
pygame.joystick.init()
pad = pygame.joystick.Joystick(0)
pad.init()
print(pad.get_name())
Reconnecting later #
Once the controller is trusted, pressing the Xbox button should reconnect it automatically. If it does not, connect it explicitly:
bluetoothctl connect XX:XX:XX:XX:XX:XX
After a reboot, give the Bluetooth service a moment to start, then press the
Xbox button. If the controller still will not connect, check
systemctl status bluetooth and run through the troubleshooting steps below.
Troubleshooting #
| Symptom | Things to check |
|---|---|
Controller never appears in scan on | Is it actually in pairing mode (fast flash)? Are the batteries good? Is it still connected to a console or phone? |
Failed to connect: org.bluez.Error.Failed | Restart Bluetooth, remove the old bond, and pair again. journalctl -u bluetooth -b usually says why. |
| Pairs, then disconnects after a few seconds | ERTM has not been disabled, or the BlueZ config was not reloaded. Re-run the disable_ertm command and restart Bluetooth. |
| Connects but input is laggy | Disable ERTM, move the Pi away from 2.4 GHz congestion, and check the [LE] interval values. Ethernet or 5 GHz Wi-Fi helps. |
No /dev/input/js* | evtest still sees it? Load joydev as above. Otherwise check dmesg for the input device. |
| Works once, then refuses after a config change | Delete the bond with remove, then pair, trust, and connect again. |
The remove-then-repair cycle is the fix for most BlueZ weirdness. If you
change input.conf or main.conf, do that before assuming the controller is
at fault.
Wrapping up #
That is the whole setup: disable ERTM, relax the HID rules, set the adapter to dual mode with a short LE interval, then pair and trust the controller. After that it behaves like any other joystick on the Pi — no receiver, no dongle, and no extra service to keep running.
On the PiCar-X I use this with, the left stick steers, the triggers drive, and the right stick aims the camera. The same pairing steps work for any program that reads a joystick, so the controller is not tied to the robot.