Arduino Playstation 2 Controller Library Troubleshooting Guide

Posted in Arduino Libraries by Bill
27 Mar 2011
Arduino Playstation 2 Controller Library Troubleshooting Guide

Ok, if you are here, you are having trouble getting your Arduino talking to your PlayStation 2 Controller via my Handy Dandy PS2X Library. Well, never fear, I stand by my leet coding abilities (Ha! who am I kidding? Really though, the library works, there’s tons of examples using it.) and I’m here to help. The problem is there’s not much I can really do unless you live near North Florida and want to come pay me a visit. It’s hard giving help over the internet! But maybe I can guide you in the right direction with this troubleshooting guide.

I’ll walk you through some debugging steps, and you should follow through with me with DEBUG off until I tell you to enable it and using the example sketch unmodified. In-between attempts, power off the Arduino and controller for 10 seconds before testing it again.  I’ll bold the quick steps if you want to skim through.

A little background first. I have not personally reverse engineered the communications protocol a PS2 controller uses. That has been done by a few other cool guys like this one.  I used what they reported in writing the PS2X library. As far as I know Sony has never official published the communications protocol to the public, so reverse engineering efforts is all we have to go on. This has lead to a few problems; for example some controllers just don’t behave like others. From the various sources around the web, the best chance of success comes from using ‘Official’ Sony controllers, and not the cheap knock-offs, 3rd  party controllers. There’s also some links with wireless controllers not working well either. Personally I have tried a wired Sony controller, and a few wireless Guitar Hero Controllers all with success, powered at 5V and no resistors.

Therefore the first thing to consider is what controller are you using? Can you try another brand, model?

Ok, now that we are past history of controllers, I’ll tell you this: 90% of the problems people have end up being related to wiring. I can’t look at your setup, so you are going to have to use your best judgment. Does the wiring look sound? Controller wires are thin and small and tend to break easily. During prototyping, I cut the ends off my wired controllers, stripped 1/4″ insulation off and heavily tinned the wires to create solid ‘pins’ that could be pushed into the female pinheader on the Arduino. This method worked, but was fragile. Later on I bought a few $5 PS2 controller extension cables and cut off the female receptacle end. I soldered the wires from the plug to PCB board and that worked well also.

 

Don’t trust the color scheme on the wiring picture. It can vary! Instead, use a voltmeter and test continuity between pin positions in the connector and the bare wires. I’ve had a few people report odd color schemes, and a few not realize what end of the connector they were looking at and got the wiring completely backwards. A quick check is to power up the controller, and pushing the ‘Analog’ button. Either the LED should have been on when it powered up, or it should light up when you press the button. If not, the controller isn’t getting power and you probably have the wiring reversed.

Alright, so you trust the wiring job, what next?

There are discussions over whether or not the controllers are tolerant of 5V logic. I’ve never had one burn out, so I believe they can handle “receiving’ 5V, but they still won’t ‘send’ 5V to the Arduino. It seems to me the one fix that seems to work the most is adding a 10k resistor between DATA (brown wire, or pin 1 on the controller port) and VCC (try both 3.3V and 5V in that order) on the Arduino.

This will help ‘pull-up’ the data line. Also there’s disagreement on what voltage to use to power the controller. A PlayStation powers the controller at 3.4V. I have always powered my controllers at 5V and had no problems, but it is risky. Controllers are so cheap on ebay though, why not try it? Try different voltages for power, switch between 3.3V and 5V, and for each voltage try it with and without the pull-up resistor on the DATA line .

One person claimed his controller wouldn’t work without level shifting all his wires, which means he just added resistors inbetween the controller’s pins and the Arduino.

The numbers he reported success with is as follow:

  1. 5V = 180 ohm, voltage drop of 1.85V (3.15v to the controller)
  2. ATT = 5.6K ohm, voltage drop of 1.08V (3.92 to the controller)
  3. CLK = 5.6K ohm, voltage drop of 1.15V (3.85 to the controller)
  4. CMD = 860K ohm, voltage drop of 1.39V (3.61 to the controller)

so you can give that a try as well. Though really, ignore the resistor on 5V and just connect the red power wire to 3.3V.

Some people report issues using pin 13 on the Arduino for CLK. Try moving the CLK line to another pin, and editing the example sketch to match.

If you have gotten this far and still no luck, you might just be out of luck. Controllers can go bad and some people just aren’t any good at wiring. But, there’s one more thing we can try messing with.

There’s a value in the ‘PS2X_lib.h’ file that governs the speed of the bus to the controller. It’s called ‘CTRL_CLK’ and you can find it by looking for this line:

#define CTRL_CLK        4

The PlayStation 2 talks to its controllers at 500kHz, or a value of ‘2’ in my library. Arduino tends to have issues setting a value that low, so by default I have it set at 4. You can try using 2 instead, and I’d also try using some higher number for a slower bus speed. Go from 2-20 and even 200 to see if you can get the controller talking. Remember to save the .h file every time you edit it, and re-compile the sketch.

Still no luck? Man you are killing me. I’ve dropped all my suggestions into this guide, so there’s not much else I can say even if you ask really nicely. Florida is nice year round, so feel free to come visit me and I will help you in person. Otherwise, you can try to enable debug. It won’t really help diagnosing wiring problems (or bad controllers) because all you will see is all FF’s or 0’s. But if you are getting some values, they may be something else going on. Drop the output in the Support Forum and I’ll see if I can help.

My last fleeting thoughts include removing the checks in the example. At the end of the setup function (after the switch statement and before the closing curly bracket ‘}’ ), add the following code:

error = 0;

type = 1;

This will bypass the error checking and run the code anyway. What do you get? Try pressing reset on the Arduino without disconnecting the controller. Anything?

Still need help?

Use the Support Forum to ask for help. Please don’t use the comments below.

Share

Trackbacks / Pingbacks

  1. PlayStation 2 Controller Arduino Library v1.0 « The Mind of Bill Porter
  2. DIY Arduino Intervalometer : DIYfilm
  1. 180 Comments.

    • […] my troubleshooting guide first and then drop me a comment if you still can’t get it […]

    • MECANo Gravatar says:

      Hey Bill, Just wanted to let you know that It works now. The trouble shoot guide pointed me straight to my solution. I powered the controller through the Arduino’s 3.3 volt output, pulled the data line up through a 10K resister and the 5 V pin on Arduino and it worked like a charm. Thank you very much for your continued support with your library and related subjects.

    • JohnNo Gravatar says:

      You, sir, are an absolute gem!

      Collating 250 comment’s worth of useful info into one post solved all my problems in about 10 minutes.

      Like Meca, I added a 10K pull up resistor, dropped the clock speed to “14” in the header file, and it’s working like a charm.

      Thanks again Bill!

    • BillNo Gravatar says:

      Haha, glad to hear it guys. Afternoon well spent then.

    • JohnNo Gravatar says:

      I didn’t try it yet, but a thought occured. Each pin on the Arduino has a built in 20K pull up resistor.

      For those of us that have got it working with a pull up resistor, I wonder if we can remove that and just enable the built in one via code.

    • ChipsNo Gravatar says:

      Thanks Bill – The troubleshooting guide worked great!

    • JohnNo Gravatar says:

      Well, it *was* working perfectly, now it randomly thinks Select, Right and occasionally L3 are being pressed.

      Oh well, it could just be that this 3rd party controller is a bit dodgy. Have an official Sony one arriving in the mail in the next day or two, at least then I’ll know for sure one way or the other. 🙂

      • BillNo Gravatar says:

        O dear. Also could be a wiring issue with intermittent bit flips. You could try slowing down the clock.

        • JohnNo Gravatar says:

          Yeah, that was the first thing I tried after double checking I hadn’t accidentally altered something in my code and forgot about it (even went back to your original example code with the library).

          It detects the controller, tells me to try out all the buttons, that X will vibrate the controller (which it won’t, because I don’t have power going to the motors), and all that lot, and when I press a button it knows I’ve done it (any button), but it’s randomly coming up with Select and “Right held this hard: 0” when I’m pressing nothing.

          Not seeing so much of the fake L3 button presses as I was earlier.

          So, it could be something up with the wiring. I set it up on an old piece of stripboard, but have a bunch of new board and other bits arriving tomorrow too, so will cut the wire back, strip new ends and start over. Fingers crossed 🙂

        • JohnNo Gravatar says:

          Oh yes, forgot to mention, it only does it when the controller’s in analogue mode. If analogue mode is turned off, the buttons push fine, and it doesn’t come up with the random phantom button presses.

          Obviously though, then I get no input from the joysticks, and no pressure readings from any buttons. 🙁

    • JohnNo Gravatar says:

      Well, solved it, but it’s still odd because the last couple of hours I’ve had it wired up exactly how I had it working before (which is, with the red wire connected to 3.3v).

      Because everything was wired up as it was before, I didn’t think to switch it, but I just figured I’d try it. Once I put it over to 5v it magically all works again. Extremely odd as it was working on 3.3v just fine earlier.

      • BillNo Gravatar says:

        Good to hear. Yeah, voltage level has always been an odd subject. Some only work at 3.3, some only at 5.

        Also, you shouldn’t be able to ‘turn off’ analog. My library should be locking the controller mode so the analog button does nothing. Can you confirm it’s that way now?

        • JohnNo Gravatar says:

          Indeed it does lock it, but I discovered that if I unplug the controller after it’s initialised everything, then plug it back in, it’ll let me switch modes. 😉

    • Michael RogersNo Gravatar says:

      Thanks for the library, Bill. It’s working great for me with the official controller, but not so much with a logitech wireless controller. It’s odd, the d-pad, stick buttons, start, and select work fine. But the four buttons on the right and the shoulder buttons are very unresponsive, almost never working, just one out of very so many presses. More odd still, even though X almost never prints out to the serial console, the vibration matches the press perfectly, indicating the library is in fact getting the button press, just not printing it. Any thoughts?

    • Michael RogersNo Gravatar says:

      I wasn’t feeding the 9v to the wireless receiver, I don’t know if that had any part in it. Obviously it’s not using it to drive the motors, but I don’t know if it still uses it for something else. I don’t need rumble for my project so it’s no problem.

    • Corey McCauleyNo Gravatar says:

      I got my controller to work…somewhat. It powers on and the analog light stays on but it won’t stop vibrating and the feedback in the serial monitor is tons of random characters and there’s a constant stream of them. Any ideas?

    • […] you to Bill Porter for writing this great PS2 Library for the Arduino and for also getting up a troubleshooting guide for those of us who are a bit more electronically […]

    • JoeNo Gravatar says:

      Awesome, I had to change CTRL_CLK to 7 on an Arduino Nano to get it to recognize the controller. All works 100% now except vibrate which does nothing, next thing to troubleshoot!

    • TImNo Gravatar says:

      I found it quite easy to just split the plug on the end of the PS2 controller to figure out the wiring. There’s a horizontal split where the plug turns from shiny plastic to matte. What’s helpful about this method is that you know without a doubt you’re getting the right pin regardless of pin color and you keep the metal pins on the end which fit quite nicely into a breadboard. BTW…I happened to split apart the plugs on two controllers (one was not working) and found two wires (black and gray) connected to ground pin (as you identified above).

      Thanks for the library…

    • Devon SimmonsNo Gravatar says:

      The Read_gamepad() function seems to make servos jitter quite badly when used with the Servo library included with the arduino sofware. Is there a fix for this?

Leave a Reply