Unable to read PS/2 keyboard events on Arduino Nano

This is a bit of an odd question, and is not really programming related. But I feel like I'm missing something obvious related to the wiring, setup, and/or initialization of the code for interfacing a PS/2 keyboard with an unbranded Arduino Nano product (CH341 serial interface).

I am trying to read key presses from a PS2 keyboard and echo them to the serial monitor. For this, I am using the "simple" sample programs of the PS2Keyboard and PS2KeyAdvanced libraries; both are equivalent and very similar. When I hook-up the keyboard to the Nano, its LEDs briefly illuminate, then its shuts down -- no key presses are read and presented in the serial monitor and the monitor shows the "ready" prompts printed by the sample programs.

The keyboard had a PS/2 terminal. I tested the keyboard on my computer with a Female PS2->Male USB-A converter and it works as expected; the LEDs also stay lit in its default mode (Caps-Lock ON). I cut off the PS/2 terminal and replaced it with a male USB-A terminal and the keyboard continues to function when connected to the computer.

On the Nano side, I hooked up a female USB-A terminal and wired its pins as follows: 1->5V, 2->D4, 3->D3, 4->GND. The keyboard is being powered by the Nano's 5V regulator, so I also attached a 9V battery to the VIN and another GND pin to compensate for the regulator's voltage drop when powered by USB alone. Given the mapping above, the sample PS2Keyboard and PS2KeyAdvanced code is initialized to use D3 as the IRQ pin, and D4 as the DATA pin.

I have reviewed these connections over and over and over, and I don't see anything wrong with the PS2->USB mapping above, and the connections to the board. The keyboard is simply not being detected and/or starting up properly when connected to the Nano board, with or without the USB modification I made. Incidentally, the keyboard also lights up briefly when connecting to a USB power bank (LEDs illuminate briefly then shut off).

Does anything seem wrong with this setup, and am I overlooking something simple?

My hypothesis is that this keyboard is actually an HID device and was hard-wired to work with a PS/2 port. This particular keyboard model comes in three varieties: PS/2, USB, and USB with hub. The internal controller board has an unpopulated USB-hub footprint, so I think the designer just used one PCB for all models to save cost. Furthermore the Windows 10 Device Manager shows it as an HID device when connected via USB -- should a PS/2 keyboard display as an HID or PS/2 keyboard in the Windows 10 Device Manager when hooked up through a USB port?

Please let me know if you have any insight on this problem. Thanks!

I cut off the PS/2 terminal and replaced it with a male USB-A terminal and the keyboard continues to function when connected to the computer.

Maybe the connector had the electronics in it to convert USB to PS/2

There are PS/2-USB adapters that have no electronics. Many keyboards that have PS/2 and USB versions can connect to PS/2 and USB with such a passive adapter.

This paragraph at Wikipedia suggests that it is always USB, and the passive adapter can connect it to a PS/2 port. Then the computer would would have to turn the PS/2 port into a USB port. In my opinion, that is not the case. I could be wrong, but I think that the keyboard or mouse itself changes its mode.

To connect a USB keyboard to an Arduino board, the Arduino board has to be able to behave as a USB Host. There are also USB Host shields. I have never tried that. In that case a Raspberry Pi could be a good choice.

The Arduino Nano can read PS/2 signals.
Can you remove the PS/2-USB adapter ? You need the PS/2 signals. I suggest to use the PS2Keyboard library that you already tried.
I have not heard of this problem before and I don't know how to turn the keyboard into PS/2 mode. Could the PS/2 signals have a idle level that makes the keyboard to recognize that ? Both PS/2 signals are pulled up with resistors to 5V.

The PS2Keyboard library sets both pins as INPUT_PULLUP. Can you connect the keyboard after the keyboard.begin() function is called, so the pullup resistors are already enabled. Or add external resistors to 5V, for example 10k pullup resistors.

What are you going to do with the key presses in the Arduino Nano ? A Arduino Leonardo can turn into a USB keyboard, so the Leonardo becomes a PS/2-USB adapter (and translate keys or add extra things if you want).

Riva:
Maybe the connector had the electronics in it to convert USB to PS/2

It is possible, but I don't think it does.

The connector is a purple mini-DIN6, and while there may be some tiny components hidden inside to do the conversion, the clock, data, +5V, and GND pins on the output all had continuity to the wires on the opposite side. I would have expected a break in continuity if an IC did the conversion as it would have been powered-off when continuity was tested.

Koepel:
The Arduino Nano can read PS/2 signals.
Can you remove the PS/2-USB adapter ? You need the PS/2 signals. I suggest to use the PS2Keyboard library that you already tried.

Thank you for your feedback!

This is the confusing aspect of my testing. The keyboard had a hard-wired PS/2 connector which I replaced with a male USB connector so I wouldn't have to use the passive converter. On the Nano side, I wired a female USB connector to the board. Whatever protocol the keyboard was putting out with the PS/2 connector should have remained unchanged as I'm only changing how the wires are organized into a connector.

I have not heard of this problem before and I don't know how to turn the keyboard into PS/2 mode. Could the PS/2 signals have a idle level that makes the keyboard to recognize that ? Both PS/2 signals are pulled up with resistors to 5V.

The PS2Keyboard library sets both pins as INPUT_PULLUP. Can you connect the keyboard after the keyboard.begin() function is called, so the pullup resistors are already enabled. Or add external resistors to 5V, for example 10k pullup resistors

Most of my testing was done by connecting the keyboard after powering up the Nano, which yielded no different results. But that said, I think you're on to something here. I suspect that the keyboard operates in USB mode by default, and needs some signal from the host device to go into PS/2 mode. I'll research and experiment more with this idea, as well as using pull-up resistors as per your suggestion.

What are you going to do with the key presses in the Arduino Nano ? A Arduino Leonardo can turn into a USB keyboard, so the Leonardo becomes a PS/2-USB adapter (and translate keys or add extra things if you want).

I'm trying to use a keyboard as an interface to an Atari 2600 -- mainly due to the simple nature of the DB-9 interface it uses, but also because it has a very unusual "keyboard" controller. The Arduino will capture the keyboard key presses and translate them to the proper signals for the Atari console. I was hoping to use a Nano due to its size and low cost, but the Leonardo looks promising and I may just try one of those if I can't figure this out (or get a PS2-only keyboard).

That is a lot of trouble for nothing. I mean, when I look for used PS/2 keyboards then the lowest price is for free, for nothing. Get a bunch of old and used PS/2 keyboards and try those. I might even have a few in a box somewhere :wink:

Koepel:
That is a lot of trouble for nothing. I mean, when I look for used PS/2 keyboards then the lowest price is for free, for nothing. Get a bunch of old and used PS/2 keyboards and try those. I might even have a few in a box somewhere :wink:

I know... but unfortunately, no one is giving away or even selling PS/2 keyboards at a reasonable cost in my area. In fact, this keyboard I'm debugging is the only "free" one I found on Craigslist within the last month. I guess there are few people around me that hold on to them or just throw them away.

I'll keep looking; a PS/2-only keyboard is the easy way to fix this :slight_smile:

Quick follow-up:

I discovered that the PS2KeyAdvanced reports that my keyboard is in fact sending a stream of 0xAA messages to the host; so everything is setup properly.

This post from 2011 suggests that the sequence of messages needs to be acknowledged by a 0xFE message with an incorrect parity bit set. The 0xAA messages also have an incorrect parity bit set, presumably to not confuse them with the standard 0xAA message that indicates a keyboard self-test has completed.

steveguidi:
My hypothesis is that this keyboard is actually an HID device and was hard-wired to work with a PS/2 port. This particular keyboard model comes in three varieties: PS/2, USB, and USB with hub. The internal controller board has an unpopulated USB-hub footprint, so I think the designer just used one PCB for all models to save cost. Furthermore the Windows 10 Device Manager shows it as an HID device when connected via USB.

I wanted to close the loop on this thread and report that my hypothesis above was indeed correct: the keyboard I struggled with is an HID device but was hard-wired to a PS/2 connector. I ultimately found a native PS/2 keyboard and am using it without issues.

Thanks for the update ! Good to know.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.