Shop OBEX P1 Docs P2 Docs Learn Events
Playstation Controller to Propeller — Parallax Forums

Playstation Controller to Propeller

Red-327Red-327 Posts: 1
edited 2006-07-26 11:50 in Propeller 1
Has anyone connected a Playstation Controller to the Propeller successfully yet?
The picture below is how I was trying to connect two controllers to the BS2p Stamp, which I have not successfully completed yet.· Once I saw the Propeller I decided to stop working with the BS2p.
Thanks,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ringo Klassen
900 x 700 - 122K

Comments

  • Dual ExhaustDual Exhaust Posts: 15
    edited 2006-06-11 05:54
    Did you ever see the article published in "Nuts and Volts" about attaching PS controllers to a Stamp? If not, I'll be glad to find the article and send it to you. It fully explains the process of obtaining the PS controller values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "It is not necessary to change. Survival is not mandatory."
    - W. Edwards Deming
  • Dennis FerronDennis Ferron Posts: 480
    edited 2006-07-26 11:42
    Hi,

    I did this with a BS2 for a "macromouse" project that I did - long before commercial macromouse product even existed. What I did was connect a playstation controller to the board from a mouse using a Basic Stamp. The Stamp would read the playstation controller and then fake the mouse circuit board into thinking someone was moving the mouse and clicking buttons. The stamp would record all of your movements into a "macro" which you could later play back.

    I've attached the entire source code for the project to this post, you're welcome to re-reverse engineer the PSX controller stuff from it. Essentially, the PSX controller makes an IDEAL controller for interfacing to a microcontroller project:

    - PSX2 controllers and analog controllers are backwards compatible with the PSX1 controllers. Essentially, if your code knows the older PSX1 controller's protocol, it will still work with newer controllers too!
    - The controller uses synchronous clocked logic with the microcontroller as the clock, so there're few timing issues involved.

    Basically, it's so simple, all you have are 3 pins to worry about. You pull the Attention pin low when you want to get the PSX controller's attention. Then you cycle the CLOCK pin on the controller at whatever speed you want, while putting bits one at a time on the data line. You send a magic number in this way, and then the controller sends back another magic number and the 16 bits following that can be stored in a variable; they will be 1 or 0 depending on which button is pressed. There are comments in the source code I attached which explain the magic numbers and what button each bit position represents. That's all there is to it.

    Since the program is huge (the biggest Stamp program I've ever written), and the controller code is not all in one place, I'll highlight the important functions here:



    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '  ReadController
    '
    '  - Queries the controller for which buttons are pressed
    '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '  Args:     None
    '
    '  Returns:  ButtonBuf (16 bits) contains the states of
    '            the buttons on the controller; all of the
    '            bXXXXX variables are set because they alias
    '            bits in ButtonBuf
    '
    '  Notes:    Technically we're supposed to wait for the
    '            Ack signal from the controller in between
    '            bytes. However, I believe the Basic Stamp
    '            is slow enough that that won't be a problem,
    '            and leaving it out makes both the program and
    '            the circuit simpler.
    '            If you start experiencing bit mixups between
    '            adjacent bytes, you might check you Ack signals.
    '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ReadController:
    
    ' Get the controller's attention
    oAttention = 0
    
    ' Bytes #1 and #2 - send the start command ($01) and
    ' the request data command ($42)
    SHIFTOUT oCommand, oClock, LSBFIRST, [noparse][[/noparse]cStartAndReqData\16]
    
    ' Byte #3 - skip the "here comes the data" byte
    SHIFTIN iData, oClock, LSBPRE, [noparse][[/noparse]ButtonBuf.LOWBYTE]
    
    ' Bytes #4 and #5 - get the buttons
    SHIFTIN iData, oClock, LSBPRE, [noparse][[/noparse]ButtonBuf\16]
    
    ' Release the controller's attention
    oAttention = 1
    
    ' Return the clock to resting state
    oClock = 1
    
    ' Make the bits true if the button was pressed
    ButtonBuf = ~ButtonBuf
    
    RETURN
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '  End of ReadController
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    ' The output from the controller is stored in a word.
    ' Each bit in the word represents a button.  Here I
    ' defined symbol names for the buttons for each
    ' individual bit in the word that was stored by
    ' ReadController:
    
    ' Buttons on the PSX controller
    ButtonBuf VAR Word
    bSlct VAR ButtonBuf.BIT0
    bJoyR VAR ButtonBuf.BIT1
    bJoyL VAR ButtonBuf.BIT2
    bStrt VAR ButtonBuf.BIT3
    bUp VAR ButtonBuf.BIT4
    bRt VAR ButtonBuf.BIT5
    bDn VAR ButtonBuf.BIT6
    bLt VAR ButtonBuf.BIT7
    bL2 VAR ButtonBuf.BIT8
    bR2 VAR ButtonBuf.BIT9
    bL1 VAR ButtonBuf.BIT10
    bR1 VAR ButtonBuf.BIT11
    bTr VAR ButtonBuf.BIT12
    bO VAR ButtonBuf.BIT13
    bX VAR ButtonBuf.BIT14
    bSq VAR ButtonBuf.BIT15
    
    
    ' Note:  Pin declarations are relative to the stamp in my
    ' circuit, not relative to the PSX controller.  I
    ' assume you have or can get the pinout of the
    ' controller connector; if not, I'll dig up the schematic
    ' for the automouse.  i means "input", o means "output"
    ' (again, relative to the stamp).
    
    ' PSX controller pins
    iData PIN 6
    oCommand PIN 12
    oAttention PIN 11
    oClock PIN 13
    iAck PIN 7
    
    
    ' To get a correct first reading from the controller,
    ' here is how you should initialize the pins:
    
    ' PSX Controller pins
    INPUT iData
    INPUT iAck
    
    OUTPUT oCommand
    OUTPUT oAttention
    OUTPUT oClock
    
    ' "Resting" state
    oAttention = cPsxcOff
    oClock = cPsxcOff
    oCommand = cPsxcOff
    
    
    ' I defined descriptive constants for the
    ' states of the PSX controller control pins.
    ' For the PSX controller, a 1 means off and
    ' a 0 means on (backwards of intuitive meaning).
    ' This is for signals going from the stamp to
    ' the PSX controller.  For signals going from
    ' the controller into the basic stamp, you should
    ' be aware that they are open collector outputs,
    ' and must be pulled up with a 2.2K resistor or
    ' else the stamp won't detect a logic-1 state
    ' from the controller when it should.
    
    ' Control states
    cPsxcOff CON 1
    cPsxcOn CON 0
    
    
    
  • Dennis FerronDennis Ferron Posts: 480
    edited 2006-07-26 11:50
    To reiterate (I said it in a source code comment but I don't expect people read source code, they only cut and paste):

    The signals coming from the controller are open collector TTL signals. You need to use 2.2K pull up resistors to bring the outputs up to VCC (i.e. 3.3 volts) when they are off, otherwise instead of 0 and 1 your logic levels will be 0 and "sort of 0". Needless to say you would only read garbage. It's easy to forget them - I did on my automouse.

    Also, I sucessfully ran a controller off 5 volts for the automouse project, but I think that the playstation controller actually expects a 3.3 volt supply anyway, so just power the controller from the same supply as the prop.
Sign In or Register to comment.