Best way of reading a parallel keyboard?

I'm trying to use an IBM 5251 keyboard on a PS/2 port, and I've got an Arduino (Duemilanove with a 328.)

Therefore, I'd like to use the Arduino to translate its output to PS/2.

There's a schematic available, which I'll post in a reply.

What's the best way of reading the parallel output, considering that I can't just sit there and poll the digital pins, without risking missing bits - and then the timing wouldn't be exact, anyway.

I see there are resources on how to output PS/2, at least.

I'll readily admit that I'm not a very good coder, so this project may be well beyond my abilities.

And, no, I don't have a working scope.

Schematic link: http://kbdbabel.org/schematic/kbdbabel_doc_ibm5251_kbd.pdf

You'll need to use interrupts; but your problem may be larger than that.

This is because ports on the ATMega are 6 bits wide (IIRC), and it looks like from that schematic you are going to need to bring in more than 6 bits of information.

Do you have other information besides that schematic that details what the keyboard outputs? If not, you should attempt to find that. Ideally, you should have on hand a logic analyzer that you could put probes on all the lines (plus the rest of the terminal, so you can see what each key does/sends) - but you don't even have a scope...

Maybe you can use pin-change interrupts triggered on a couple of ports - and read the data as fast as possible, dumping it somewhere for later analysis.

Interrupt handling:

http://www.arduino.cc/en/Reference/AttachInterrupt
http://www.arduino.cc/playground/Code/Interrupts
Arduino Playground - HomePage (look under "AVR Related"->"Interrupts"

While the Arduino environment provides some level of interrupt handling, it is less than what the ATMega can actually do (they likely set things up this way because so many other things, like PWM, use interrupts as well). Setting this up to do what you want won't be easy.

You may want to play around with some of the examples for interrupts first, and get an idea of how things work before interfacing that keyboard...

:slight_smile:

I don't have the terminal, just the keyboard.

And, no, I don't have signalling information, and the kbdbabel guy doesn't have it posted.

Also, in an IRC channel, it was mentioned that the "Data Av." pin is a pin that I could interrupt on, and then check all of my pins.

I've been looking around, and looks like PORTD is 8 bits wide, based on this - enough to cover the 7-bit scan code, and the make/break bit.

So, I believe I can use PORTD (unless I absolutely have to use pins 0 and 1 for the PS/2 output) for the input data, and read PORTD on an interrupt from whatever pin the Data Av. pin is connected to.

That leaves the PS/2 output and the POR to handle, for stuff I absolutely have to handle for this to work. I think there's enough pins to do it. (There's also the +5 and -5 supplies, but I consider that a separate issue entirely.)

Well, it sounds like you are on your way, then - but you will probably want to find a way to communicate serially, so you can see how things are working at the Arduino level - that is, on the interrupt and reading the parallel pins, what data you get (or don't get), to see if it matches up with what you are expecting before you move on to the PS/2 portion.

Since you have what you believe to be a single interrupt line, you could tie it to one of the interrupt pins on the Arduino, then wire the parallel pins to any of the other digital i/o pins (and leave TX/RX alone); when the interrupt occurs, read the pins and output the data to the serial port - you would still have serial comms for debugging...

Then once you were sure of the data, you could move on to the PS/2 portion of things.