Lynxmotion PS2 V3 on Basic Atom Pros

As noted in a few threads, Lynxmotion recently released a new version of the PS2 controller (V3), which is not working with programs on the Basic Atom Pros such as the BAP28. Yesterday I received one of these new controllers and have made some changes to some code to make them work here.

There appears to be an issue with how we were first trying to determine if we were in Analog mode by outputting the First 0x1, then reading a byte from the PS2, which would be the version number and then aborting from this PS2 packet and starting again by doing a complete query (0x01 0x042 …) Also the controller did not initialize the same to be able to get the additional information like the pressures on the buttons. But since almost non of our programs use this, I simply avoid that.

Note: These also appear to be more sensitive to having the Buttons/LEDS enabled, so you need to make sure you remove the jumpers. #2 in the diagram on lynxmotion.com/images/html/build151.htm

Also not sure if true on all of these controllers, but on mine, the Start button is very hard to press. I need to use my left thumb nail to be able to press it in far enough to make it register.

So I first hacked up a simple test program that appears to be working OK:

[code];--------------------------------------------------------------------
TRUE con 1
FALSE con 0

;[PS2 Controller]
PS2DAT con P12 ;PS2 Controller DAT (Brown)
PS2CMD con P13 ;PS2 controller CMD (Orange)
PS2SEL con P14 ;PS2 Controller SEL (Blue)
PS2CLK con P15 ;PS2 Controller CLK (White)
PadMode con $79
;--------------------------------------------------------------------

;[Ps2 Controller]
DualShock var Byte(7)
DSLast var Byte(7)
DSChanged var byte
DS2Mode var Byte

PS2Index var byte
i var sword

;--------------------------------------------------------------------
;[REMOTE]

enable
;[INIT]

;PS2 controller
sound P9,[100\5000, 100\4500, 100\4000]

high PS2CLK

pause 100

;====================================================================
;[MAIN]
GOSUB Ps2Init
main:

;Read remote input
GOSUB Ps2Input

DSChanged = FALSE
for i = 0 to 6
	if DualShock(i) <> DSLast(i) then
		DSLast(i) = DualShock(i)
		DSChanged = TRUE
	endif
next
if DSChanged then
	serout s_out, i9600, "DS: ", hex DualShock(0), " ", hex Dualshock(1), " ", hex DualSHock(2),  " ", hex DualShock(3),  " ", hex DualSHock(4), |
				 " ", hex DualShock(5),  " ", hex DualShock(6), 13]  
endif

pause 100

goto main

;--------------------------------------------------------------------
;[PS2Init]
Ps2Init:
input PS2DAT
low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG_MODE_ENTER
high PS2SEL
pause 1

low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET_MODE_AND_LOCK
high PS2SEL
pause 1

; only if you need pressure values
; low PS2SEL
; shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET_DS2_NATIVE_MODE
; high PS2SEL
; pause 1

; low PS2SEL
; shiftout PS2CMD,PS2CLK,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 PS2SEL
; pause 1

low PS2SEL
shiftout PS2CMD,PS2CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG_MODE_EXIT
high PS2SEL
pause 288

return

;--------------------------------------------------------------------
;[PS2Input] reads the input data from the PS2 controller and processes the
;data to the parameters.
Ps2Input:
; Try only straight reads here…
low PS2SEL
shiftout ps2CMD,PS2CLK,FASTLSBPRE,$1\8,$42\8]
shiftin ps2DAT,ps2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
high PS2SEL
pause 1
return
[/code]

I then updated my own copy of the PS2 controller code of the V2.1 Phoenix code base. In this I did similar to the above. But I also added code to work like the Arduino PS2X library and if you have not read from the PS2 in 1.5 seconds it will reinit the PS2 as it likely timed out… I no longer have a Hexapod with a BAP28 or Arc32 on it, so I am hoping it is working OK. I did verify that the code was working (debug output), also clicking on the different buttons, did get me the right types of beeps…

I updated the code up on my Github drop of it: github.com/KurtE/Phoenix_For_BAPS
Note: I did not update the zip files I had up there to include this. If people play around with this new stuff and are happy, I will update the zip files as well. Also I did not update the Lynxmotion 2.0 releases, but the changes should be very similar.

Next up figure out some issues with it on Botboarduino (and Teensy 3.1 but that is a side story)

This code is great, but its missing the code for the head and pinchers of an A-POD. I made some adjustments to it to get the head partially working but I am still having problems with the pinchers opening and closing with L1 and L2 on the PS2 controller. I dont have the pressure sensor hooked up so maybe that is causing a problem.