element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Raspberry Pi – Xbox Controller – Scratch Game
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 15 Dec 2012 4:43 PM Date Created
  • Views 1587 views
  • Likes 2 likes
  • Comments 0 comments
Related
Recommended
  • xbox360
  • rpibeginner
  • raspberrypi

Raspberry Pi – Xbox Controller – Scratch Game

oneleggedredcow
oneleggedredcow
15 Dec 2012
imageWant to build this project?
View Parts

 

This video is unavailable.
You don't have permission to edit metadata of this video.

 

Goal

To play a game on the raspberry pi using an Xbox controller.

Introduction

Xbox 360 controllers use a standard USB interface, and since the raspberry pi has two USB ports, I wanted to hook up an Xbox controller and play a game with it.  There are a couple of other projects out there that hook controllers up to the raspberry pi and play games:

http://www.raspberrypi.org/archives/1754

http://www.raspberrypi.org/archives/tag/gaming

 

However they don’t seem to use Xbox controllers, and well, that’s what I have laying around.

I had also heard great things about the Scratch programming language and how it lets you quickly create games using a graphical interface.  Since it came pre-installed on Raspbian, I decided to give it a shot.

Xbox Controller

The first step was to get the Xbox controller to communicate with the raspberry pi.  To do this, I used xboxdrv, a linux Xbox 360 controller driver.  This was fairly easy to set up on the raspberry pi, just type:

 

sudo apt-get install xboxdrv

 

This will download and install the driver.

The driver is capable of translating button presses on the controller into keyboard keys.  I figured this would be the easiest way to integrate with a game since most respond to keyboard input.  To map the Xbox controller buttons to keys and run the driver, use the following command:

 

sudo xboxdrv --ui-clear --ui-buttonmap a=XK_space,b=XK_b,x=XK_x,y=XK_y --ui-buttonmap dl=XK_Left,dr=XK_Right,du=XK_Up,dd=XK_Down

 

This maps the D-Pad on the controller to the up/down/left/right keyboard arrows and the green A button to the space bar.  That’s the only keyboard keys that we care about for this demo.

Scratch Game

Looking at the scratch website, there were tons of games submitted by the community, so I decided to give one of them a shot and see how it worked on the raspberry pi.  The game that I landed on was Asteroid Avoider.  It’s a game where you fly through space and try to avoid asteroids.

Playing the game is a little tricky because if you have a keyboard and a mouse installed in the two USB ports, you need to remove one of them in order to plug in the Xbox controller. It makes navigating a little tricky, but it works.

Conclusions

Scratch running on the raspberry pi is slow.  This makes the game very difficult to play.  It looks like pygame performs much better.  However, connecting an Xbox controller to the raspberry pi is a breeze and seems to work great!

 

 

element14
Product Name*DescriptionBuy All PartsBuy All Parts
Raspberry Pi Model BRaspberry Pi Model BRaspberry Pi model B
Optical MouseOptical MouseBasic USB optical mouse
Raspberry Pi Power SupplyRaspberry Pi Power Supply120-240v to 5V power supply with micro USB connector
KeyboardKeyboardBasic USB keyboard
Additional Parts
Product Name*Description
8GB PNY Class 10 SDHC Card8GB Class 10 high performance SD memory card
Wired Xbox 360 controllerUSB Xbox 360 controller

 

*Products and resources listed are listed to help members build their own Pi Projects. They are suggestions and listed for educational purposes. For substitutions of any parts, please post a question asking the original author.
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube