Shop OBEX P1 Docs P2 Docs Learn Events
PlayStation 2 Analog Buttons — Parallax Forums

PlayStation 2 Analog Buttons

Duane DegnDuane Degn Posts: 10,588
edited 2014-05-27 12:35 in Propeller 1
I read, a while back, on Wikipedia, the buttons on a PlayStation 2 controller are pressure sensitive.

None of the PlayStation 2 Objects I've seen use the pressure information. Since I hadn't seen any projects or objects that treated the buttons as analog inputs, I figured Wikipedia was wrong about the PS2 controller.

In attempts to modify one of the PS2 objects for a recent project, I learned that the PS2 controller does indeed have pressure sensitive buttons. With the help of the internet, I've got the Prop to read these (12) analog button values.

I personally think it is pretty cool to have this additional level of control from the PS2 controller. I have no idea how I'll use these analog buttons in any of my current projects, but I like knowing they're there.

I thought some of you might be interested in this information.

Are there any objects for the Propeller that read the analog button values? If not, I'll make sure and post the modified object.

Edit: Now in OBEX.

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2012-04-23 10:11
    Good source documentation for PS2 controllers are here, if anyone's interested: http://www.geocities.co.jp/Playtown/2004/psx/ps_eng.txt and
    https://docs.google.com/View?docid=ddbmmwds_5cw4pk3
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-24 13:02
    Mark,

    Thanks for the links. The first link included a space character at the end that kept my browser from finding the correct page.

    This link should take people to the correct page.

    The second link took me to a Google Docs login page.

    I'm just about finished with my demo showing off the analog nature of the PlayStation 2 buttons. I'll be uploading it soon.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-24 13:40
    Attached is the modified PlayStation 2 object and demo.

    Here's the output from the demo with the analog buttons turned on and with the square, circle and right arrow buttons pressed.
    Press "d" to enter digital mode.
     Digital mode will turn off the analog buttons.
     Press "a" to enter analog mode.
     Press "b" to change to analog button mode.
     If not all ready in analog mode this option will change
     the controller to analog mode.
       Mode: Analog                    Joysticks and analog buttons in use.
                      Left             Right
                   x:108 y:138      x:133 y:131
       Buttons:  Sq   X    O    Tri  R1   L1   R2   L2
       Digital:   1    0    1    0    0    0    0    0
       Analog:  126    0   66    0    0    0    0    0
    
       Buttons:  <    v    >    ^    St   JR   JL   Sel
       Digital:   0    0    1    0    0    0    0    0
       Analog:    0    0   57    0
       Raw: $5FDF5A79,$8A6C8385,$00000038,$7E004200,$00000000
       All Buttons: 01111111011111
       Last debug message: Turned on analog buttons.
       Last action:
       programName = dwdPs2Demo120424g
    
    

    There aren't any methods to convert the raw data to joystick values. These conversions are done in PASM with the results written to hub RAM.

    The parent object needs seven longs and 34 bytes to hold the controller information.
    VAR
      
      ' Keep below in order and together.
      long [B]psData[5], allDigitalButtons, debugLong
    [/B] ' Keep above in order and together.
      
      ' Keep below in order and together.
      byte[B] rightX, rightY, leftX, leftY
    [/B] byte [B]digitalButton[Ps2#_NumberOfControllerButtons]
    [/B] byte [B]analogButton[Ps2#_NumberOfAnalogButtons], mode, dataSize
    [/B] ' Keep above in order and together.
    

    Once the PS2 object has been started, it doesn't need to be called again except to change modes. The controller is continuously polled with the new data continuously written to hub RAM.

    The demo will start out in digital mode (boring); you'll need to press "b" on the keyboard to turn on the analog buttons.

    I tried to add comments to explain how to use the object. One thing to keep in mind is that there are three different sets of button data being written to the hub.

    Here's a quote from the comments.
    The bits representing the button states are ordered
      differently than the bytes measuring the pressure of
      the analog buttons.  The program uses the same button
      order for both the digital buttons and the analog
      readings from those buttons.
      This reordering of the pressure data should make it
      easier to use with the digital button data.
      The button states are reported three different ways.
      The state of all 16 buttons are written to a long with
      each button being represented by one bit.  A low value
      in the button's bit position indicates a button press.
      The second set of button data is an array of 16 bytes.
      The normal state of these bytes is zero.  A button
      press with cause a one to be written to the corresponding
      byte.
      The third set of button data is held in a 12 byte array.
      The bytes in this array contain the pressure reading
      for each button.  These reading vary from zero (for
      no pressure) to 255 (full pressure).
     
    

    I personally think it's pretty cool these buttons will output analog values and I look forward to using these buttons to control aspects of a robot.

    Hopefully some of you will find it useful.

    Let me know if any of you have questions or suggestions for improvement.

    I do play to add control to the Dual Shock motors. I will also likely add a way of locking the controller in the various modes.

    Edit(3/11/15): Warning, the code attached is an old version. There are likely better options available.
    I plan to upload this program or an improved version to my GitHub account
    If there isn't code similar to what is attached here on my on GitHub, send me a message and I'll make and check for any improved versions of the code.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-24 17:32
    I realize I never posted a link to the site that helped me the most with this driver.

    The Curious Inventor has a lot of information about the PlayStation 2 controller.

    I've read conflicting information about the controller. Is it a 5V device or a 3.3V device?

    I'm currently powering it with 3.3V.

    I know I've mentioned my dislike of generic controllers, but I thought I'd mention it again in this thread. The first controller I purchased was from SparkFun. I was disappointed to find the joysticks only had 5-bit resolution instead of the 8-bit resolution provided by the Sony controller.

    I'd strongly recommend getting a Sony controller over a generic controller. The Sony controller only costs $5 more than the $10 generic. I just tried to find the $15 Sony controller I had seen on Amazon and I couldn't find it. This was the only normal black Sony PlayStation 2 controller I could find on Amazon and it costs $20.

    I wish the reviews of the generic controller would mention how many bits of precision the used.

    To be honest, I'm not sure how the 5-bits vs 8-bits would effect my use of the controller. It just bugs me on principle that the generic controller has less resolution the original Sony controller.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-03 09:02
    I just added this to the OBEX.

    http://obex.parallax.com/object/460

    If any of you use PlayStation 2 controllers, I hope you give it a try.
  • dgatelydgately Posts: 1,621
    edited 2014-05-27 12:12
    Duane,

    The OBEX links in this thread no longer work. I get a 404 error trying to access them. You may want to update the links here to the new OBEX URLs...


    dgately
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-27 12:35
    Thanks for the heads up.

    I try to keep the links in my index up to date but I didn't think about my one and only OBEX entry.
Sign In or Register to comment.