Shop OBEX P1 Docs P2 Docs Learn Events
PSTWO controller emulation — Parallax Forums

PSTWO controller emulation

computer guycomputer guy Posts: 1,113
edited 2009-01-18 22:52 in Propeller 1
Hi everyone,

I need to get the propeller to emulate a keyboard and a PS2 controller("guitar hero" guitar).
Obviously not at the same time but I want it to be changed via a switch.

What is involved in getting this to happen?


Thank you smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

Guitar Hero controller using the prop (WIP) --> HERE

Post Edited (computer guy) : 1/18/2009 8:28:49 AM GMT
«1

Comments

  • LeonLeon Posts: 7,620
    edited 2008-06-27 13:08
    I built a 'keyboard wedge' once with an AVR. It shouldn't be difficult to find some similar hardware and software on the web and adapt it for the Propeller.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • computer guycomputer guy Posts: 1,113
    edited 2008-06-27 13:15
    Thank you Leon. smile.gif

    I didn't think that it couldn't be done.
    The software side I am assuming is as easy as outputting the key codes. e.g 0x27 for the letter "A".
    The hardware should be as simple as some pull up resistors and perhaps some transistors to get the 5v required for the PC.

    Is this correct?


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-27 13:19
    Here's a nice reference on the PS/2 interface: www.computer-engineering.org/ps2protocol/
  • ClemensClemens Posts: 236
    edited 2008-06-27 13:21
    http://forums.parallax.com/showthread.php?p=675656
    I think this was a thread about a usb keyboard emulation - probably not what you are looking for, but cool anyway.
  • LeonLeon Posts: 7,620
    edited 2008-06-27 13:22
    The interface is just an open-collector transistor, IIRC.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • computer guycomputer guy Posts: 1,113
    edited 2008-06-28 07:07
    Thank you everyone smile.gif

    so for PS/2 keyboard.

    attachment.php?attachmentid=54353

    Just realised that the host does a lot of pre configuration.
    Would someone be interested in writing an obex object for "keyboard" and "PS2 controller" emulation.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip

    Post Edited (computer guy) : 6/30/2008 6:05:49 AM GMT
    258 x 514 - 4K
  • computer guycomputer guy Posts: 1,113
    edited 2008-06-30 11:53
    I know this is a big ask but I wouldn't ask if i didn't think the entire community would benefit from it.
    Some good information can be found here.
    www.curiousinventor.com/guides/ps2#mappings
    I am more interested in the Guitar Hero controller emulation.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-01 10:18
    Anyone smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-07-01 10:33
    Imagine how good you would have become at programming if you wrote those objects.

    Graham
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-07-01 11:29
    I don't have a link but didn't deSilva have some basic code for doing this (emulating keyboard) or at least talk about it?
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-01 11:46
    Graham I would love to learn by writing these objects.
    However as someone who has never fully understood any communication protocol and knows little if any ASM I don't even know where to start.

    Steven I will search the forums and see what I can find.

    There is already objects for a keyboard and a PS2 Controller all that needs to be done is to reverse the functions.



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip

    Post Edited (computer guy) : 7/1/2008 12:27:05 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-01 13:50
    Steven I searched the forums several times and can only find talk of a keyboard emulator not an actual object or attempt to do so.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-07-01 14:21
    "All that needs to be done is reverse the functions" -- this is easy to say, can be hard to do.

    So, basically, you're looking for a PS/2 Keyboard "Replacement" -- instead of the Propeller clocking bits OUT of a keyboard (which we already have code for), some external device will be clocking bits OUT of the Propeller. You'll need some level-shifting in there from the 5-volt Keyboard clock to the 3.3 volt Propeller levels, too.
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-02 05:43
    "this is easy to say, can be hard to do."
    I wasn't saying it would be easy just that there is a starting point.

    I was planning on using 2n2222 (or similar) transistors for the 3.3v to 5v level shifting.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-02 07:22
    One nice thing about making your own guitar hero controller is being able to add an auto play function to play the song for you. smile.gif
    I found an article on the net of a VB.net program that does this. Shouldn't be to hard to convert to spin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip

    Post Edited (computer guy) : 7/2/2008 8:10:19 AM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-02 13:07
    Ok I will try and code the keyboard code myself.
    However I may need some help from time to time as I have never coded in PASM before.
    I will basically be reversing all commands in the keyboard driver so that it writes rather than reads.

    Wish me luck. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-05 06:07
    If I was to call the transmit command from the keyboard with 'data' containing a command. Can I then just call the receive command to get the response from the computer?
    Or do I have to do something else in between? Also does the receive command store the received data in the 'data' variable?

    The propeller quick reference guide has helped me understand allot of the PASM functions.



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-06 12:18
    This is really overwhelming, Trying to reverse an object is really hard when you don't know the programming language.
    The prop now has to generate the clock signal rather than detect it and it has to initiate most communication.

    If someone could at least get a starting point that I could perhaps work on that would be great.

    Its the init code that is hard. Getting the prop to identify its self as a keyboard. Once that is done it is just a matter of sending scan codes.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • BradCBradC Posts: 2,601
    edited 2008-07-06 12:41
    Starting point?

    PUB Main (KeyboardPin) : Ok | Mask
        Mask := 1 << KeyboardPin
    
    



    [noparse]:)[/noparse]

    But seriously, If for some reason you don't or can't understand how the PS2 interface works, why not grab some code (and there is bucketloads of it around) for another processor (pic, avr, hc11). Read it, understand it, port it to the Propeller.

    As Calvins dad would say. "It builds character" [noparse]:)[/noparse]

    I don't even own a machine with a PS2 input anymore, it's all USB here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Pull my finger!
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-07-06 18:30
    hello computerguy,


    as i read on the website Mike mentioned

    www.computer-engineering.org/ps2protocol/

    the communication between PC and keyboard is not symmetrical.

    As you have difficulties to find a starting point. I think this caused by the idea just to reverse everything.
    But "reversing" is not as easy as multipling with minus one

    I think it will be easier to start the whole thing new from the basic up

    If the Prop should send scancodes this is the case "Communication: Device-to-Host"
    http://www.computer-engineering.org/ps2protocol/ said...


    "Communication: Device-to-Host"

    The PS/2 mouse and keyboard implement a bidirectional synchronous serial protocol.
    The bus is "idle" when both lines are high (open-collector).
    This is the only state where the keyboard/mouse is allowed begin transmitting data.
    The host has ultimate control over the bus and may inhibit communication at any time by pulling the Clock line low.

    The device always generates the clock signal.
    If the host wants to send data, it must first inhibit communication from the device by pulling Clock low.
    The host then pulls Data low and releases Clock.
    This is the "Request-to-Send" state and signals the device to start generating clock pulses.

    Summary: Bus States
    Data = high, Clock = high: Idle state.
    Data = high, Clock = low: Communication Inhibited.
    Data = low, Clock = high: Host Request-to-Send

    All data is transmitted one byte at a time and each byte is sent in a frame consisting of 11-12 bits. These bits are:

    * 1 start bit. This is always 0.
    * 8 data bits, least significant bit first.
    * 1 parity bit (odd parity).
    * 1 stop bit. This is always 1.
    * 1 acknowledge bit (host-to-device communication only)

    so this could be a starting point:
    programming a loop that is generating the clock signal and waiting for
    the dataline to become low as the signal Prop can start datatransmission

    next step:
    calculating the parity bit
    adding startbit (always 0) 8 databits, paritybit and stopbit (always 1) to a long and shiftout the eleven bits

    then adding the check for: host takes dataline high as a signal comm. inhibited by the host
    etc. etc.

    another website with infos about the protocol
    www.beyondlogic.org/keyboard/keybrd.htm

    best regards

    Stefan
  • Matthew HayMatthew Hay Posts: 63
    edited 2008-07-06 19:18
    Just a quick thought that popped into my head, why not make a wedge and let a real keyboard do most of the work for you?

    You'll have to make sure you passthrough everything that the keyboard is giving you but it should eliminate most of the init stuff. Check the sparkfun tutorial for some of their experience with this (the used avr but most of their information will still be useful to you)

    www.sparkfun.com/commerce/present.php?p=Key-Counter
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-07 11:42
    "The device always generates the clock signal.
    If the host wants to send data, it must first inhibit communication from the device by pulling Clock low. "

    If the prop is generating a clock signal on the clk line how can the host pull the line low?


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-07-07 13:22
    Hello computerguy,

    first of all - if you don't want to be tricky by switching the IO-Mode of data and clock all the time between Input and Outputmode
    you have to use FOUR PINs if the propeller should act as a keyboard emulator.

    You can find out this by carefully reading the website
    www.computer-engineering.org/ps2protocol/

    Maybe i ask how good is your knowledge about electronics?

    Take a look at the circuit

    ps2.JPG

    if the microcontroller-PIN "C" is low the transistor is "locked"=very high resistance - no current flowing from +5V through the Pull-Up-resistor down to ground
    then on microcontroller-PIN "B" there is high-level because of the pull-up-resistor. The circuit +5V-Pull-Up-Transistor-Ground is "openend"

    If the microcontroller-PIN "C" is high the transistor is "switched through" low resistance now a current is flowing from +5V through the Pull-Up-resistor down to ground
    then on microcontroller-PIN "B" there is low-level because all the voltage drops down "in" the pull-up-resistor

    By switching the PIN "C" the clock signal is generated

    The clockline is high as long as PIN "C" is low. If - on the other end the HOST connects the clockline to ground
    (and closes the circuit) then there will be PIN "B" low WITHOUT PIN "C" beeing high
    and the microcontroller (the keyboard-device) has to check for this combination.

    By this tricky way of circuitry the host - IN FACT - CAN pulldown the clockline by closing the circuit by himself.

    best regards

    Stefan
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-08 01:38
    So the low of the host overrides the high of the pullup.

    So the code needs to check if "pin C" is low and if it is check if "pin B" is low if they both are low for 100us then the host is pulling the clock line low.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-08 05:59
    computer guy said...

    So the low of the host overrides the high of the pullup.

    So the code needs to check if "pin C" is low and if it is check if "pin B" is low if they both are low for 100us then the host is pulling the clock line low.


    Thank you smile.gif

    Also if I was to use 2n2222 transistors wouldn't a 100ohm resistor be needed between the prop and base pin.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-07-08 07:19
    hello Computer Guy,

    yes a resistor between Prop-PIN and base of the transistor makes extremly sense.

    100 Ohms is a little bit low. each transistorTYPE has its own current-amplifyingfactor
    most of them in the range 50-150. If the pull-up-resistor is 10kOhms. You have a current of 5V / 10000 Ohm = 0,5mA
    So the collector-emitter-current should be 0,5mA. The base-emitter-current steers the collector-emitter-current
    let's assume the currentamp-factor is 100: then the base-emitter-current has to be 0,5mA = 500mikroA / 100 = 5 mikroA
    The base-resistor has to have a maximumvalue of 3,3V / 0,5 mikroA = 660kOhm

    For switching-purposes it's usual to use a 4,7kOhm resistor.
    3,3V / 4700 Ohm = 700 mikroA. The collector-emitter-current provided is 70 mA wich is pretty much and sufficient for
    digitical logic devices (usually 0,1-10 mA)

    i have to make an additional remark

    The schematic in the previous posting has a +5V supply and the PC-keyboardinterface works on 5V too.
    The propeller runs on max 3,3V. To avoid damage to the propeller you need 1kOhm current-limiting-resistors in serial to PIN A and PIN B
    in schematic above


                                     +5V
                                      |                                 
                                    PullUp
                                      |                                 
    Proppeller PIN A ---- 1kOhm ------+------> to HOST (PC)
    
    
    



    if you are not familiar to the basics of transistorelectronics search for a EASY to understand tutorial
    What i found at the english wikipedia is HARD to understand and does not cover the basic things
    about base-emitter and collector-emitter current.

    My experience searching with google in about 15 Minutes is:
    an EASY to understand tutorial could'NT be quickly found

    here is a link to a german website with two pictures
    showing an analogon with water

    leifi.physik.uni-muenchen.de/web_ph10/grundwissen/15trans_eff/trans_eff.htm

    small base-current small collector-emitter-current
    modell1.gif

    bigger base-current bigger collector-emitter-current
    modell2.gif

    the different with of the waterchannels represents the amplifying-factor for the current

    the small base-channel drives the big collector-emitter-channel


    best regards

    Stefan

    Post Edited (StefanL38) : 7/8/2008 8:08:31 AM GMT
  • scanlimescanlime Posts: 106
    edited 2008-07-08 07:27
    If you're still looking for a way to emulate the Guitar Hero controller, I have a generic Playstation controller emulator object that might be useful.

    It's at svn.navi.cx/misc/trunk/unicone2/psx-base/, as well as on the object exchange.

    Guitar Hero controllers are basically just analog PS2 controllers (not Dual Shock- Guitar Hero will work with a Dual Shock emulator, but GH2 doesn't) with the left d-pad button held down. I've tested this emulator object successfully with Guitar Hero and Guitar Hero 2. You just have to be sure to use CONTROLLER_ANALOG mode instead of CONTROLLER_DUAL_SHOCK.
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-08 08:05
    Thank you both.

    The PS2 GH emulator is more important than the keyboard.

    I didn't think of the 1kohm resistor but now that you mention it I remember the need for it.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-08 11:57
    StefanL38,

    I have always compared to a transistor as an electronic tap.
    The more current that is applied or the more you turn the valve the more current passes from emitter to collector or the more water is allowed to flow.
    That has always worked for me. smile.gif

    I just remember that in a previous project a resistor of some value was needed between prop and base pin to prevent the prop from doing damage to the transistor.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip
  • computer guycomputer guy Posts: 1,113
    edited 2008-07-08 12:34
    Micah Dowty,

    I have had a look at your emulator and am not sure how to use it.
    Could you please write some short code to configure it to emulate an Analog Controller and then send out that the "Square" button has been pushed.
    This should be enough to give me a general idea of how to use it.

    Also do you have a copy of the schematic for connecting the prop to the PS2?


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Stickers for sale

    Building Blocks To The Propeller Chip

    Post Edited (computer guy) : 7/8/2008 12:48:03 PM GMT
Sign In or Register to comment.