PlayStation 2 Controller Arduino Library v1.0

Bill | June 5, 2010 in Projects, Source Code, Tutorials, Videos | Comments (29)

The first fully working version (v1.0) is now available. I split this into a new blog post, as many things have changed.

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.

Download here:

PS2X lib v1.41

Old Versions:

PS2X_lib_v1.0

PS2X_lib v1.3

PS2X lib v1.4

For those who missed the excitement the first time, here’s a wiring diagram(from the amazing CuriousInventor PS2 Interface Guide) and demonstration video:

Image Source: CuriousInventor

Here’s a video demonstrating the library.


29 Responses to “PlayStation 2 Controller Arduino Library v1.0”

RSS feed for comments on this post. TrackBack URL

  1. Comment by Bob — July 13, 2010 at 8:54 am  

    I have just checked the wires on the extender cable and they match the above pinout. I have verified they are connected properly and have added the resistors. The operating voltage is 5v for the board. I have checked the voltage at each wire and it ranged between 3.3 and 4.3v with the resistors. The Arduino Alpha software version 0018 only has one option for the duemilanove 128. When I push the analog button the red light dows come on. Any ideas? I’m lost. Thanks for the help

  2. Comment by Eric — July 13, 2010 at 11:53 am  

    I’m also getting the ‘No Controller Found’ error in Version 1.2 with the same board and wiring I was using that worked correctly with Version 1.0. I’m using the EL Sequencer board from SparkFun Electronics (http://www.sparkfun.com/commerce/product_info.php?products_id=9203), which is a 3.3V, LilyPad-compatible board. I have a 6″ flying-lead harness that goes from the EL Sequencer to the front-controller ports I’ve ripped out of an original PlayStation; everything after that is a stock SCPH-10010 cable and controller.

    I’ve gotten it to work by increasing the CTRL_CLK definition in PS2X_lib.h to 19. I’m guessing that it was originally decreased to 3 in version 1.2 to fix “Was running at 50kHz, not the required 500kHz.” as reported in the changelog. So it’s clocking slower, but it works.

  3. Comment by Bill — July 13, 2010 at 12:16 pm  

    Hmm, I had a feeling that the arudino delay-us function might have an issue with such a low value on 8 mhz AVRs. My arduino is 16mhz and works fine at 3us delay.

    Thanks for posting, I’m going to add a auto-increment clock delay code segment to the init function, just like it auto increases sentence delay if it’s not talking. That should cover the clock speed issue.

  4. Comment by Bill — July 13, 2010 at 5:47 pm  

    Well, I changed the clock back to 50kHz. Everyone having issues (Bob) download and install the new library v1.3 and see if it works then.

  5. Comment by Bob — July 14, 2010 at 9:59 pm  

    I have uploaded the latest version to the Arduino, checked and reject wiring. I got the error “Controller connected but not receiving commands” once and every other time it was “No controller connected”. Frustrating but definetly a learning process.

  6. Comment by Bill — July 14, 2010 at 10:08 pm  

    Bob,

    The fact that you got the “controller connected” error leads me to believe it’s a wiring or power issue; because for a split second, it worked. The only way it will return that error is if it successfully talked to and heard back from the controller.

    The only other thing I can think of is the clock is still too fast for you. If you open up the PS2x.h file, in the first few lines you will find “#define CTRL_CLK 20 ” try increasing that number to see if it helps.

  7. Comment by Bob — July 15, 2010 at 9:55 am  

    Thanks Bill, I toyed around with CTRL_CLK and it worked when I changed it to 500. Albeit does not detect the controller on every reset of the arduino it’s still great progress. One question about the button serial.print functionality. Why does the Square button display “Square just released” when pressed, X button displays “X just changed”, and both Select and Start buttons displays “being held”. Other than that thanks so much for taking the time to guide my newbie electronics mind into solving the problems I was having.

  8. Comment by Bill — July 15, 2010 at 10:15 am  

    Look through the example sketch. It’s demonstrating that my library has many different functions. Depending on your project, you may want the buttons to behave differently. Maybe you only want code to run if a button was just pressed, or just released, or being held!

  9. Comment by Bill — July 17, 2010 at 6:15 pm  

    Hey Bob,

    I just thought of something. My example uses pin 13 as the clock pin, but some arduinos have a LED tied to pin 13, and that may be messing with the controller. Try moving the controller’s clock line to another pin, and changing the pin number in the config_gamepad() function.

  10. Comment by storm — July 18, 2010 at 8:25 am  

    Regarding 50khz/500khz CTRL_CLK:
    your example ran like a charm, but in my project I had problems with interrupts happening during read_gamepad(). Analog stick values just jumped to 128 randomly. Setting clock to 500khz (CTRL_CLK = 2) fixed this completely + works great now. Thanks a lot for this!

Leave a Reply