Shop OBEX P1 Docs P2 Docs Learn Events
Snooping on a PS2 controller... — Parallax Forums

Snooping on a PS2 controller...

BamseBamse Posts: 561
edited 2006-01-29 20:26 in BASIC Stamp
Howdy...

I was able to read the PS2 controller using the article in Nuts and Volts from September 2003...
http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf

Now I want to figure out how to use the actuators (feedback) in the pad and my plan is to snoop on a pad hooked up to Playstation...
I have a PS2 Linux Kit so I can programatically send commands to the pad so I would know what command I'm snooping on...

The plan is just to hook up three pins on the BS2 to pin 2 (PsxCmd), 6 (PsxAttn) and 7 (PsxClock, inverted with the 2N3904) on a connected pad...
Would I need a resistor between the pad and the BS2 ???
Then send commands every three seconds and try to snoop on these by waiting for Attn to go low and do a SERIN from the PsxCmd...

Does this seem like a reasonable approach???

Jon Williams had a recent article in N&V where he put up a Professional Development Board and I sent him a PM earlier to see if the PDB was still up for grabs...
He has already received feedback and he might already have the information to do this...
Anyhow, this would be my weekend project, a good learning experience so to say... yeah.gif

/Bamse

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-28 20:01
    There's a lot going on at Parallax right now so I'm still evaluating the TON of feedback I received on that article, some from a very surprising source. At any rate, we often put 220-ohm resistors inline with output pins; if what they're connected to also turns into an output and goes to the opposite state the resistor will protect the Stamp pin. It's cheap insurance, that's all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BamseBamse Posts: 561
    edited 2006-01-29 20:26
    Looks like I hit a wall here, I have tried all possible combinations of Attn and Clk going Hi/Low.
    The output is always ""PsxIn: FF"...

    I have some coding background, but Basic is new to me so I wonder if I did anything wrong in the code...

    Electronics is totally new to me so it might be something wrong here too... roll.gif
    I measured the voltage between 4 (Vss) and 5 (Vdd) on the PS2 pad and it's 3.5 V...
    Shouldn't that be enough for the BS2 to detect a High signal ???

    The programming of the PS2 pad seem to work fine, I turn on the actuator for 3 seconds then turn it off for 3 and loops...
    Another strange thing is that my results are displayed out of sync with my commands sent to the pad so I wonder if I can read Attn properly at all...

    /Bamse

    ' =========================================================================
    '
    '   File...... Snoop2.BS2
    '   Purpose... Snooping on a PlayStation Controller
    '   Author.... Fredrik Safstrom
    '   E-mail.... Bamse@alleberg.com
    '   Started... 29 January 2006
    '   Updated...
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    
    ' Snoop one byte on a PS2 controller...
    ' Dispaly the result in a Debug Window...
    
    ' BS2 Pin 0 (PsxAtt) hooked up to PS2 Pad pin 6 via 220 Ohm.
    ' BS2 Pin 1 (PsxClk) hooked up to PS2 Pad pin 7 via 220 Ohm.
    ' BS2 Pin 2 (PsxCmd) hooked up to PS2 Pad pin 2 via 220 Ohm.
    ' Vss to PS2 Pad pin 4.
    
    ' When PsxAtt goes low, shift in bits from PsxCmd on the low edge on PsxClk.
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    
    PsxAtt          PIN     0             ' Make them inputs...
    PsxClk          PIN     1
    PsxCmd          PIN     2
    
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    
    idx             VAR     Nib           ' Loop counter
    psxIn           VAR     Byte          ' byte snooped from controller
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    
    DEBUG CLS
    
    INPUT           PsxAtt
    INPUT           PsxClk
    INPUT           PsxCmd
    
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    
    Main:
      DO : LOOP UNTIL (PsxAtt = 0)       ' Wait for attention.
    
      DEBUG "Attn Low...", CR
      FOR idx = 0  TO 7                  ' Shift in 8 bits.
        DO : LOOP UNTIL (PsxClk = 0)     ' Wait for Clock to go low...
        PsxIn = PsxIn << 1               ' Shift bits one position to left
        psxIn = psxIn | PsxCmd           ' Add Cmd bit that we try to snoop on...
        DO : LOOP UNTIL (PsxClk = 1)     ' Wait for Clock to go Hi so we can shift in next byte...
      NEXT
    
      DEBUG "PsxIn: ", HEX PsxIn, CR       ' Display result
    
      DO : LOOP UNTIL (PsxAtt = 1)         ' Wait for Att to go low, ignore extra bytes...
      DEBUG "Attn Hi...", CR
    GOTO main
    
    END
    
    
Sign In or Register to comment.