Dear Arduino community,
I am making an Arduino-based device, which shall be recognized as a pure PS/2 keyboard and shall forward Sega Genesis and Super Nintendo gamepad input as PS/2 key presses for my MS-DOS Laptop (kinda like this thing, only with some of my quality-of-life improvements).
My project is based on a Pro Micro (ATmega32U4) but the problem persists with Arduino Nano (ATmega328).
I’ve written a long and windy code to read Sega 6-button input and send corresponding keys to PS/2 port…
It works, but it somehow fails to deliver 2-5% of PS/2 commands (i.e. either command to “press” key or command to “release”). My gamepad library is 100% reliable (as I tested it by forwarding to HID ATmega32U4-native USB-keyboard output leading to many hours lost to pla… ahem …testing Genesis emulator).
To verify the issue, I’ve designed this simple thing:
Color code is:
Black - DATA
Yellow - CLOCK
Orange - +5V (from PS/2 port)
Red - GND
And fed it the following short code to forward keypresses from REAL keyboard to HOST pc:
#define KB_YELLOW 6
#define KB_BLACK 5
#define HOST_YELLOW 8
#define HOST_BLACK 7
bool YELLOW = 0;
bool BLACK = 0;
void setup() {
// put your setup code here, to run once:
pinMode(KB_YELLOW, INPUT);
pinMode(KB_BLACK, INPUT);
pinMode(HOST_YELLOW, OUTPUT);
pinMode(HOST_BLACK, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(KB_YELLOW) != YELLOW) {
YELLOW = !YELLOW;
digitalWrite(HOST_YELLOW, YELLOW);
}
if (digitalRead(KB_BLACK) != BLACK) {
BLACK = !BLACK;
digitalWrite(HOST_BLACK, BLACK);
}
}
My test is as follows:
- I let the pc boot up with REAL keyboard connected directly (so BIOS properly initializes presence of the keyboard).
- Once loaded – I disconnect REAL keyboard and connect my Arduino device as intermediary.
- I press keys on the keyboard.
The thing still drops up to 5-10% of commands! The problem seems to persist with longer (2-3 byte keycodes) than shorter ones (i.e. Num-pad arrows are more reliable than “ordinary” arrows, pressing a key is more reliable than release it, etc.). The wire itself seems fine, as I tested it as a direct (passive) extension to the keyboard and it worked.
The questions are:
- What is the issue? It is the same for Pro Micro (ATmega32U4) and Arduino Nano (ATmega328).
- Is it the problem with connection? Is it my mistake to connect the leads directly to Arduino?
- The problem with power? (I tried retaining USB power to the device. Seems to have done nothing) Do I have to filter it somehow? How?
- Can you advice on emulating a PS/2 keyboard?
Thanks in advance!