Hacking an Xbox controller

I’ve managed to use an Xbox controller with my Raspberry Pi. This blog post will tell you about what I’ve managed to do with it and how to do it yourself.

What I’ve managed to do so far

I’ve managed to map the D-pad, and the A, B, X & Y buttons to keys on the keyboard so that they can be used by any application, and create a desktop icon that starts the driver

How you can do it yourself (on the Raspberry Pi)

  1. Type the following into a terminal window to update the cache and install the driver program (press enter after each line):
    sudo apt-get update
    sudo apt-get install xboxdrv
  2. Run this command to remove something that conflicts with the driver (You’ll have to run this once per boot):
    sudo rmmod xpad
  3. Run this command to start the driver and map the keys (You’ll have to run this with your desktop open):
    sudo xboxdrv --ui-clear --ui-buttonmap a=XK_Return,b=XK_Escape,x=XK_x,y=XK_y --ui-buttonmap dl=XK_Left,dr=XK_Right,du=XK_Up,dd=XK_Down

It’d be nice if we didn’t have to enter those two commands every time we wanted to use the controller so let’s write a script to do that for us

  1. Open a new file in your text editor and type in the following:
    sudo rmmod xpad
    sudo xboxdrv --ui-clear --ui-buttonmap a=XK_Return,b=XK_Escape,x=XK_x,y=XK_y --ui-buttonmap dl=XK_Left,dr=XK_Right,du=XK_Up,dd=XK_Down
  2. Save your file with a name that you’ll remember and recognize as a file for this purpose (like start-xbox-driver)
  3. Type the following in a terminal window to make it executable (replace pathToScript with the path to your script):
    sudo chmod +x pathToScript
  4. You can run the script by typing the following into a terminal window (again, replace pathToScript with the path to your script):
    bash pathToScript


I hope this is useful to anyone who wants to get started with using an Xbox controller with their Raspberry Pi and I’ll keep you updated when I do more with it.


One thought on “Hacking an Xbox controller

  1. Do you think you could post the basic code to run the bot i’m starting out and I have no idea to even begin starting coding. Is it like Notepad coding: if A then go forward. Or is it something like- If A robot.moveUp(3)?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s