Shop OBEX P1 Docs P2 Docs Learn Events
PS2/Xbox (360)/Gamecube controller — Parallax Forums

PS2/Xbox (360)/Gamecube controller

bulkheadbulkhead Posts: 405
edited 2007-05-29 17:28 in General Discussion
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

Comments

  • YojimboYojimbo Posts: 40
    edited 2005-12-28 01:49
    I am very interested in this too, I have a wireless controller I was to play with on my bot. I simply don't know how to go about testing which pins on the controller are I/O and which is PWR, GND, etc. Then there's trying to get the wireless card that plugs into the PS2 to interface correctly. This would be a fun project.
  • bulkheadbulkhead Posts: 405
    edited 2005-12-28 04:48
    Ok, after searching google, I found this thread from these forums on using a ps2 controller with the basic stamp 2.

    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?
  • bulkheadbulkhead Posts: 405
    edited 2006-01-21 05:08
    Ok, well, it looks like I'm going to write this myself...but I have a few questions.

    If I'm correct, the best way to go about this would be to create a class, psxController, that would be used like this:

    //in (for example, a robot) class
    psxController myPsx= new psxController(<whatever needs to be initialized>);
    
    if(myPsx.frontJoystick())
        moveForward();
    //etc.
    
    
    



    Next, should I use shiftIn and shiftOut or a Uart?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-21 12:14
    These should get you going.
    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
  • bulkheadbulkhead Posts: 405
    edited 2006-01-21 18:45
    Wow! Much thanks, peter. You probably saved me several hours (or more) of great confusion! It makes much more sense to me now that it's in Java.

    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:
    Format.printf("%3d ",myPsx.JoyLX); Format.printf("%3d ",myPsx.JoyLY);
    


    I don't quite understand what this line is doing, or what printF() does.

    Thanks.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-21 20:29
    Compare the java code to the article's pbasic code and you see
    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
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-01-22 11:00
    Here is a psx controller product description,
    showing the buttons and joysticks.
    The ThumbR and ThumbL variables are bitmasks
    for the available buttons.

    regards peter
  • bulkheadbulkhead Posts: 405
    edited 2006-02-12 07:26
    Well, it's been about three weeks, and I'm posting about my slightly modified code as well as a few minor issues with the "psx.java." Here are my observations from my experience with it.

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-12 07:41
    The Get_PSX_Packet_Fast() probably does not work because clockMode is fixed to Inverted.
    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
    ·
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-12 07:49
    Nice direct button check methods!
    bittest() does not need to be defined static (but it may in this case).
    regards peter
  • bulkheadbulkhead Posts: 405
    edited 2006-02-12 08:01
    I did invert my clock using the transistor as described in the article. Now that I think about it, isn't it not necessary to do so on the Javelin? shiftIn and shiftOut can send inverted clock pulses based on the intial state of the clock pin before the method call.

    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.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-12 08:19
    I translated the pbasic code directly to javelin code. Perhaps
    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-12 12:50
    From the shiftin documentation:
    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
  • bulkheadbulkhead Posts: 405
    edited 2006-02-13 01:18
    Peter, just tried it, it works great! Thanks.

    Here's the updated file
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-02-13 03:08
    Perfect!
    I also updated the Get_PSX_Buttons() accordingly.
    regards peter
  • cybermimilcybermimil Posts: 10
    edited 2007-05-28 19:54
    Hi,
    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?
  • Damien AllenDamien Allen Posts: 103
    edited 2007-05-28 20:06
    Just as a side note, there has been a gamecube controller object written for the propeller which you may be able to adapt to your needs. As far as the xbox360 controller is concerned, I think it is USB HID device which may require the use of a vinculum chip from FTDI to interface to.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-05-28 21:23
    Have you connected it as in this document?
    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
  • cybermimilcybermimil Posts: 10
    edited 2007-05-29 06:14
    In fact I connected directly the Javelin pin to the ps2 cable. I'm not using resistance or transistor. I'll try this evening.
  • cybermimilcybermimil Posts: 10
    edited 2007-05-29 17:28
    OK It work perfectly now...
    Thanks
Sign In or Register to comment.