Setting up a Bluetooth gamepad on a Raspberry Pi may not be as straightforward as some were expected. This post documents how I set up a Bluetooth gamepad on a Raspberry Pi, and I hope it could help you if you encountered any difficulties when doing so.
Specifically, the gamepad I'm using is an Xbox controller. If you are using a joystick from other brands, there is a high chance that this post still works for you, but as I only have an Xbox controller, your mileage may vary.
1. Change Bluetooth Settings
The first thing to look at is /etc/bluetooth/main.conf
. In my setup, I changed the following option values. The first five were in the General
section and the last one was in the Policy
section of this .conf file.
Then we can restart the bluetooth service or restart the pi.
2. (Optional) Test
To test if everything works, we can use bluetoothctl
to manually pair and connect to the joystick.
If there's still some issues connecting the joystick, then you may have a try to disable the Bluetooth ERTM feature.
3. (Optional) Auto-connect Script
We can have an auto-connect script that tests whether the input device exists, and try to connect to the gamepad if the specified device is not presented.
A cron task could be set to execute this script every minute. The following code shows how to auto-connect to a joystick at AA:BB:CC:DD:EE:FF
, assuming only connect one gamepad to Raspberry Pi (thus testing /dev/input/js0
).