PS2 Wireless Gamepad works with BS2 - Heres how
TechnoRobbo
Posts: 323
Wireless requires a stricter timing. The Ti timing of "shiftout" command·is too long it needs to be 4 microseconds not 46 microseconds as listed in the help file.
Here have fun :
' {$STAMP BS2}
' {$PBASIC 2.5}
· psxThumbL VAR Byte ' left thumb buttons
· psxThumbR VAR Byte ' right thumb buttons
· 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
· idx VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· DEBUG HOME, BIN8 psxThumbL," ",BIN8 psxThumbR," ",CR'HEX2 psxID," ",HEX2 psxSta,CR
··· DEBUG "psxJoyRX = ",DEC3· psxJoyRX ,CR
··· DEBUG "psxJoyRY = ",DEC3· psxJoyRY ,CR
··· DEBUG "psxJoyLX = ",DEC3· psxJoyLX ,CR
··· DEBUG "psxJoyLY = ",DEC3· psxJoyLY ,CR
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:' This routine REQUIRES inverted clock signal from
··· DIR10=1
··· DIR11=0
··· LOW PsxClk
··· LOW PsxAtt
····· 'GOTO test
······ 'request data
····· tmpout=$01
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
····· tmpout=$42
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
····· tmpout=$00
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
······ FOR idx=0 TO 7
······· psxThumbL.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxThumbR.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyRX.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyRY.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyLX.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyLY.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
··· HIGH PsxAtt
·· RETURN
END
Here have fun :
' {$STAMP BS2}
' {$PBASIC 2.5}
· psxThumbL VAR Byte ' left thumb buttons
· psxThumbR VAR Byte ' right thumb buttons
· 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
· idx VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· DEBUG HOME, BIN8 psxThumbL," ",BIN8 psxThumbR," ",CR'HEX2 psxID," ",HEX2 psxSta,CR
··· DEBUG "psxJoyRX = ",DEC3· psxJoyRX ,CR
··· DEBUG "psxJoyRY = ",DEC3· psxJoyRY ,CR
··· DEBUG "psxJoyLX = ",DEC3· psxJoyLX ,CR
··· DEBUG "psxJoyLY = ",DEC3· psxJoyLY ,CR
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:' This routine REQUIRES inverted clock signal from
··· DIR10=1
··· DIR11=0
··· LOW PsxClk
··· LOW PsxAtt
····· 'GOTO test
······ 'request data
····· tmpout=$01
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
····· tmpout=$42
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
····· tmpout=$00
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT· PsxClk,2
····· NEXT
····· PAUSE 1
······ FOR idx=0 TO 7
······· psxThumbL.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxThumbR.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyRX.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyRY.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyLX.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
····· FOR idx=0 TO 7
······· psxJoyLY.LOWBIT(idx)=PsxDat
······· PULSOUT· PsxClk,1
····· NEXT
··· HIGH PsxAtt
·· RETURN
END
Comments
Here's a modified version that doesn't use the transistor in the circuit to invert the clock.
' {$STAMP BS2}
' {$PBASIC 2.5}
· buff VAR Byte(6)
· idx VAR Nib
· idy VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· DEBUG HOME, BIN8 buff(0)," ",BIN8 buff(1)," ",CR'HEX2 psxID," ",HEX2 psxSta,CR
··· DEBUG "psxJoyRX = ",DEC3· buff(2) ,CR
··· DEBUG "psxJoyRY = ",DEC3· buff(3) ,CR
··· DEBUG "psxJoyLX = ",DEC3· buff(4) ,CR
··· DEBUG "psxJoyLY = ",DEC3· buff(5),CR
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:
··· DIR10=1
··· DIR11=0
··· High PsxClk ' Change this to low if you use the transistor
··· LOW PsxAtt
··· FOR idy = 0 TO 2
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT PsxClk,2
····· NEXT
··· NEXT
··· FOR idy = 0 TO 5
····· FOR idx=0 TO 7
······· tmpout.LOWBIT(idx)=PsxDat
······· PULSOUT PsxClk,2
····· NEXT
····· Buff(idy)=tmpout
··· NEXT
··· HIGH PsxAtt
·· RETURN
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
In the attached image is the standard interface by Jon Williams that appeared in the Nuts & Volts article.
Note it has a transistor on the clock pin - don't need it.
The following section of the second program is the key.
···· High PsxClk ' Change this to low if you use the transistor
if you wish to use the transistor in the diagram change it to this.
···· Low PsxClk ' Change this to high if you omit the transistor.
Jon Williams does recommend that a 220 ohm resistor be used in an output to protect your BS2.
the second attachment below shows that connection
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
Fake EDIT: nvm, im retarded. i just read thru the code, now i understand how to hook it up.
im going to change the pins thouhg. that way i can have a remote bot, then push x for autonomous, then triangle to return to remote.
and i dont see anything in your code that pulses the servos. i have everything hooked up (except +9) and it recognizes the controller and stuff, but the servos wont move
when i plug +9(grey) into a 9v source, the right vibrator in the contoler turns on (only when i push the analog button)
Post Edited (HavoKane) : 8/5/2006 12:59:47 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
psxJoyRX = 255
psxJoyRY = 255
psxJoyLX = 255
psxJoyLY = 255
that shows up in the debug window. no buttons do anything. i tried it on 2 different contollers
' {$STAMP BS2}
' {$PBASIC 2.5}
· buff VAR Byte(6)
· idx VAR Nib
· idy VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 9
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
· Servo· PIN·12··· 'assuming it is on pin 12
· ServoPos ·VAR· WORD
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
····ServoPos··=buff(4) *·2 + 500
··· ServoPos··=ServoPos··MIN·500
··· ServoPos··=ServoPos··MAX·1000
··· PULSOUT Servo,·ServoPos
··· PAUSE·10 ' reduce or remove this pause if servo acts erratic
··LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:
··· DIR10=1
··· DIR11=0
··· High PsxClk ' Change this to low if you use the transistor
··· LOW PsxAtt
··· FOR idy = 0 TO 2
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT PsxClk,2
····· NEXT
··· NEXT
··· FOR idy = 0 TO 5
····· FOR idx=0 TO 7
······· tmpout.LOWBIT(idx)=PsxDat
······· PULSOUT PsxClk,2
····· NEXT
····· Buff(idy)=tmpout
··· NEXT
··· HIGH PsxAtt
·· RETURN
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
Oh and of course your code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
Post Edited (TechnoRobbo) : 8/5/2006 1:35:26 AM GMT
i did.
sorry, i dont have a camera, so i drew a schematic in mspaint. lo
the code is yours, copy + paste
Post Edited (HavoKane) : 8/5/2006 1:45:21 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
i have the parallax modified servos (continous)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
' {$PBASIC 2.5}
buff VAR Byte(6)
idx VAR Nib
idy VAR Nib
tmpout VAR Byte
PsxAtt PIN 9
PsxClk PIN 8
PsxCmd PIN 10
PsxDat PIN 11
Servo PIN 12 'assuming it is on pin 12
ServoPos VAR WORD
MAIN:
DO
GOSUB Get_PSX_Buttons
ServoPos =buff(4) * 2 + 500
ServoPos =ServoPos MIN 500
ServoPos =ServoPos MAX 1000
PULSOUT Servo, ServoPos
PAUSE 10 ' reduce or remove this pause if servo acts erratic
LOOP
'
[noparse][[/noparse] Subroutines ]
Get_PSX_Buttons:
DIR10=1
DIR11=0
High PsxClk ' Change this to low if you use the transistor
LOW PsxAtt
FOR idy = 0 TO 2
LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
FOR idx=0 TO 7
PsxCmd=tmpout.LOWBIT(idx)
PULSOUT PsxClk,2
NEXT
NEXT
FOR idy = 0 TO 5
FOR idx=0 TO 7
tmpout.LOWBIT(idx)=PsxDat
PULSOUT PsxClk,2
NEXT
Buff(idy)=tmpout
NEXT
HIGH PsxAtt
RETURN
END
the servo just sits there and spins. the controller does nothing
i have a wire controller plugged in becuase the wireless one was too expensive. does your code not work with wired controllers?
Post Edited (HavoKane) : 8/5/2006 2:14:04 AM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
· buff VAR Byte(6)
· idx VAR Nib
· idy VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 8
· PsxClk PIN 9
· PsxCmd PIN 10
· PsxDat PIN 11
· Servo· PIN 12··· 'assuming it is on pin 12
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· IF buff(5)<80 THEN
····· PULSOUT Servo,1000
··· ELSEIF buff(5)>160 THEN
····· PULSOUT Servo, 500
··· else
····· PULSOUT Servo, 750 ' or whatever your stop position is
··· endif
··· PAUSE 10 ' reduce or remove this pause if servo acts erratic
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:
··· DIR10=1
··· DIR11=0
··· HIGH PsxClk ' Change this to low if you use the transistor
··· LOW PsxAtt
··· FOR idy = 0 TO 2
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
····· FOR idx=0 TO 7
······· PsxCmd=tmpout.LOWBIT(idx)
······· PULSOUT PsxClk,2
····· NEXT
··· NEXT
··· FOR idy = 0 TO 5
····· FOR idx=0 TO 7
······· tmpout.LOWBIT(idx)=PsxDat
······· PULSOUT PsxClk,2
····· NEXT
····· Buff(idy)=tmpout
··· NEXT
··· HIGH PsxAtt
·· RETURN
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
and the servo movement is kinda erratic. even if i cahnge/remove the pause statement. and the servos doesnt stop moving if i let go of the joystick.
Post Edited (HavoKane) : 8/5/2006 2:27:57 AM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
· buff VAR Byte(6)
· idx VAR Nib
· idy VAR Nib
· tmpout VAR Byte
· PsxAtt PIN 8
· PsxClk PIN 9
· PsxCmd PIN 10
· PsxDat PIN 11
· Servo· PIN 12··· 'assuming it is on pin 12
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· IF buff(5)<80 THEN
····· PULSOUT Servo,1000
··· ELSEIF buff(5)>160 THEN
····· PULSOUT Servo, 500
··· else
····· PULSOUT Servo, 750 '<
Please·Note
··· endif
··· PAUSE 10 ' reduce or remove this pause if servo acts erratic
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:
··· DIR10=1
··· DIR11=0
··· HIGH PsxClk ' Change this to low if you use the transistor
··· LOW PsxAtt
··· FOR idy = 0 TO 2
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
····· FOR idx=0 TO 7
········TOGGLE PsxClk·· ' note the change
······· PsxCmd=tmpout.LOWBIT(idx)
······· TOGGLE PsxClk
····· NEXT
··· NEXT
··· FOR idy = 0 TO 5
····· FOR idx=0 TO 7
······· TOGGLE PsxClk
······· tmpout.LOWBIT(idx)=PsxDat
······· TOGGLE PsxClk
····· NEXT
····· Buff(idy)=tmpout
··· NEXT
··· HIGH PsxAtt
·· RETURN
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
use the Jon williams code (http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf) if your using the transistor it will execute faster.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
the actual amount is 20 but the extra instruction add a delay. - I use the PSC servo controller so I dont have to bother with all that.· Leaves more time for the meat of the program.
http://www.parallax.com/detail.asp?product_id=28023
trust me you wont regret buying it
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
I have tried your code with a wired PS2 controller (logitech). It works fine.
I switched it with a logitech and a madcarz wireless controller. Nothing happens.
I use the schematic with the transistor.
Any suggestions?
michael
2. Note that the 7.6V (commanly referred to as the 9v pin) Green wire Pin 3 has been reported to be necessary on some controllers.· The pelican doesn't need it though.· I can publish the rumble code if someone wants it.
3. also I did not include the code for automatically turning on the analog mode so make sure you do that manually.
Oh what the heck here's the code
·' {$STAMP BS2}
' {$PBASIC 2.5}
'i/o config
· 'BUFF VAR Byte(3)
· PW· VAR Word
· buff VAR Byte(6)
· PsxAtt PIN 9 ' PSX joystick interface
· PsxClk PIN 8
· PsxCmd PIN 10
· PsxDat PIN 11
·'--equates---
· tmpout VAR pw.LOWBYTE
· idx·· VAR pw.NIB2
· idy·· VAR pw.NIB3
· 'inits
··· PAUSE 250 'give controller time to initialize··
··· OUTPUT PsxCmd
··· INPUT PsxDat
··· LOW PsxClk
··· LOW PsxAtt
··· FOR idy = 0 TO 8
····· LOOKUP idy,[noparse][[/noparse]$01,$43,$00,$01,$00,$00,$00,$00,$00],tmpout
····· GOSUB BitSend
··· NEXT
··· HIGH PsxAtt
··· PAUSE 1
··· LOW PsxAtt
··· FOR idy = 0 TO 8
····· LOOKUP idy,[noparse][[/noparse]$01,$44,$00,$01,$03,$00,$00,$00,$00],tmpout
····· GOSUB BitSend
··· NEXT
··· HIGH PsxAtt
··· PAUSE 1
··· LOW PsxAtt
··· FOR idy = 0 TO 8
····· LOOKUP idy,[noparse][[/noparse]$01,$43,$00,$00,$00,$00,$00,$00,$00],tmpout
····· GOSUB BitSend
··· NEXT
··· HIGH PsxAtt
··· PAUSE 1
· '[noparse][[/noparse]$01,$43,$00,$01,$00,$00,$00,$00,$00]'config mode enter
· '[noparse][[/noparse]$01,$44,$00,$01,$03,$00,$00,$00,$00]'set analog
· '[noparse][[/noparse]$01,$4D,$00,$00,$01,$ff,$ff,$ff,$ff]'Vibration Enable
· '[noparse][[/noparse]$01,$43,$00,$00,$00,$00,$00,$00,$00],'config mode exit
· 'program
· MAIN:
· DO
··· GOSUB Get_PSX_Buttons
··· DEBUG HOME,BIN8 buff(0)," ",BIN8 buff(1) ,CR
··· DEBUG DEC3 buff(2)," ",DEC3 buff(3) ,CR
··· DEBUG DEC3 buff(4)," ",DEC3 buff(5) ,CR
· LOOP
'
[noparse][[/noparse] Subroutines ]
· Get_PSX_Buttons:' This routine REQUIRES inverted clock signal from
··· OUTPUT PsxCmd
··· INPUT PsxDat
··· LOW PsxClk
··· LOW PsxAtt
··· FOR idy = 0 TO 2
····· LOOKUP idy,[noparse][[/noparse]$01,$42,$00],tmpout
····· GOSUB BitSend
··· NEXT
··· FOR idy = 0 TO 5
····· FOR idx=0 TO 7
······· tmpout.LOWBIT(idx)=PsxDat
······· PULSOUT PsxClk,2
····· NEXT
····· buff(idy)=tmpout
··· NEXT
··· HIGH PsxAtt
·· RETURN
· BitSend:
··· FOR idx=0 TO 7
······ PsxCmd=tmpout.LOWBIT(idx)
······ PULSOUT PsxClk,2
···· NEXT
··· RETURN
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
Post Edited (TechnoRobbo) : 8/6/2006 8:07:22 AM GMT