Simulate a Button Press Only Using ATMEGA2560

I recently took a keyboard apart to learn and experiment and I learned about the matrix used to shrink the amount of control pins needed. I took the control board out and soldered wires where the matrix traces were prior. What I want to be able to do is connect these wires to the Digital I/O pins of a Mega and simulate a key press without any other circuitry. Is this possible to do in code or would I need an external chip such as a 4066 or something? Thanks.

Sure, look at the keypad.h library to do that.

My apologies for not being as clear as I should have been. I can see where one would think that I soldered the wires to the matrix when in fact, I soldered the wires to the control board. I want the Mega to BE the matrix, not receive presses from the matrix I took apart.

This is tricky - I would put a row and a column on the 'scope, and plug it into a computer. The keyboard will probably have a pullup on all of the rows (or all of the columns) while driving each column (or each row) LOW in turn. And then I would see how wide and how frequent this pulse is. Assuming it's not something insanely fast, it should be possible to do.

I would probably put all the pins that get actively driven by the keyboard controller onto one port, and put a PCINT on that port, and have it check if any pin is low in the ISR and if so, drive the appropriate other pin low to simulate a keypress (I would use direct port writes for this, putting all of those lines onto the same port; I'd keep a global array of bytes (one for each line actively driven by the keyboard), so the ISR could just see when one pin was low, and write the appropriate byte from the array to the relevant PORTx register.

I wish I was in my universities lab to use one of the oscopes. I tried using the builtin PulseIn function but it was returning a constant value. It did make me think that perhaps the board I'm using is cycling though too fast. That led me to this forum. I've have yet to try interrupts mainly because I've only used them while programming MSP430 devices and I'm not familiar with Arduino. I'll shall give that a go now. Thank you.

Just did some research and the Mega only has a select few digital pins that can be used for interrupts. The board I'm using is controlling 20 pins which is more than the Mega can handle.

DarkSage:
Just did some research and the Mega only has a select few digital pins that can be used for interrupts. The board I'm using is controlling 20 pins which is more than the Mega can handle.

That is incorrect - there are 19 available PCINT pins, and you only need pins that can do interrupts on the pins driven by the keyboard, not the ones it listens on. PCINT is much easier to use than the "external interrupt" INTn pins for this use case.

The fact that you do not have access to a 'scope makes reverse engineering the keyboard much harder, though...

I would expect pulseIn to return a constant value, as the keyboard will likely pulse those pins low at a constant interval. Of course, the controller on the keyboard might set it's own interrupts on

HOWEVER this all begs the question - why not just use a Micro or Leonardo, which has native USB, to emulate a USB keyboard using the keyboard library?! (The Uno and Mega do not have native USB, and cannot do this without much more pain) This is a much easier method to make an arduino generate keypress events - trivial compared to what you're talking about doing.

Thanks for that input. And to answer the last question........simply because I don't have one.......yet.

Well, there's an easy way to fix that! Clones are like $7 shipped from US, $5 shipped from China (via ox cart) on ebay. Be careful with EBay listings, as sellers selling the much cheaper Nano (which does not have native USB) include the word "Micro" in the listing title.