And finally when the relevant key is released(PS/2 protocol refers to this as 'break') the code will cycle through the current byte array and clear only the relevant byte. Basically what my code does is each time a new key is pressed (PS/2 protocol refers to this as 'make') it cycle through the last 6 bytes of the array that are used for normal key-presses, and fill in the first empty byte it finds with the relevant 'HID scancode'(Shown as in fig.2 Also you can find a complete list from the attached PDF) for the received 'PS/2 scancode'. The output 8 bytes array you saw is formatted according to the above fig.1 You can learn much more about this and also how the modifier keys status byte is written from this wiki about USB-HID. This is just an explanation for the previous outputs. If everything here happens you are golden to proceed! and lastly if you press either Caps Lock,Num Lock or Scroll Lock you should get something like this with multiple lines at the same time,Ġ0 00 xx 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00.and finally return to this when every key is released,.and if you press new key d with value 'nn' without releasing key a or key b your output should change to,.when you only release key b the output should change to,.For each new multiple normal key-presses(for an example we will press both hypothetical key a,key b and key c with values 'xx','yy' and 'zz' in that order) you should get continuous(not mandatory) newlines like this,.
Finally when you release all modifier keys 'xx' should become 00.
So here we will upload a 'DEBUG' version of the final sketch with a human readable output(through the serial monitor) to test things out. This becomes especially true if you don't have any external programmer like a USBasp or another Arduino to use as a ISP. But in final sketch I have disregarded this method and implemented these modifier keys as simple key-presses(You will see that these modifier keys also have "make" and "break" scancode independent from normal keys whether or not multiple keys are pressed.) because it makes things easier with USB-HID protocol.īefore updating the Atmega8U2 or 16U2(UNO Rev3) to identify our Arduino as a USB keyboard we should make sure all the conversion stuff is working correctly and the final final sketch is uploaded or otherwise it will be a major pain to keep over-writing the firmware again and again between the Original and USB-keyboard hex files just so you could upload the correct sketch. "Status Bits" refers to modifier keys(Ctrl,Alt,Windows,Shift/Caps) and you will see that with each additional modifier key, this value changes while the main "Code" of normal(non-modifier) key is unchanged.Also you can get a complete list of PS/2 scancodes from the library by opening either 'PS2KeyAdvanced.h' or 'PS2Ke圜ode.h' files from '\Documents\Arduino\libraries\PS2KeyAdvanced\src\' This "make" and "break" scancode system and "Code" which is the isolated(c & 0xFF) scancode of either the key-press or key-release plays an important part in PS/2 to USB conversion and I recommend you study the other 2 examples that comes with library to get a better understanding if you are planing on improving or changing(remapping keys to different layouts) the final sketch.
Here I have attached a modified version of the SimpleTest.ino from PS2KeyAdvanced library examples with updated clock and data pins and also a "make" and "break" representation.
But don't worry you can't actually brick your UNO/Mega by doing this it is always reversible.Īlso by any chance if you have an Arduino that already has a USB-HID capability (Arduino Pro Micro or Leonardo,etc do a google search) you can forget this instructable ever existed go directly here to save yourself from a world of trouble, just kidding!īefore you go all hands on deck first make sure everything is working on keyboard and library.
This is because we will be over-writing the firmware on its USB interface chip(little guy near the USB port Atmega8U2 and 16U2 depending on the revision). By that I mean you can't use the Serial communications and you can't reprogram it via the USB. When you are using your UNO/Mega as a USB-HID device(Not limited to keyboard, it can even be a mouse,joystick,etc.) you will temporarily loose its functions as a Arduino. Then you have come to the right place :)įair warning before we get into it.
Did you ever wanted use your old PS/2 Keyboard with your laptop or new desktop PC and found out that they don't have PS/2 ports anymore? And then rather than go buy a cheap PS/2 to USB Adapter like a normal person would do, wanted to use your Arduino as a PS/2 to USB Adapter.