Emulating a piano keyboard

Hi there!

I've been given a old 1980's 61 key electronic piano, and it has no keyboard! I was wondering if there was a way to emulate a 8x8 keypad matrix on a Arduino Uno, Due, or Mega?
I was thinking that I could send MIDI data to the Arduino, and get it to trigger the appropriate key(s). Having 61 relays is a bit out of the question, but any suggestions or pointers towards the right path would be greatly appreciated! :open_mouth:

Anything's possible no doubt. Perhaps more circuit details would bring forth more answers. You need to close 61 circuits, or just 16 (8 x 8)?

Just 16, the keyboard is in a 8x8 matrix, 8 columns and 8 rows. I don't mind using relays, now that I realise I don't need 61 of them.

May I suggest optocouplers instead of relays: Quieter, can be driven directly by Arduino, smaller, much cheaper in numbers. The only drawback is that unlike relay contacts, the output transistors in optocouplers are polarity conscious - assuming NPN output transistors in the optocouplers, you will need to make sure that the collector of each opto output goes to the more positive side of the keyswitch it is replacing, and the emitter to the more negative side.

There is one potential problem though: How many note polyphonic is this piano? Although your optocoupler or relay outputs can be wired in an 8 * 8 matrix, the worst case scenario is that you may have to be able to turn on quite a few of them (say at least ten, the maximum number of keys a human player could press) at the same time. This means that there is a requirement for the controller to be able to press, hold and release ANY of the piano keys independently or together in an almost infinitely variable number of ways. Put simply, each of your optos or relays will need an arduino output dedicated to control it. Practically, this means you'll need to use a number of output expanders such as I2C to 8-bit port ICs, ie, PCF8574.

The piano can handle more than 10 notes at once, but I wouldn't mind if the Arduino could control only 2 or 3 at a time. I'm just about to see if any of my local electronics stores have optocouplers.

I'm not totally convinced optocouplers on their own will do it, because in a keypad matrix situation, there is not necessarily a "ground".

Is there any way to manually trigger keys by shorting pins on the mainboard? Would I need a resistor for that? I thought it might be handy to know what pins do what.

Not necessarily, but unless the matrix uses some really strange multiplexing, or "Charlieplexing", either rows or columns will be strobed low or high and the other, pulled high or low to sense it. Optocouplers would suit perfectly as the outputs "float", though you are looking at one per "key" and - you cannot multiplex the input side!

If it is polyphonic (more than two), then the matrix necessarily contains diodes, and optocouplers would automatically perform this function.

And again, a matrix must be multiplexed, so the trick is actually to figure out exactly how it is multiplexed, how fast and how regularly, and produce a program which matches the (eight) strobes to the (eight) sense lines, using only 8 outputs and 8 inputs.

Hi, I don't want to put a spanner in the works but how do you know the keys were single switches, usually they are 2 switches, one to signal the key has just started to be pressed and another to signal when the key is fully depressed. This is how the circuitry knows how hard the key was pressed and thus the volume of that keys note.
Yours might not be this elaborate but there is the possibility.
Tom... :slight_smile:

Hi Tom, any suggestions are help! Even if they are a spanner in the works!

This piano isnt very high-end, just a 1980's good home electronic piano. I dont think it has velocity sensitivity, as I was given the "remains" of the keyboard today, and I can see that when the key is pressed, it just pushes a piece of copper onto a metal bar to make the connection. The keyboard has diodes on it, definately polyphonic.
If the lack of pins on a Uno is a problem, I have a a Mega and a Due sitting somewhere.

In reply to Paul,

Would it really be needed to find out how fast the piano scans the keyboard? I can find out the different combinations for the notes by shorting out the pins on the mainboard of the piano, so I think I've got that one sorted.

I only ever seem to use my arduino for detecting and generating square waves, so anything outside that is all new. Just a terrible excuse for my incompetence! :3
I also can't quote people on my phone.

Clym5:
Would it really be needed to find out how fast the piano scans the keyboard? I can find out the different combinations for the notes by shorting out the pins on the mainboard of the piano, so I think I've got that one sorted.

The point is - you are faced with either 61 relays, contacts, optocouplers or what-not, with a whole menagerie of components to operate these and emulate the original mechanical keys, or else you figure out how to make the mainboard think that those keys exist by determining what it is "looking" for as it scans, and feeding it a code for that moment (of scanning) which would correspond to a keypress - a virtual key.

To do this, you have to figure out (a CRO is useful, but this is digital, and an Arduino can be used to analyse patterns) what this scanning or "polling" looks like, to see whether an Arduino can be used to detect and respond to it in the necessary timeframe. Given that this is a "HID", it should be a relatively slow process.

Ah, alright. I'll get my oscilloscope out tomorrow and have a look at how it scans the keys. Thanks for all the help so far!