Close

Communicating with a PS2 Controller

A project log for Universal Controller

One controller to rule them all! A PS2 controller crossed with an AVR and XBee / Bluetooth, to use in multiple physical computing projects.

the-big-oneThe Big One 04/09/2014 at 22:170 Comments

PS2 controllers are actually pretty easy to interface with; they use SPI mode 3 (CPOL=1 and CPHA=1); while in theory you could use the SPI hardware on an AVR to talk directly to the controller, I chose to just write my own (adapt my own) bit-banging protocol.

There are a few good sites which have protocol details; in our library, we started with Bill Porter's Arduino library, and adapted it to work with raw AVR-GCC rather than requiring Arduino.  

Over time, I ended up re-writing much of the code (both because I could, and also to make the timings a bit closer to spec).  The PS2 protocol details as described at http://store.curiousinventor.com/guides/PS2/#high_level were invaluable to this project; just because the hardware uses SPI, doesn't mean that it understands what you are sending!

In its current form, our PSX library provides a simple API for communicating with PS2 controllers.  It allows for reading of all 16 buttons (everything other than the 'Analog' button, which is a special function), as well as 8 bit values for X and Y axis on both joysticks.  It does not handle button pressures or vibration motors, but it would be relatively simple to add support for that if you are interested in it.

For details on the PSX library component, and to download the code, please see http://digitalcave.ca/resources/avr/psx.jsp

Discussions