ps2 controller interface with bs2px
ohVaNiLLaGoRiLLa
Posts: 33
I have recently found this code and instructions for interfacing a PlayStation 2 controller with the basic stamp,http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf , I put the circuit together and it works great with a wired controller! When I try to use a wireless controller with it though my stamp doesn't even recognize the controller. I am using a bs2px for the project I'm working on if that is significant at all. Anyone have any ideas to why a wireless controller does not work?. I took a female PlayStation 2 plug and wired it up so you can just plug the controller into it so plugging a wireless ps2 controller receiver into it should work just fine but it does not. The wireless controller I am trying to use is not a Sony brand controller, it's a generic GameStop wireless controller.
Here is the code I am using
Here is the code I am using
' {$STAMP BS2px} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' This program demonstrates the essential interface between the BASIC ' Stamp and a Sony PlayStation (or compatible) game controller. This ' code assumes that the clock signal is inverted between the Stamp and ' the controller to allow simpler [less sophisticated] interface with ' SHIFTOUT and SHIFTIN. ' ' Note: The interface and portions of code are based on previous work by ' Aaron Dahlen. ' -----[ I/O Definitions ]------------------------------------------------- PsxAtt PIN 8 ' PSX joystick interface PsxClk PIN 9 PsxCmd PIN 10 PsxDat PIN 11 ' -----[ Constants ]------------------------------------------------------- Inverted CON 1 ' inverted clock signal Direct CON 0 ' no inverter in clock line ClockMode CON Inverted ' -----[ Variables ]------------------------------------------------------- idx VAR Nib ' loop counter psxOut VAR Byte ' byte to controller psxIn VAR Byte ' byte from controller ' joystick packet psxID VAR Byte ' controller ID psxThumbL VAR Byte ' left thumb buttons psxThumbR VAR Byte ' right thumb buttons psxStatus VAR Byte ' status ($5A) psxJoyRX VAR Byte ' r joystick - X axis psxJoyRY VAR Byte ' r joystick - Y axis psxJoyLX VAR Byte ' l joystick - X axis psxJoyLY VAR Byte ' l joystick - Y axis ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Setup: HIGH PsxAtt ' deselect PSX controller OUTPUT PsxCmd PsxClk = ~ClockMode ' release clock OUTPUT PsxClk ' make clock an output ' -----[ Program Code ]---------------------------------------------------- Main: DO GOSUB Get_PSX_Packet_Fast ' type and packet DEBUG HOME, "Type = " IF (psxStatus = $5A) THEN DEBUG IHEX2 psxId, " (", IHEX2 psxStatus, ")", CLREOL, CR, CR, BIN8 psxThumbL, " ", BIN8 psxThumbR, " " IF (psxId <> $41) THEN DEBUG DEC3 psxJoyLX, " ", DEC3 psxJoyLY, " ", DEC3 psxJoyRX, " ", DEC3 psxJoyRY ELSE DEBUG CLREOL ENDIF ELSE DEBUG "Unknown. No response.", CR, CLRDN PAUSE 1000 ENDIF PAUSE 100 LOOP END ' -----[ Subroutines ]----------------------------------------------------- ' This routine REQUIRES inverted clock signal from ' Stamp to PSX controller Get_PSX_Buttons: IF (ClockMode = Direct) THEN Get_PSX_Packet ' redirect if not inverted LOW PsxAtt SHIFTOUT PsxCmd, PsxClk, LSBFIRST, [$01, $42] SHIFTIN PsxDat, PsxClk, LSBPOST, [psxThumbL, psxThumbL, psxThumbR] psxId = $41 HIGH PsxAtt RETURN ' This routine manually creates the clock signal, ' so it can be used with a direct (via 220 ohm resistor) ' connection to the clock input ' ' Execution time on BS2 is ~145 ms. Get_PSX_Packet: LOW PsxAtt ' select controller psxOut = $01 : GOSUB PSX_TxRx ' send "start" psxOut = $42 : GOSUB PSX_TxRx ' send "get data" psxId = psxIn ' save controller type psxOut = $00 : GOSUB PSX_TxRx psxStatus = psxIn ' should be $5A ("ready") GOSUB PSX_TxRx : psxThumbL = psxIn ' get PSX data GOSUB PSX_TxRx : psxThumbR = psxIn GOSUB PSX_TxRx : psxJoyRX = psxIn GOSUB PSX_TxRx : psxJoyRY = psxIn GOSUB PSX_TxRx : psxJoyLX = psxIn GOSUB PSX_TxRx : psxJoyLY = psxIn HIGH PsxAtt ' deselect controller RETURN ' Transmit psxOut to, and receive psxIn from the ' PSX controller PSX_TxRx: FOR idx = 0 TO 7 PsxCmd = psxOut.LOWBIT(idx) ' setup command bit PsxClk = ClockMode ' clock the bit psxIn.LOWBIT(idx) = PsxDat ' get data bit PsxClk = ~ClockMode ' release clock NEXT RETURN ' This routine combines manual and built-in shifting ' routines to get the best speed and all valid data. ' ' Execution time on BS2 is ~40 ms. Get_PSX_Packet_Fast: IF (ClockMode = Direct) THEN Get_PSX_Packet ' redirect if not inverted LOW PsxAtt ' select controller SHIFTOUT PsxCmd, PsxClk, LSBFIRST, [$01] ' send "start" psxOut = $42 : GOSUB PSX_TxRx ' send "get data" psxId = psxIn ' save controller type SHIFTIN PsxDat, PsxClk, LSBPOST, [psxStatus] ' should be $5A ("ready") SHIFTIN PsxDat, PsxClk, LSBPOST, [psxThumbL] SHIFTIN PsxDat, PsxClk, LSBPOST, [psxThumbR] SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyRX] SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyRY] SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyLX] GOSUB PSX_TxRx : psxJoyLY = psxIn HIGH PsxAtt ' deselect controller RETURN
Comments
Regards,
TCIII
nv101.pdfPS2 Wireless with BS2.bs2