Putting robotics at your service™

Free shipping on orders over $200

PS2 Controller Not Reading Properly

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 9 posts ]

User avatar
Novice ( offline )
Posts: 80
Posted: 2010-01-09 16:29 
I just got a Lynxmotion wireless controller with the wire harness but am having problems getting it to work right. I'm using a Bot Board II with a Basic Atom Pro 28 and tried following the tutorial but the terminal is filled with only readings of 255 for every function every time except the mode reading which is 7F? The lights on the receiver both stay solid which seems to indicate that a connection is being made. Here is the code I'm using with ATOM-Pro IDE 08.0.1.7:

Code:
;PS2 Controller / BotBoard II
DAT    con P12
CMD    con P13
SEL    con P14
CLK    con P15
PadMode   con   s79
;-----------------------------

index var byte
temp var byte(19)
mode var byte
LastButton   var   byte
Small_Motor var byte
Large_Motor var byte

;PS2 controller
high CLK
LastButton(0) = 255
LastButton(1) = 255

sound 9,[50\4000,40\3500,40\3200,50\3900]

main:

gosub PS2INPUT

PS2INPUT:

  low SEL
  shiftout CMD,CLK,FASTLSBPRE,[$1\8]
  shiftin DAT,CLK,FASTLSBPOST,[Mode\8]
  high SEL
  pause 1

  low SEL
  shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8]   
   shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(8)\8, |
   temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(18)\8]
  high SEL
  pause 1   

;serout s_out,i14400,[dec DS2Mode, 13]
Mode = Mode & 0x7F
  if Mode <> PadMode THEN
      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
      high SEL
      pause 100

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
      high SEL
      pause 1

   endif


;-----------Basic Micro IDE terminal----------
; sending carriage return (CR = 13) and the PS2 mode(hex) to the PC
serout S_OUT,i57600,[13, hex2 mode\2] ; Basic Micro Pro IDE <= 08.0.1.7

for index = 1 to 18 ; temp(0) contains a dummy variable so we don't send it to the PC
; sending all the data to the PC
serout S_OUT,i57600,[" ", dec3 temp(index)\3] ; Basic Micro Pro IDE <= 08.0.1.7
next
;-----------------------------

goto main

_________________
Dan Toborowski
President
Central Illinois Robotics Club
http://www.circpeoria.org
http://sites.google.com/site/teamtobor/


Rookie ( offline )
Posts: 28
Posted: 2010-01-11 12:02 
Here's the code that I use. This is a code extract and I attempted to add some of the library code so it will compile, but I am at work so I cannot say it will run. This is extracted from my live code base and I use the PS2C controller all the time for my robot so I know the code is good.
I am using a GameStop branded wireless controller but any should work.

Code:

cTRUE                        con   1
cFALSE                        con   0

cDISPLAY_I2CBUFFER               con 1
cDISPLAY_BUFFER                  con 2
cDISPLAY_MESSAGE               con 3

cMESSAGE_SIZE                  con 128   
cBUFFER_SIZE                  con 128
g_wMessageCount                  var word
g_sMessage                     var   byte (cMESSAGE_SIZE)
g_sBuffer                     var   byte (cBUFFER_SIZE)

; The PS2C device is a PS2 Controller

g_wPS2CButtons            var word                     ; PS2 controller buttons bit map
g_wPS2CJoystickLeftX      var byte                     ; PS2 controller left joystick x axis
g_wPS2CJoystickLeftY      var byte                     ; PS2 controller left joystick y axis
g_wPS2CJoystickRightX      var byte                     ; PS2 controller right joystick x axis
g_wPS2CJoystickRightY      var byte                     ; PS2 controller right joystick y axis

cPIN_PS2C_DAT                  con   P16      ; PS2 controller data
cPIN_PS2C_CMD                  con   P17      ; PS2 controller command
cPIN_PS2C_ATT                  con   P18      ; PS2 controller attention
cPIN_PS2C_CLK                  con   P19      ; PS2 controller clock

cPS2C_BUTTONS_BIT_SQUARE         con 0
cPS2C_BUTTONS_BIT_CROSS            con 1
cPS2C_BUTTONS_BIT_CIRCLE         con 2
cPS2C_BUTTONS_BIT_TRIANGLE         con 3
cPS2C_BUTTONS_BIT_R1            con 4
cPS2C_BUTTONS_BIT_L1            con 5
cPS2C_BUTTONS_BIT_R2            con 6
cPS2C_BUTTONS_BIT_L2            con 7
cPS2C_BUTTONS_BIT_LEFT            con 8
cPS2C_BUTTONS_BIT_DOWN            con 9
cPS2C_BUTTONS_BIT_RIGHT            con 10
cPS2C_BUTTONS_BIT_UP            con 11
cPS2C_BUTTONS_BIT_START            con 12
cPS2C_BUTTONS_BIT_R3            con 13
cPS2C_BUTTONS_BIT_L3            con 14
cPS2C_BUTTONS_BIT_SELECT         con 15
cPS2C_BUTTONS_BIT_COUNT            con 16

cPS2C_JOYSTICK_RIGHT            con 0
cPS2C_JOYSTICK_LEFT               con 1
cPS2C_JOYSTICK_COUNT            con 2

cPS2C_FEEDBACK_ON               con 255
cPS2C_FEEDBACK_OFF               con 0

cPS2C_CLOCK_DELAY               con 5

cPS2C_CMD_GET_RESPONSE_MODE         con 0x41
cPS2C_CMD_POLL_DATA               con 0x42
cPS2C_CMD_SET_CONFIG_MODE         con 0x43
cPS2C_CMD_SET_MODE               con 0x44
cPS2C_CMD_GET_STATUS            con 0x45
cPS2C_CMD_SET_MOTOR_MAP            con 0x4D
cPS2C_CMD_SET_RESPONSE_MODE         con 0x4F

cPS2C_START                     con 0x01
cPS2C_NOOP                     con   0x00

cPS2C_EXIT_CONFIG               con   0x00
cPS2C_ENTER_CONFIG               con   0x01

cPS2C_MODE_DIGITAL               con   0x00
cPS2C_MODE_ANALOG               con   0x01

cPS2C_MODE_UNLOCKED               con   0x01
cPS2C_MODE_LOCKED               con   0x03

cPS2C_ACK                     con 0x5A

bPS2CReadError                  var byte
bPS2CInit                     var byte

bPS2CPollSmallMotor               var byte
bPS2CPollLargeMotor               var byte

; Get the count of the chars in the message buffer
GetMessageCount
   g_wMessageCount = 0
   while (g_sMessage(g_wMessageCount) <> 0)
      g_wMessageCount = g_wMessageCount + 1
   wend
   return

Display
   gosub GetMessageCount
   serout S_OUT, I38400, [str g_sMessage\g_wMessageCount]
   return

; The Common module supports processing that is common to all Basic Atom projects

bGetBitCount      var byte
bGetBitBit         var bit
lGetBitUI32Data      var long

p_bGetBitBit      var byte

p_lGetBitData   var long
GetBitUI32 [p_lGetBitData, p_bGetBitBit]
lGetBitUI32Bit      var long
lGetBitUI32Value   var long
   lGetBitUI32Value = 1
   for bGetBitCount=0 to (p_bGetBitBit-1)
      lGetBitUI32Value = (lGetBitUI32Value*2)
   next
   lGetBitUI32Bit = (p_lGetBitData & lGetBitUI32Value)
   if (lGetBitUI32Bit >= 1) then
      bGetBitBit = 1
   else
      bGetBitBit = 0
   endif
   return bGetBitBit

p_wGetBitData   var word
GetBitUI16 [p_wGetBitData, p_bGetBitBit]
   lGetBitUI32Data = p_wGetBitData
   gosub GetBitUI32 [lGetBitUI32Data, p_bGetBitBit], bGetBitBit
   return bGetBitBit

PS2CInitialize
   bPS2CReadError = cFALSE
   bPS2CPollSmallMotor = cPS2C_FEEDBACK_OFF
   bPS2CPollLargeMotor = cPS2C_FEEDBACK_OFF
   bPS2CInit = cTRUE
   high cPIN_PS2C_CLK
   gosub PS2CPoll
   bPS2CInit = cFALSE
   gosub PS2CPoll
   if (bPS2CReadError = cFALSE) then
      gosub PS2CSetMode [cPS2C_MODE_ANALOG, cPS2C_MODE_LOCKED]
      gosub PS2CPoll
   endif
   return

p_bPS2CConfigMode   var byte
PS2CSetConfigMode [p_bPS2CConfigMode]
   g_sBuffer(0) = cPS2C_START, cPS2C_CMD_SET_CONFIG_MODE, cPS2C_NOOP, p_bPS2CConfigMode, cPS2C_NOOP
   gosub PS2CCommand [5, cTRUE]
   return

p_bPS2CModeType   var byte
p_bPS2CModeLock   var byte
PS2CSetMode [p_bPS2CModeType, p_bPS2CModeLock]
   gosub PS2CSetConfigMode [cPS2C_ENTER_CONFIG]
   g_sBuffer(0) = rep cPS2C_NOOP\9
   g_sBuffer(0) = cPS2C_START, cPS2C_CMD_SET_MODE, cPS2C_NOOP, p_bPS2CModeType, p_bPS2CModeLock
   gosub PS2CCommand [9, cTRUE]
   gosub PS2CSetConfigMode [cPS2C_EXIT_CONFIG]
   return

p_bPS2CPollSmallMotor      var byte
p_bPS2CPollLargeMotor      var byte
PS2CSetFeedback [p_bPS2CPollSmallMotor, p_bPS2CPollLargeMotor]
   bPS2CPollSmallMotor = p_bPS2CPollSmallMotor
   bPS2CPollLargeMotor = p_bPS2CPollLargeMotor
   gosub PS2CPoll
   return

PS2CPoll
   bPS2CReadError = cTRUE
   g_sBuffer(0) = rep cPS2C_NOOP\9
   g_sBuffer(0) = cPS2C_START, cPS2C_CMD_POLL_DATA, cPS2C_NOOP, bPS2CPollSmallMotor, bPS2CPollLargeMotor
   gosub PS2CCommand [9, cTRUE]
   if (g_sBuffer (2) = cPS2C_ACK) then
      bPS2CReadError = cFALSE
   else
      if (bPS2CInit = cFALSE) then
         g_sMessage = "PS2C Read Error!", 0
         gosub Display [cDISPLAY_MESSAGE, cTRUE]
      endif
   endif
   if (bPS2CReadError = cFALSE) then
      g_wPS2CButtons.highbyte = g_sBuffer(3)
      g_wPS2CButtons.lowbyte = g_sBuffer(4)
      g_wPS2CJoystickRightX = g_sBuffer(5)
      g_wPS2CJoystickRightY = g_sBuffer(6)
      g_wPS2CJoystickLeftX = g_sBuffer(7)
      g_wPS2CJoystickLeftY = g_sBuffer(8)
      gosub PS2CFixJoysticks
      gosub PS2CShowData
   endif
   high cPIN_PS2C_ATT
   return

PS2CFixJoysticks
   if ((g_wPS2CJoystickRightX <> 0x00) and (g_wPS2CJoystickRightX <> 0xFF)) then
      g_wPS2CJoystickRightX = 127
   endif
   if ((g_wPS2CJoystickRightY <> 0x00) and (g_wPS2CJoystickRightY <> 0xFF)) then
      g_wPS2CJoystickRightY = 127
   endif
   if ((g_wPS2CJoystickLeftX <> 0x00) and (g_wPS2CJoystickLeftX <> 0xFF)) then
      g_wPS2CJoystickLeftX = 127
   endif
   if ((g_wPS2CJoystickLeftY <> 0x00) and (g_wPS2CJoystickLeftY <> 0xFF)) then
      g_wPS2CJoystickLeftY = 127
   endif
   return

p_bPS2CCommandCount      var byte
p_bPS2CCommandAtt      var byte
PS2CCommand [p_bPS2CCommandCount, p_bPS2CCommandAtt]
p_bPS2CCommandLoop      var byte
p_bPS2CCommandLoop2      var byte
p_bPS2CCommandWByte      var byte
p_bPS2CCommandRByte      var byte
   low cPIN_PS2C_ATT
   for p_bPS2CCommandLoop=0 to (p_bPS2CCommandCount-1)
      p_bPS2CCommandRByte = 0
      p_bPS2CCommandWByte = g_sBuffer(p_bPS2CCommandLoop)
      for p_bPS2CCommandLoop2=0 to 7
         if ((p_bPS2CCommandWByte & 0x01)) then
            high cPIN_PS2C_CMD
         else
            low cPIN_PS2C_CMD
         endif
         low cPIN_PS2C_CLK
         pauseus cPS2C_CLOCK_DELAY
         p_bPS2CCommandWByte = (p_bPS2CCommandWByte >> 1)
         p_bPS2CCommandRByte = (p_bPS2CCommandRByte << 1)
         if (IN16) then
            p_bPS2CCommandRByte = (p_bPS2CCommandRByte | 1)
         endif
         high cPIN_PS2C_CLK
         pauseus cPS2C_CLOCK_DELAY
      next
      g_sBuffer (p_bPS2CCommandLoop) = p_bPS2CCommandRByte
   next
   if (p_bPS2CCommandAtt) then
      high cPIN_PS2C_ATT
   endif
   return

PS2CShowData
bPS2CShowDataValue   var long
bPS2CShowDataBit   var byte
bPS2CShowDataCount   var byte
   if (g_wPS2CButtons <> $FFFF) then
      g_sMessage = "PS2C joysticks: ", dec g_wPS2CJoystickLeftX\3, "/", dec g_wPS2CJoystickLeftY\3, "-", dec g_wPS2CJoystickRightX\3, "/", dec g_wPS2CJoystickRightY\3, " buttons: ", hex g_wPS2CButtons\4, 0
      gosub Display [cDISPLAY_MESSAGE, cTRUE]
      bPS2CShowDataValue = g_wPS2CButtons
      for bPS2CShowDataCount = 0 to (cPS2C_BUTTONS_BIT_COUNT-1)
         gosub GetBitUI16 [bPS2CShowDataValue, bPS2CShowDataCount], bPS2CShowDataBit
         if (bPS2CShowDataBit = 0) then
            g_sMessage = " /", 0
            gosub Display [cDISPLAY_MESSAGE, cFALSE]
;            gosub GetLookup [cLOOKUP_FAST, (bPS2CShowDataCount+1), cLOOKUP_PS2CBUTTON_ID_OFFSET]
            gosub Display [cDISPLAY_BUFFER, cFALSE]
         endif
      next
   endif
   return

main
   gosub PS2CInitialize
mainloop
   pause 20
   gosub PS2CPoll
   if (bPS2CReadError) then
      return
   endif
   if (g_wPS2CButtons.Bit2 = 0) then   ; SQUARE
      g_sMessage = "small feedback", 0
      gosub Display [cDISPLAY_MESSAGE, cTRUE]
      gosub PS2CSetFeedback [cPS2C_FEEDBACK_ON, cPS2C_FEEDBACK_OFF]
   endif
   if (g_wPS2CButtons.Bit3 = 0) then   ; X
      g_sMessage = "stop feedback", 0
      gosub Display [cDISPLAY_MESSAGE, cTRUE]
      gosub PS2CSetFeedback [cPS2C_FEEDBACK_OFF, cPS2C_FEEDBACK_OFF]
   endif
   if (g_wPS2CButtons.Bit0 = 0) then   ; O
      g_sMessage = "large feedback", 0
      gosub Display [cDISPLAY_MESSAGE, cTRUE]
      gosub PS2CSetFeedback [cPS2C_FEEDBACK_OFF, cPS2C_FEEDBACK_ON]
   endif
   if (g_wPS2CButtons.Bit1 = 0) then   ; TRIANGLE
      g_sMessage = "both feedback", 0
      gosub Display [cDISPLAY_MESSAGE, cTRUE]
      gosub PS2CSetFeedback [cPS2C_FEEDBACK_ON, cPS2C_FEEDBACK_ON]
   endif
   goto mainloop



User avatar
Guru ( offline )
Posts: 9257
Posted: 2010-01-11 13:04 
tobor wrote:
I just got a Lynxmotion wireless controller with the wire harness but am having problems getting it to work right. I'm using a Bot Board II with a Basic Atom Pro 28 and tried following the tutorial but the terminal is filled with only readings of 255 for every function every time except the mode reading which is 7F? The lights on the receiver both stay solid which seems to indicate that a connection is being made. Here is the code I'm using with ATOM-Pro IDE 08.0.1.7:


There is not much that can go wrong here. The controller and receiver will sync up when power is applied. It will do this even with no Atom installed. The receiver can be installed into the cable upside down if you are not careful. Test them in the game console if available.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


User avatar
Novice ( offline )
Posts: 80
Posted: 2010-01-11 22:38 
I've tried hooking up a wired PS2 controller to the Bot Board II but no luck. I copied the supplied tutorial code exactly but was unable to return anything other than "255" for all outputs using the wireless or wired controller. Can this output provide me with any insight as to where the problem may be? Hardware? Code? The controller?

I decided to try writing my own code but I haven't had any luck with either. Here is the code I'm currently trying to use to read the PS2 controller commands but it doesn't appear to work at all. Should the subroutine "PS2 Input" be filling the array "index" with the proper values for the PS2 controller's commands?

Code:
'-------[ Constants ]------------------------

DAT       con P16         ' define pin assignment for PS2 controller data
CMD       con P17         ' define pin assignment for PS2 controller command
SEL       con P18         ' define pin addignment for PS2 controller select
CLK       con P19
PadMode      con   s79

'-------[ Variables ]--------------------------

index var byte
temp var byte(19)
mode var byte
LastButton   var   byte
Small_Motor var byte
Large_Motor var byte

' -----[ Initialization ]------------------------

;PS2 controller
high CLK
LastButton(0) = 255
LastButton(1) = 255

sound 9,[50\4000,40\3500,40\3200,50\3900]

' -----[ Main Program ]-------------------

main:

goto PS2INPUT

' -----[ Get PS2 Controller Commands ]-------------

PS2INPUT:

;PS2 controller
high CLK

  low SEL
  shiftout CMD,CLK,FASTLSBPRE,[$1\8]
  shiftin DAT,CLK,FASTLSBPOST,[Mode\8]
  high SEL
  pause 1

  low SEL
  shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8]   
   shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8]
  high SEL
  pause 1   

;serout s_out,i14400,[dec DS2Mode, 13]
Mode = Mode & 0x7F
  if Mode <> PadMode THEN
      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
      high SEL
      pause 100

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
      high SEL
      pause 1

      low SEL
      shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
      high SEL
      pause 1

   endif

goto Calculate

Calculate:......

_________________
Dan Toborowski
President
Central Illinois Robotics Club
http://www.circpeoria.org
http://sites.google.com/site/teamtobor/


User avatar
Guru ( offline )
Posts: 4913
Posted: 2010-01-11 23:06 
I am sort-of confussed here.

I believe in your first post you said it was on a BAP on a BB2. In that post I saw a few problems in your code like you doing a gosub of the PS2 code, which had no return, which would sooner or later reset your processor.

In the current program you have the pins defined on P16-P19 instead of the standard P12-P15. Did you move your controller to other pins? If so did you provide a pull-up resistor for the DAT line?

If you have the PS2 in the normal position, do you have the jumpers installed for the LEDS? This can sometime cause problems.

Have you tried the program in the tutorial? http://www.lynxmotion.com/images/html/build034.htm

Kurt


User avatar
Novice ( offline )
Posts: 80
Posted: 2010-01-12 12:55 
Well in one of those acceptable but frustrating moments, I was able to get the controller to correctly output readings. This was achieved after unplugging and plugging everything back in and uploading the tutorial code again. I also swapped the Bot Board II with another just for good measure but the previous board hadn't been giving me any issues until the PS2 controller problem. Of course I could swear that the code is identical to what I've been using all along and I don't think I made any different connections than before.

So I'm glad it all works but frustrated that I didn't learn why I was having problems to begin with. If I happen to find out I'll be sure to share it with the group. Here is the code that successfully worked.

Code:
;-----------Bot Board Selection----------
;PS2 Controller / BotBoard II
DAT con P12
CMD con P13
SEL con P14
CLK con P15
;-----------------------------

index var byte
temp var byte(19)
mode var byte
Small_Motor var byte
Large_Motor var byte

;PS2Init
high CLK

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high SEL
pause 100

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$4D\8,$00\8,$00\8,$01\8,$FF\8,$FF\8,$FF\8,$FF\8] ;VIBRATION_ENABLE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG_MODE_EXIT_DS2_NATIVE
high SEL
pause 1

low SEL
shiftout CMD,CLK,FASTLSBPRE,[$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high SEL
pause 1

main

;-----------PS2 Mode----------
low SEL
; asking "mode" to PS2 controller
shiftout CMD,CLK,FASTLSBPRE,[$1\8]
; reading "mode" from PS2 controller
; 73(hex) is dualshock1 (digital buttons)
; 79(hex) is dualshock2 (analog buttons)
shiftin DAT,CLK,FASTLSBPOST,[mode\8]
high SEL
;-----------------------------

pause 1

;-----------PS2 Data----------
low SEL
; asking data to PS2 controller
shiftout CMD,CLK,FASTLSBPRE,[$1\8,$42\8]
; reading data from controller
; (don't use a "for-next" loop, it's too slow to read PS2 data)
shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(8)\8, |
temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(18)\8]
high SEL
;-----------------------------

pause 1

;-----------Basic Micro IDE terminal----------
; sending carriage return (CR = 13) and the PS2 mode(hex) to the PC
serout S_OUT,i57600,[13, hex2 mode\2] ; Basic Micro Pro IDE <= 08.0.1.7

for index = 1 to 18 ; temp(0) contains a dummy variable so we don't send it to the PC
; sending all the data to the PC
serout S_OUT,i57600,[" ", dec3 temp(index)\3] ; Basic Micro Pro IDE <= 08.0.1.7
next
;-----------------------------

goto main


If anyone's curious, I'll be using this PS2 controller for a mecanum wheel robot. The math behind getting it to work is a little complicated but I'll post some project updates and sample code once I get it working.

_________________
Dan Toborowski
President
Central Illinois Robotics Club
http://www.circpeoria.org
http://sites.google.com/site/teamtobor/


User avatar
Guru ( offline )
Posts: 4125
Posted: 2010-01-12 15:28 
If you have the time, it's considered good practice to put stuff back one part at a time, and determine exactly what was causing the failure.

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Expert ( offline )
Posts: 644
Posted: 2010-01-13 17:06 
Thanks. I just got this same hardware, and the program works for me.


User avatar
Guru ( offline )
Posts: 4125
Posted: 2010-01-13 17:25 
glad to hear it!

Alan KM6VV

Adam wrote:
Thanks. I just got this same hardware, and the program works for me.

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


 

cron
All times are UTC - 5 hours [ DST ]. It is currently 2014-10-25 13:26
Feedback Form
Feedback Form