PS2/Xbox (360)/Gamecube controller
I've seen guides on how to do this for the basic stamp, but what about the Javelin? Anyone ever connect a video game controller to their javelin? (and can share their code here)? I just wanted to check in case I could save myself a couple hours of work.
Edit: 2-11-06 Scroll down about 8 posts to see the code and results for hooking up a PS2 controller.
Post Edited (bulkhead) : 2/12/2006 7:28:38 AM GMT
Edit: 2-11-06 Scroll down about 8 posts to see the code and results for hooking up a PS2 controller.
Post Edited (bulkhead) : 2/12/2006 7:28:38 AM GMT
Comments
http://forums.parallax.com/showthread.php?p=552280
In that thread, theres a link to the Nuts & Volts article which contains a program (in basic) for wiring up a ps2 controller
there---> www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf
Could anyone translate that program to java? Would it work if it were translated? or is the Javelin different from the bs2?
If I'm correct, the best way to go about this would be to create a class, psxController, that would be used like this:
Next, should I use shiftIn and shiftOut or a Uart?
Store files in folder %PATH%\lib\stamp\peripheral\gamecontrollers\playstation\
The methods in psx class and main() are copied from the article (with namechanges)
regards peter
However, I'm still not quite sure how this works, exactly.
With what values do I compare char JoyXY and char ThumbL to know whether the button is pushed down or not? Do I find these values by experimentation through the debug message window?
Also, could you explain what this line does:
I don't quite understand what this line is doing, or what printF() does.
Thanks.
what it means or what it is supposed to do.
eg.
Format.printf("%3d·",myPsx.JoyLX);
does the same as
debug DEC3 JoyLX
and
Format.printf("%08b·",myPsx.ThumbL);
displays the value of ThumbL as a binary digit string (value 12 is printed as 00001100)
and
"%02x" is used to display a value in 2 hexdigits (with leading 0 if value < 16)
Study the article to find out why things are done the way they are done.
regards peter
·
showing the buttons and joysticks.
The ThumbR and ThumbL variables are bitmasks
for the available buttons.
regards peter
Get_PSX_Packet() works, but Get_PSX_Packet_Fast() does not. The second method retrieves the ID ok, so I assume that shiftOut works fine, but it seems the shiftIn's aren't working because I don't get any of the other data. I have yet to have a controller work using the "faster" method, but the slow one works good enough for my needs. Yes I did invert the clock signal and changed the code to match it.
Another strange issue that, I don't know if it's the code in the "psx.java," the Javelin stamp, or just my strange luck, is the fact that only a few controllers I have tested have worked. I have an original dual shock Sony brand controller, and it does not work at all (not even ID is retrieved), but this may be because it's pretty old. Next, I have a brand new Pelican wireless controller that reads the ID (it's a different # than the wired controllers) but cannot read any other information. I guess wireless controllers do work differently than wired ones. The two controllers that I have had success with are a clone of the Sony dualshock controller, and a ddr pad (non-analog) which work perfectly (both joysticks work fully).
My wiring for the controllers is EXACTLY like the one in the Nuts and Volts article, and I have my javelin hooked up to a 6.0V battery. The controllers get their power from the "Vdd" line from the Javelin.
If anyone has any ideas or solutions to fix these issues, I would greatly appreciate it. Overall, I'm content with the results of this endeavor, and am posting my experiences for the benefit of others who choose to undertake this project. My next step in improving control would probably be to use a bs2 (OEM) to handle the communication with the PS2 controller, and use a Uart on the Javelin to recieve the data from the bs2, but that's a project for later...
Edit: Almost forgot, here is my slightly modified code(I call it the "psxCont" class to distinguish it from the original "psx" class). All the changes are at the bottom of the code. I just added a lot of boolean methods, which allow the "psxCont" to be used like an object. You can do myPsx.circle() to see if the controller's circle button is depressed, or myPsx.analogOn() to see if it's in analog mode. Just some little things, but they make it easier to use (at least for me).
Post Edited (bulkhead) : 2/12/2006 7:41:07 AM GMT
The Get_PSX_Packet() uses direct mode (controller connects via resistor to javelin).
See the N&V article how to support both modes.
You can make the clockMode a constructor argument. That allows you to set
the initial clockMode from your main program.
The wireless ps2 controllers are different. See this thread.
http://forums.parallax.com/showthread.php?p=569560
regards peter
·
bittest() does not need to be defined static (but it may in this case).
regards peter
Anyways I think the reason it works now is because when Get_PSX_Packet() is called, it uses the manual data transfer function PSX_TxRx() to get all the bytes. When I run Get_PSX_Packet_Fast() it gets the ID properly because that's done manually with PSX_TxRx(). I assume shiftOut works because the controller responds to the "start byte" that is sent out, since it returns it's ID thereafter. Therefore I suspect something is wrong with the shiftIn method since it doesn't recieve any data for all the other fields.
the Javelin shiftin works slightly different from basic stamp shiftin.
Try the constants
CPU.PRE_CLOCK_MSB
CPU.POST_CLOCK_MSB
CPU.PRE_CLOCK_LSB
CPU.POST_CLOCK_LSB (this is the value I used)
and see if any one of those work.
Also note that Get_PSX_Packet_Fast() should only be called if you
do use the transistor in your circuit. If you use the resistor connection
you should only·use Get_PSX_Packet().
regards peter
If MSb first is selected then the result
will be the data read in on the port. If LSb first is selected then the data is
returned MSb justified and must be shifted right (16-bitCount) bits to
obtain the correct value.
So perhaps the lines should be like
····· Status = (char)(CPU.shiftIn(datPin, clkPin, 8, CPU.POST_CLOCK_LSB)>>>8);
because only 8 bits are shifted in.
regards peter
Here's the updated file
I also updated the Get_PSX_Buttons() accordingly.
regards peter
I'm french and I'm new in this forum.
I write it because I have a problem with PS2 Controller and Javelin Stamp.
I use a standard SONY PS2 DUALSHOCK 2 CONTROLLER with a javelin stamp and the javelin stamp demo board.
I use your classes but I'have always the result "Type = Unknow. No response."
I' think I have correctly connect all the pin.
I tried with different controller but I have always the same result.
Do you think It's not correctly connect? (I dont connect ACK pin )
Can you help me please?
http://www.parallax.com/dl/docs/cols/nv/vol4/col/nv101.pdf
Have you also connected the javelin GND to the joystick GND?
Bulkhead had it running so you can assume the class is ok.
regards peter
Thanks