PS2 contoller and BS2

Hello,

I was looking on the LM site, and I didn’t find any codes for a PS2 controller and a BS2. I will have the mini ABB and the sony playstaton cable for Christmas with the new playstation controller from lynxmotion I hope, but maybe just a normla MadCatz one, and since the holidays aren’t so long, well I thought I should advance with the code. I will probably just start testing with a pan and tilt to see how it works, and then with the BRAT junior and finaly the BRAT. Does anyone have some code to use with the BS2?

Sam, thanks

Here you go. :smiley: Enjoy…
lynxmotion.com/images/html/build036.htm

Cool! I will try to understand teh code later on, I have to go now, bye. thanks :smiley:

Sam

Here is the code I posted in the July 2006 issue of Servo Magazine

I did this with a BS2px, but it works fine with the BS2.
Both Jon’s and Aaron’s articles can be obtained here: servomagazine.com/media-file … Roboto.zip
It is my understanding that Aaron’s article is based on the information that Jim provided to him.

‘
‘ Simple Playstation Demonstration
‘ Based on the code published by Jon Williams in Nuts and Volts
‘ magazine, September 2003

PsxDat PIN 4 ‘ DATA Signal Line
PsxCmd PIN 5 ‘ Command Signal Line
PsxAtt PIN 6 ‘ Attention Signal Line
PsxClk PIN 7 ‘ Clock Signal Line

Inverted CON 1 ‘ Use Inverted Clock Signal
Direct CON 0 ‘ No Inverter in Clock Signal
ClockMode CON Inverted

idx VAR Nib ‘ Loop Counter
psxOut VAR Byte ‘ Command Byte to Controller
psxIn VAR Byte ‘ DATA Byte from Controller

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 ‘ Right Joystick - X axis
psxJoyRY VAR Byte ‘ Right Joystick - Y axis
psxJoyLX VAR Byte ‘ Left Joystick - X axis
psxJoyLY VAR Byte ‘ Left Joystick - Y axis

Main:
OUTPUT PsxCmd ‘ Set Command Signal Line as Output
OUTPUT PsxClk ‘ Set Clock Signal Line as Output
HIGH PsxAtt ‘ Deselect Playstation Controller
DO ‘ Generic Program Loop
GOSUB Get_PSX_Packet_Fast ‘ Read DATA from Controller
GOSUB Debug_Display ‘ Display the Results
LOOP ‘ Infinite Loop
END

‘
‘ This routine combines manual and built-in shifting routines to the
‘ best speed for receiving data from the Playstation controller.
‘
Get_PSX_Packet_Fast:
LOW PsxAtt ‘ Select Controller
SHIFTOUT PsxCmd, PsxClk, LSBFIRST, $01] ‘ Send “Start”
psxOut = $42 : GOSUB PSX_TxRx ‘ Send “Get Data”
psxId = psxIn ‘ Controller Type
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxStatus] ‘ Controller Status
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxThumbL] ‘ Left Thumb Buttons
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxThumbR] ‘ Right Thumb Buttons
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyRX] ‘ Right Joystick X-Axis
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyRY] ‘ Right Joystick Y-Axis
SHIFTIN PsxDat, PsxClk, LSBPOST, [psxJoyLX] ‘ Left Joystick X-Axis
GOSUB PSX_TxRx : psxJoyLY = psxIn ‘ Left Joystick Y-Axis
HIGH PsxAtt ‘ Deselect Controller
RETURN

‘ Manual clock signal line toggling and Transmiting psxOut to
‘ controller and receivin psxIn from the controller
PSX_TxRx:
FOR idx = 0 TO 7 ‘ 8 Bit Loop Counter
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

Debug_Display: ‘ Display the results in a DEBUG Window
DEBUG HOME, “Type = “
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
RETURN

Pete Miles