Sending key strokes using an old keyboard?

Hello arduino hive.!

I have been using this forum for a few years now and have usually found answers to the simple problems I have had but now I'd like some specific feedback, hence the first post!

I want to send key strokes to a computer from my Arduino Mega.

Why not use an arduino with built in USB serial, like the pro micro or Leonardo?

Because I already have an Arduino Mega and that would be too easy otherwise. Well maybe if this all turns out to be too much effort I'll just buy another Arduino.

But bear with me. I have an old table calculator, the kind that prints out a docket and I want to use this to send the key strokes. I have already gutted it and am using the existing key matrix to receive all the keys. Exactly like one of those little 3x4 keypads only cooler.

It uses a 10x10 matrix hence the Mega. I didn't plan on sending keystrokes to the computer at the start of this project otherwise I would have just bought a Due... the one that looks like a mega but has the usb capabilities.

But what I do have is an old usb keyboard! Broken down it's just a tiny pcb with a 26 pin button matrix. Now I have soldered wires to the 26 pins and have mapped the columns and rows and all the keys! When I touch a row wire with a column wire I get a keypress. Awesome that was easy.

Now get the arduino to touch the right wires together when I press the keys on the old calculator and we are away!

This is where I'm at. I have enough digital pins left on the Mega and thought I could get something working.

Here's what I tried. By setting the pins as output and then to low I can use this as a switch to connect the wires of the button matrix. For example pin 40 and pin 41 combination will press the button H. Normally is pin 40 high and 41 low. When I press a button on the calculator both pins go to low, effectively connecting them right? Well it works and I get a key press.

The problem is when I use more and more pins. Because they all end up being connected unintentionally either bot high or low and that gives me multiple presses.

My thoughts are now, is this somehow possible with my current setup or do I have to spend more money. I feel like I'm super close. Maybe an idea to use optocouplers or something to do the switching but then just buy a new board right?

Would be interested to hear your thoughts!

Both pins low does "connect" them but not in the way that the keyboard controller is expecting. Think about how a matrix should work: the controller raises each of the "column" pins one at a time and checks which "row" pins change as a result.

So the Arduino must detect what the controller is doing and only drive the output pins at the right time. You will probably have to use interrupts to get a fast enough response.

A PS2 keyboard (can still buy new with PS2 mouse at WalMart cheap just last year) takes 4 pins to connect.

If you use direct port manipulation and select pins to match you can speed the process. Arduino digitalRead() takes 5x as long as a direct port (PINx register) read but you better have the port set right before you read, the Arduino command does it every time need it or not.

I think that if a button matrix has all the pins but 1 column pin at a time pinMode(x,INPUT_PULLUP) and that 1 pinMode(x,OUTPUT) and then set LOW in the DDR register. Each row can read the column, if the pins are on the same port then 1 read gets them all. When the rows are done reading, set the pin back to INPUT_PULLUP and make the next column OUTPUT LOW.

As far as I can figure, this matrix needs no diodes to get multiple keypresses right. The LOW column pin only drains rows with a closed switch to it. There is no power path up, only drains down.

Okay managed to find this post again. Is there a way to find post that you've posted in easily?

Anyway I've changed tack and will try to leave the computer all together. Trying to keep it all in the Arduino but proving to have its own limitations.

Thanks for the solid advise however, I appreciate the time taken to answer.

Jeremy :slight_smile: