Playstation Controller Wired (PS2)
rough_wood
Posts: 61
I am new enough to this that I dont know if there is a difference between PS2 and PS1 controllers. For clarity I have been using a stock PS2 controller.
Using the program by Jon Williams, I chopped it up to try to make it smaller and quicker. This is my first night tinkering with it, so it isnt near done.
I am trying to use it to control a robot (which I dont have yet so I just use servos) kind of like in the article. Problem is the article doesnt really go into driving motion. Here is my version, which leaves the servo a little choppy when moving, but doesnt constantly stutter back and forth when the joystick is still. I am guessing this is because there are only 256 positions on the joystick, while moving over a range of 500 for the servo's range of motion in steps of 2. Here is what text I have in the editor: (BTW like i said this is my first program so dont risk damaging your system by just copying my well intended text, the way it is, it might be damaging the servo until the analog LED is on, but I THINK the servo is just sitting at 1010.)
' {$STAMP BS2}
' {$PBASIC 2.5}
' Based on Jon Williams program
PsxAtt PIN 8
PsxClk PIN 9
PsxCmd PIN 10
PsxDat PIN 11
Servo· PIN 15
Direct CON 0
ClockMode CON Direct
idx VAR Nib
psxOut VAR Byte
psxIn VAR Byte
psxID VAR Byte
psxThumbL VAR Byte
psxThumbR VAR Byte
psxStatus VAR Byte
psxJoyRX VAR Byte
psxJoyRY VAR Byte
psxJoyLX VAR Byte
psxJoyLY VAR Byte
duration VAR Word
HIGH PsxAtt
OUTPUT PsxCmd
PsxClk = ~ClockMode
OUTPUT PsxClk
DO
· GOSUB Get_PSX_Packet
· DEBUG HOME, BIN8 psxThumbL, " ", BIN8 psxThumbR, " "
· DEBUG DEC3 psxJoyLX, " ", DEC3 psxJoyLY, " ",
········DEC3 psxJoyRX, " ", DEC3 psxJoyRY, CR
duration = psxJoyLX
duration = duration */ 512
duration = duration + 500
DEBUG DEC4 duration, CR
LOOP
Get_PSX_Packet:
·LOW PsxAtt
·psxOut = $01 : GOSUB PSX_TxRx
·psxOut = $42 : GOSUB PSX_TxRx
·psxId = psxIn
·psxOut = $00 : GOSUB PSX_TxRx
·psxStatus = psxIn
·GOSUB PSX_TxRx : psxThumbL = psxIn
·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
·RETURN
PSX_TxRx:
PULSOUT 15, duration
·FOR idx = 0 TO 7
· PsxCmd = psxOut.LOWBIT(idx)
· PsxClk = ClockMode
· psxIn.LOWBIT(idx) = PsxDat
· PsxClk = ~ClockMode
·NEXT
·RETURN
Note mainly the location of the pulsout command, it is in the PSX_TxRx, outside the for-next While <8. I figured putting it inside the for-next it'd need pauses and would likely have a poor effect on reaction time etc. Where it is seems to get plenty of hits since its link seems to be pointed to regularly in the Get_PSX_Packet. Does anyone have any pointers on how to get the rotation to smooth out while keeping or improving on its steadyness once at its proper radial?
Using the program by Jon Williams, I chopped it up to try to make it smaller and quicker. This is my first night tinkering with it, so it isnt near done.
I am trying to use it to control a robot (which I dont have yet so I just use servos) kind of like in the article. Problem is the article doesnt really go into driving motion. Here is my version, which leaves the servo a little choppy when moving, but doesnt constantly stutter back and forth when the joystick is still. I am guessing this is because there are only 256 positions on the joystick, while moving over a range of 500 for the servo's range of motion in steps of 2. Here is what text I have in the editor: (BTW like i said this is my first program so dont risk damaging your system by just copying my well intended text, the way it is, it might be damaging the servo until the analog LED is on, but I THINK the servo is just sitting at 1010.)
' {$STAMP BS2}
' {$PBASIC 2.5}
' Based on Jon Williams program
PsxAtt PIN 8
PsxClk PIN 9
PsxCmd PIN 10
PsxDat PIN 11
Servo· PIN 15
Direct CON 0
ClockMode CON Direct
idx VAR Nib
psxOut VAR Byte
psxIn VAR Byte
psxID VAR Byte
psxThumbL VAR Byte
psxThumbR VAR Byte
psxStatus VAR Byte
psxJoyRX VAR Byte
psxJoyRY VAR Byte
psxJoyLX VAR Byte
psxJoyLY VAR Byte
duration VAR Word
HIGH PsxAtt
OUTPUT PsxCmd
PsxClk = ~ClockMode
OUTPUT PsxClk
DO
· GOSUB Get_PSX_Packet
· DEBUG HOME, BIN8 psxThumbL, " ", BIN8 psxThumbR, " "
· DEBUG DEC3 psxJoyLX, " ", DEC3 psxJoyLY, " ",
········DEC3 psxJoyRX, " ", DEC3 psxJoyRY, CR
duration = psxJoyLX
duration = duration */ 512
duration = duration + 500
DEBUG DEC4 duration, CR
LOOP
Get_PSX_Packet:
·LOW PsxAtt
·psxOut = $01 : GOSUB PSX_TxRx
·psxOut = $42 : GOSUB PSX_TxRx
·psxId = psxIn
·psxOut = $00 : GOSUB PSX_TxRx
·psxStatus = psxIn
·GOSUB PSX_TxRx : psxThumbL = psxIn
·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
·RETURN
PSX_TxRx:
PULSOUT 15, duration
·FOR idx = 0 TO 7
· PsxCmd = psxOut.LOWBIT(idx)
· PsxClk = ClockMode
· psxIn.LOWBIT(idx) = PsxDat
· PsxClk = ~ClockMode
·NEXT
·RETURN
Note mainly the location of the pulsout command, it is in the PSX_TxRx, outside the for-next While <8. I figured putting it inside the for-next it'd need pauses and would likely have a poor effect on reaction time etc. Where it is seems to get plenty of hits since its link seems to be pointed to regularly in the Get_PSX_Packet. Does anyone have any pointers on how to get the rotation to smooth out while keeping or improving on its steadyness once at its proper radial?
Comments
A friend had a broken PS2, I tore it apart, kept many things including the controller ports.
I pried the circuit board off the plasic part which can be seen when no controller is plugged in.
The little sheet metal curled blank·female pluge remained with the circuit board, I just desoldered.
I soldered on 3 inch insulated 22 guage wires, then wrapped a little electric tape around the exposed metal.
Just slide them onto the pins in the controllers plug, then into the breadboard. Not a hard connection, but good for prototyping I figure.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
GOSUB PSX_TxRx : psxThumbL = psxIn
·GOSUB PSX_TxRx : psxThumbR = psxIn
I need to trick it into thinking it already sent those bytes...
I think the best you going to do -- speed-wise -- that just gives you the joystick data is this:
Note that this ignores the "ready" byte from the controller, so there's no way to tell if the joystick values are valid.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
' {$STAMP BS2}
' {$PBASIC 2.5}
' Based on Jon Williams program
PsxAtt PIN 8
PsxClk PIN 9
PsxCmd PIN 10
PsxDat PIN 11
Servo· PIN 15
Direct CON 0
ClockMode CON Direct
idx VAR Nib
psxOut VAR Byte
psxIn VAR Byte
psxID VAR Byte
psxStatus VAR Byte
psxJoyRX VAR Byte
duration VAR Word
HIGH PsxAtt
OUTPUT PsxCmd
PsxClk = ~ClockMode
OUTPUT PsxClk
DO
· GOSUB Get_Joysticks_Fast
· DEBUG HOME, DEC3 psxJoyRX, CR
duration = psxJoyRX
duration = duration */ 512
duration = duration + 500
DEBUG DEC4 duration, CR
PULSOUT servo, duration
LOOP
Get_Joysticks_Fast:
· LOW PsxAtt··································· ' select controller
· SHIFTOUT PsxCmd, PsxClk, LSBFIRST, [noparse][[/noparse]$01, $42] ' send "start"
· SHIFTIN PsxDat, PsxClk, LSBPOST,
··· [noparse][[/noparse]psxJoyRX, psxJoyRX, psxJoyRX]
· FOR idx = 0 TO 7
· PsxCmd = psxOut.LOWBIT(idx)
· PsxClk = ClockMode
· psxIn.LOWBIT(idx) = PsxDat
· PsxClk = ~ClockMode
·NEXT
· psxJoyRX = psxIn
· HIGH PsxAtt································ ' deselect controller
· RETURN
It probably wouldnt be too tough to make a small vehicle with front wheels on 1 servo, which when turned just rotates the whole axis, horrible steering geometry but who cares. Then on the psxJoyRy you could put on a motor that would move it forward and back (I think you would need an H-Bridge for reverse) without really compomising the steering that much. Skid steer would be easy by changing to Y's. I am pretty pleased with it. I still dont have an application for it but at least I am finally understanding some of the basics behind using microcontrollers. Well off to rent "Napolean Dynamite" which I hear is more stupid-funny than "Dumb and Dumber". Again thanks for helping get my feet on the ground Jon.