Connecting Xbox Controller to Raspberry Pi via SSH
This guide provides step-by-step instructions to set up and connect an Xbox controller to a Raspberry Pi over SSH, using only the terminal.
Setting up Dependencies
To enable Bluetooth and install necessary drivers:
Enable and Start Bluetooth Service
sudo systemctl enable bluetooth sudo systemctl start bluetooth
Update the Package List
sudo apt update
Install Xbox Driver
sudo apt install xboxdrv
Connecting the Xbox Controller
To connect the Xbox controller, follow these steps using bluetoothctl
:
Open the Bluetooth Controller
bluetoothctl
Turn Bluetooth Power On
power on
Enable Agent
agent on
Set the Default Agent
default-agent
Start Scanning for Devices
scan on
Look for the MAC address and name of your Xbox controller in the scan results.
Pair the Controller
pair <MAC Address>
Trust the Controller
trust <MAC Address>
Connect the Controller
connect <MAC Address>
Exit Bluetooth Controller
exit
The controller should now be connected to your Raspberry Pi.
Setting up Python Environment
For this project, a specific Python environment is required:
Run Python from the Virtual Environment
sudo ~/Projects/venv/bin/python
(Optional) Create an Alias for Convenience
To simplify running the specific Python version, create an alias by adding the following line to your
~/.bashrc
or~/.bash_aliases
file:alias mypython='sudo ~/Projects/venv/bin/python'
After adding the alias, reload your shell:
source ~/.bashrc
You can now use
mypython
to run the project-specific Python.
—
This completes the setup for connecting an Xbox controller to your Raspberry Pi via SSH and configuring the required Python environment.