No announcement yet.

PS/2 Keyboard Driver, Demo, Instructions!

  • Filter
  • Time
  • Show
Clear All
new posts

  • PS/2 Keyboard Driver, Demo, Instructions!


    Attached please find a PDF file with instructions on how to attach an AT PS2 keyboard directly to the 4D uVGAII module, with a bit of 'keyboard operational theory' and some links thrown in.

    Also, an extensive 4DGL demo program is also attached, containing a rather complete PS/2 keyboard driver as well as a scrolling typing demonstration (one can type on a 38-line by 80-character 640x480 resolution VGA display). The program size when compiled for RAM is 3801 bytes.

    Only two GPIO pins of the uVGAII are needed. No external power supply is neccessary, just attach the uVGAII to the PC using the USB cable; the keyboard uses the ground and taps the 5v available on the uVGA (full description of all of that is in the PDF file).

    Study the demo program carefully, it is a non-trivial example of just how useful, compact and clear the 4DGL language is. Also, many sophisticated programming techniques are used that one may have heard about but never seen a practical example of how to use, such as parameter passing-by-reference, indirect addressing, local/static function variables, bit-level manipulation including odd-parity generation/checking and SERDES (serialising/deserialising) and more.

    The program also can be modified fairly simply to serve as a real (TTL voltage) serial terminal, to transmit, receive, display and control some other device (ie, MCU board, etc.).
    An attempt was made to heavily comment the program, to ease modification for one's own applications. If anything is unclear, please ask here and I will be glad to clarify - be patient, I'm very busy, but I will answer any reasonable question.

    Best Regards,


    NB - This implementation only runs properly out of RAM. To get it to run 'standalone' (ie, not attached to PC/4D workshop), one must use a 'run from disk' technique (ie, load and run the program from uSD card)., and power the uVGAII through the Vin and GND pins on the uVGAII 5-pin connector.
    CAUTION - PLEASE be very careful not to reverse polarity to your keyboard!
    Before you connect your keyboard, make certain that the +5v and
    Gnd connections from the uVGAII pins to the PS/2 connector are
    correct. Otherwise, you can damage the keyboard electronics.
    Also, NEVER 'hotplug' (plug or unplug) a PS/2 keyboard when
    power is on (same is true for a PC, too).

    Attached files PS2_Demo.4dg (19.2 KB)
    Attached Files

  • #2

    Hi autologic,

    that's an excellent piece of work

    Im sure it will generate a lot of interest as if can form the basic front end for many applications.
    You have also done an excellent job of documenting it

    If your ok with it, we would like it to take pride of place in the codebase.


    • #3

      Hi Autologic,
      also thanks from me for sharing your code with us.

      Regards, Frank


      • #4

        Gotta give credit where credit's due, well done


        • #5


          You're all welcome; I cerainly agree that you can put it in the codebase!



          • #6


            I cannot get this PS/2 program to work. I've butchered 2 good PS/2 keyboards trying to figure this out.

            I have some questions that I hope will help me.

            Why can't it run from Flash? A program is a program. If the only signals it uses are IO2 and IO3, what does RAM and Flash have to do with program operation.

            Second, in your docs, you mention Do Not plug the PS/2 keyboard in yet. Then a paragraph later under Making It Work, you give directions as step #1 to plug the keyboard in. Ok?

            Third, you mention: "Now, connect the 'PS/2 Data' wire to the IO2_PIN [J2 pin 3] and the 'PS/2 Clock' wire to the IO3_PIN [J2 pin 2] on the uVGAII module."
            However, in the 4D Systems uVGA docs, it clearly shows:
            J2 Pin 2 is IO2
            J2 Pin 3 is IO3

            I have tried swapping my keyboard CLK and DATA wires and nothing happens in either case. I've even tried changing the program to use BUS6 and 7 as a test and it doesn't work, either.

            The keyboard is fine. When it powers up, when the USB cable is powering up the uVGA module all 3 keyboard LEDs flash on for about a second then back off like they do when you turn on your PC.

            I can't tell if the program is working because no text I type is showing up. Only the bottom line of fancy text shows up. "4D Systems 4DGL uVGAII GFX Platform - Demo......"

            I'm surprised several people commented that it's a great program, and also that nobody else has commented on what *should* be one of the best utilities for the uVGA so far. Yet, no feedback in one year.

            What's the status, any working code?
            Roger Taylor


            • #7

              Autologic hasn't visited these forums for a few months now, so you may have to get it working without him.

              I don't understand the need to butcher a keyboard, surely you just buy a socket and wire it up as per his diagram?

              Since there have been 32 downloads I suspect quite a few people have gotten this to work.

              Have you tried comparing the functionaity of the IO pins specified in the program by writing another program that exercises the pins and checking which pins are changed with a meter?

              Maybe your keyboard does not support scan code set 3?

              I suspect the need to run out of RAM is for speed, RAM programs run faster than FLASH programs. Since the clock is generated by the keyboard it may be that the program will be too slow to work if run from FLASH


              • #8

                No problem cutting the keyboard cables. I've got plenty of these things. The two I tried are 2011 model "emachines" PS/2 keyboards. They are flimsy so I replaced them the day I bought my computers. I can't think of a better reason to cut the cables open. There's 4 wires. Yellow, Red, Brown, Gray.

                I'll try a Packard Bell keyboard next.

                And what about the MouseDraw program? What is the wiring for that? I'd love to make a small motherboard for the uVGA that has a keyboard and mouse input.
                Roger Taylor


                • #9

                  The Packard Bell keyboard didn't work either. It powers up and the LEDs come on and go off like they should but no data response.

                  I think this program needs to take into consideration what the PS/2 standard might be, as I've tried 3 keyboards now with no luck. (1 old and 2 new).

                  The IO2 and IO3 pins work fine on my uVGA.

                  Also, autologic has it wrong about what pins on J2 are IO2 and IO3.

                  How can so many downloads with no feedback mean that everyone has had success, when the docs are incorrect.

                  I'm just wondering if something else is wrong that is keeping this from working for me.

                  If anybody has a working PS/2 utility for the uVGA could you please post it?
                  Roger Taylor


                  • #10

                    Hi cocotower,

                    Sorry for the delay, as I mentioned I'm rather busy.

                    Thanks for your remarks.

                    However, in the 4D Systems uVGA docs, it clearly shows:
                    J2 Pin 2 is IO2
                    J2 Pin 3 is IO3
                    1) You're right. I've corrected the J2 pin / IO pin typo, sorry if that caused any trouble.

                    2) I specified not to plug the keyboard into the uVGAII yet, so that one would wait until reading the rest and not expect the keyboard to magically work with no further ado - sorry if that was too pedantic.
                    3) The reason it won't work from Flash is indeed because of the speed difference between RAM and Flash on the Picaso; maybe I could have optimised the program to work from Flash but we didn't need it in Flash, if someone wants that, they can work it out. [ie, the program is a demo showing how to do this, not an application]

                    4) The PS/2 standard was duly taken into account (as it has been on any embedded device we've hooked PS/2 keyboards up to), there are several links in the PDF to tutorials and exhaustive discussions about this for the interested persons. The program uses a methodology that is successful because it adheres strictly to the protocol and automatically compensates for differing clock speeds on different keyboards (or 'clock drift' on the same keyboard due to changing temp. and such on some of the crappier keyboards).

                    5) We've tested this on no less than 7 different keyboards (addition to the 6 specified in the PDF: a "GPT KB-4" that costs < USD $5) of different qualities, different clock ratings, different current demands (30mA - 170ma), etc. and it always works (and that's only for this demo on the uVGAII - the same method we've been using for years on a wide range of MCU modules). I'm not making this point to 'bash' you, just to let you know it does work. Also, quite a few of those persons who downloaded the program have taken the time to tell me it works, and other positive things.

                    6) The program self-tests at startup; it reports pass/fail for keyboard functions (in red capitals at top of the monitor that the uVGAII is attached to). Do you see this when you run the demo?

                    Perhaps the power output of your USB cable (from your PC to your uVGAII) is low (too low to power the keyboard and uVGAII at the same time properly), perhaps the short-cut of just cutting off the PS/2 plug from the keyboard and wiring it to the uVGAII is causing some problem, I can't get enough info from your post to troubleshoot it.