PlayStation 2 Controller Arduino Library v1.0

Posted in Arduino Libraries by Bill
5 Jun 2010
PlayStation 2 Controller Arduino Library v1.0

Want to interface a PlayStation 2 Controller with an Arduino Microcontroller? You have come to the right place. Below you will find a link to download an easy to use library that takes care of all the interfacing for you, so you can start using the controller right away for your project. Don’t forget to link your cool projects in the comments, I’d love to see what you do with the library.

First, a brief history:

A while ago, I spent countless days trying to interface an Arduino and a Play Station 2 controller. I wanted to build a controller for my SAGAR robot, and figured PS2 + Arduino would be perfect. However, no matter what I did, no existing library would work for me. I shelfed the project for a while, but recently found this forum post with some code by a member named Shutter. I tried out the code, and to my surprise, IT WORKED!!! Well, mostly anyway. It didn’t really have analog stick support, nor was it formatted into an easy to use library. Well, through need I spent some time adding analog stick support, and formatted it into a library. It works fine on my Arduino Pro mini.

The first fully working version (v1.0) is now available. The big change is you can now define what pins of the Arduino are used, no longer are you tied to pins 10-13. Also, vibration (Rumble) and analog button pressure readings (how hard is a button being pressed) are now working. The library has changed names. PSX -> PS2X to avoid confusion with other sets of code. Sorry for those that need to change a bunch of their programs.

I had to rewrite a lot of code that powers the library, there is not much left of the original code written by Shutter of Arduino forums. There were many bug fixes, now the controller should automatically be in analog mode, and the mode button should be locked. There’s also a catch to make sure not to much time has past since the last controller reading. If there was, it will configure the controller again, in case it timed out.

Source Code available on GitHub project page.

 

Download PS2X

 

Old Versions:

PS2X_lib_v1.0

PS2X lib v1.41

Arduino PS2 Controller Library V1.5

Wiring the Controller

The seemingly most notorious part prone to errors is wiring the controller to the Arduino. Lynxmotion sells a nice breakout connector available HERE.

WARNING! WARNING!

The Lynxmotion adapter may not follow the color wiring diagram below. Instead, it might follow this diagram. (Lynxmotion only). Be careful and use a volt meter to confirm pin positions.

Or, to wire the controller not using the Lynxmotion adapter, follow the pinout in the following picture from the amazing CuriousInventor PS2 Interface Guide:

Image Source: CuriousInventor

A note from CuriousInventor: “Red – Power: Many sites label this as 5V, and while this may be true for Play Station 1 controllers, we found several wireless brands that would only work at 3.3V. Every controller tested worked at 3.3V, and the actual voltage measured on a live Playstation talking to a controller was 3.4V. McCubbin says that any official Sony controller should work from 3-5V.”

Here’s a video demonstrating the library.

Guitar Hero Controller Example

The following is a video and source for example of how to use the library with a Guitar Hero Controller.

Source: (tested with v1.5, should work with v1.6 as well)

Guitar Hero Example Arduino Code

Guitar Hero Example Processing Code (thanks Patrick)

Another Demo

Author unknown

Project Showcase

Hey guys, feel free to drop a link off in the comments to your project that uses my library. I’ll post it here.

  1. Guitar Hero Axe Controlled Flamethrowers by Chris Marion
  2. Scanalogic Review by CuriousInventor
  3. SAGAR by Me
  4. Remote Controlled Robot (Video) by ‘teachengineering
  5. ‘America Dream’  Electric Hammock by Stephen Shaffer
  6. Life size R2D2 robot by Dan
  7. Simon Says via DDR mat by Dalpix

Trouble?

Follow my troubleshooting guide first and then visit the Support Forum if you still can’t get it working. Don’t ask for help in the comments below.
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Share

Trackbacks / Pingbacks

  1. Assignment 7: Electronics Prototyping – Mamma Mia! Look at My Arduino! | Tar's Adventures in HCI+D
  2. Assignment 7: Electronics Prototyping – Mamma Mia! Look at My Arduino! | Tar's Adventures in HCI+D
  3. Usare joystick PS2 sul PC e sulla PS3 con Arduino. | TecnoMente

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/46/d285670699/htdocs/bill/wp-includes/comment.php on line 879
  1. 587 Comments.

    • VishNo Gravatar says:

      Hi, I got the following error while debugging… Could you please explain what this means… thanks.
      OUT:IN
      1:FF 42:1 0:10 0:FE 0:FF 0:FF 0:FF 0:FF 0:FF 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      OUT:IN
      1:FF 42:1 0:10 0:FE 0:FF 0:FF 0:FF 0:FF 0:FF 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      Controller mode not matched or no controller found
      Expected 0x41 or 0x73, got 1
      No controller found, check wiring…

    • hemant raidasNo Gravatar says:

      i found this error always….

      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN
      1:0 42:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN Configure
      1:0 43:0 0:0 1:0 0:0
      OUT:IN Configure
      1:0 44:0 0:0 1:0 3:0 0:0 0:0 0:0 0:0
      OUT:IN Configure
      1:0 43:0 0:0 0:0 5A:0 5A:0 5A:0 5A:0 5A:0
      OUT:IN
      1:0 42:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      No controller found, check wiring, see readme.txt to enable debug. visit http://www.billporter.info for troubleshooting tips
      Unknown Controller type found

    • ModimNo Gravatar says:

      Arduino IDE gives me an error when trying to compile the example to my Arduino UNO board.

    • Ch khuanNo Gravatar says:

      Hello,Bill:
      Can I use Playstation 1 controller instead of PS2 controller? What is the difference if I use the PS1 controller?

    • AshutoshNo Gravatar says:

      Hi, can i please get the wiring or fritzing circuit diagram for where to connect the pins on my arduino?
      Thanks in advance!

    • NkNo Gravatar says:

      Hi Bill!
      I have used your ps2x library before with arduino UNO its great…
      but now i have “Arduino Due” your library is not compatible with Due?
      So can you edit this library for Arduino Due
      Thank you in advance…

    • ANo Gravatar says:

      Bill,

      I spent $5 on a PS2 controller from GoodWill and hooked it up to my Arduino Mega.

      Downloaded everything from your website and after minor debug…Wallah!

      So now that everything works I thought I’d write a thank you note, as well as reflect nostalgically on the PS2. (I’m a GenX’er, after all. We’re very nostalgic)

      Actually growing up I hated the PS2. We sat there starring at TV’s while pressing memorized (or in my case not memorized) sequences of buttons.

      Of course since all my fellow GenX friends loved the PS2 I was considered to be very stupid.

      So it’s with a grin that now I’m making a PS2 controlled robot. Where are all their PS2’s now? Thought so! (Intentional “smack talk” tone unintended)

      Yep, now I love the PS2 (or atleast the controller).

      🙂

      Again many thanks,

      A.

      • FerricNo Gravatar says:

        did you use a wired or a wireless controller……?
        i have a wireless controller and i am getting many errors

        • ANo Gravatar says:

          I used a genuine PS2 controller that is wired.

          I have not tried the wireless yet and so can’t comment on it. I’d like to try that next though and would like to know that it’s feasible.

          Did you add a pull-up resister between the Data line and 5V? There’s a “debug” document on the website with additional suggestions as well…

          Also lots of feedback saying the aftermarket PS2 compatibility isn’t always consistent with the Arduino. Perhaps easiest to just get a genuine PS2 with cable for debug and go from there.

    • […] was painful. So how did I arrive to such an idea? I discovered that some very nice hacker made a PS2 controller arduino library publicly available and came across some examples of people using their old controllers to not only […]

    • […] was painful. So how did I arrive to such an idea? I discovered that some very nice hacker made a PS2 controller arduino library publicly available and then came across some examples of people using their old controllers to not […]

    • VijayNo Gravatar says:

      Hi

      is it possible to use this library to output ps2 controller commands and if so can you help me with it by giving me an example

      thank you

    • mattNo Gravatar says:

      I am curious, I know most of the buttons(excluding Start, analog, and select) are pressure sensitive. How many bits of analog is this? And is it utilized in the library? Thanks looks awesome! I am thinking of using it as control of an underwater ROV and the display on my laptop.

    • StevenNo Gravatar says:

      Hi, I’m trying to implement this library but this is the error I am receiving:

      OUT:IN
      1:FF 42:1 0:10 0:FE 0:FF 0:FF 0:FF 0:FF 0:FF 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      OUT:IN
      1:FF 42:1 0:10 0:FE 0:FF 0:FF 0:FF 0:FF 0:FF 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
      Controller mode not matched or no controller found
      Expected 0x41 or 0x73, got 1
      No controller found, check wiring, see readme.txt to enable debug. visit http://www.billporter.info for troubleshooting tips
      Unknown Controller type

    • FerricNo Gravatar says:

      did you use a wired or a wireless controller……?
      i have a wireless controller and i am getting many errors

    • […] PS2X: creata da Bill Porter, la potete scaricare dal suo sito (scendendo un po’ trovate Download […]

    • varanNo Gravatar says:

      I’m using wired ps2 controller
      my controller was giving 2.data = 0x79 and i was not able to switch off analog mode then suudenly after sometime 2.data changed to 0x73 (when analog mode is on) and i was able to switch off anlog mode (2.data became 0x41) .
      I am not to figure out why this happens.

      Please someone help.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.