Sunday, 5 June 2016

Converting an upright piano to an electronic midi piano

The Manchester Hackspace has recently moved.  When the move occurred there were two old upright piano fortes found in the corner of the new place...I asked to keep them!  I have been meaning to attempt a conversion from an acoustic mechanical piano to an electronic one for a very long time. Tuning my old walnut cased iron framed piano is becoming too difficult.  I miss being able to play in tune and with other instruments.  I also seriously miss being able to compose music and I used to use midi extensively to achieve that.  I haven't the space to write, play and record every instrument....so instead I used to use midi software on an external computer and have that record, notate and sequence the different parts to make create my opus!  Years ago I had access to an Atari ST 520FM which had built in midi ports - it made this very easy, I also had access to a Clavinova CLP-360 Yamaha electronic piano.  It was awesome and I miss it dearly...

So rather than let my creative talents go to waste I plan on tuning one of the pianos up as much as possible and restoring it to as near working condition as possible.  This can then be kept for posterity or donated to a worthy cause...It was looking a little shabby when I found it but I have cleaned it up and opened up the panels:

Here are some photos of the piano:

A classic Upright Piano with the covers off!

The iron frame and the strings

The pedals, the sustain has definitely seem some action!

Another side shot of the slightly...better piano!

There are actually two pianos physically they look very similar but one was in much better shape than the other.  Here is a video of the better one...One of the D flat keys does not have a bridal strap and so won't play or return.  I'm going to replace that strap but other than that it's got a nice action and is very easy to play...better than my own!  It was however horribly out of tune...


I have a piano tuning kit I bought off ebay for doing my own tuning so I broke it out and set to it. Tuning a piano is an art...it's difficult and takes skill and practice.  I did get it mostly in tune, some of the higher and lower notes beat me and I will spend a bit more time on it.  I am jealous of how easily played this piano is...my own keys are much stiffer and harder to play...mine also is in B flat...this piano tuned to A (440 Hz) without too much issue.

Here is the piano now tuned...hopefully it sounds better! EDIT - I haven't got a video of the tuned piano to share yet - I will upload one soon.  The internet needs more of my poor piano playing skills shared!


The plan with other piano is to remove the hammer action and strings and place some sensors underneath the keys. The sensors will connect to a microcontroller which will then send out midi data which can be used to drive a midi based synthesizer which will in turn be connected to an audio amplifier and a couple of speakers mounted inside the cabinet. The benefits of doing this are:

  • The piano will always be in tune!
  • A midi synthesizer can produce thousands of different voices - a whole orchestra and more!
  • The piano can be used as a midi Jukebox and a band in the box.
  • It is a great excuse to investigate touch pressure sensor technology.

Here is the current plan in a diagram


There are many aspects and parts to the project which will need careful thought and consideration.  I don't want to lose the piano's playability. If I remove the action - the mechanical part of the piano which converts the key press to strike a note the piano won't play as well. Here is a video I found on youtube which shows how a piano key functions:


I think in order to make this work it will be necessary to add a spring mechanism to where the key would normally pivot the action mechanism to get the key to return to it's original position. I am not great at mechanical engineering - here is my chance to improve!

It will also be necessary to sense the note being played. Most electronic pianos have a maximum number of keys being able to be played at the same time - this is known as polyphony.

An explanation on Note Polyphony

It would be nice to be able have at least a 32 note polyphony without any noticeable lag or delay. I'm not going to be playing pieces like this but being able to play 32 notes a once puts this device in the category of a reasonable electronic piano.

https://en.wikipedia.org/wiki/Two_hundred_fifty-sixth_note

So lets recap the requirements of the input section:

  • Sense at least 32 simultaneous key presses
  • record how long each note was held for 
  • record how hard the note was pressed

To do this we will need a pressure sensor which can easily be built and placed underneath the key of the piano.

I recently took some inspiration from this project:

http://liamtmlacey.com/vintage-toy-synthesiser

Liam used a sensor material known a velostat. It is a very interesting material which converts pressure into an electrical signal - it's electrical resistance changes as pressure is applied. I bought some from Proto-Pic

Velostat from Proto-pic

My plan is to combine the velostat into a simple resistive divider circuit which is then connected to the analogue input of a microcontroller and use this to 'sense' the note or notes being played.

A piano has 88 keys! If we want to sense them being played we need a way of reading in 88 analogue inputs. An arduino has six analogue inputs....an arduino mega has a few more but still not enough! We could use multiple microcontrollers but that makes things awkward and expensive as we need to then to synchronize them all...yikes!

I think this will require some analogue multiplexing in order to work well and not be overly cumbersome....I looked at a couple of the analogue multiplexers available and settled on this one:

74HCT4067 - Analogue Multiplexer

It's basically a single throw sixteen throw switch which can be controlled by a microcontroller. There lots of breakout boards available on the internet. I bought this one:

Ebay shop - 74HC4067 breakout board

I haven't used it yet....my first plan is to test and model the analogue input stage...then connect it to the multiplexer and then use that to scale up for 88 keys.

In order to make this work we will need a lot of multiplexers:

88 keys / 16 channels = Number of multiplexer devices needed

therefore 5.5 devices (six) in reality.

Before that we need to make a sensor measurement stage.  I've decided to use a buffered simple resistive divider circuit:

The Sensor Measurement Stage
The above circuit is an approximation of how the electronics will read a key press.  The circuit functions as follows:

The momentary switch and the 10 kΩ potentiometer model the behaviour of the velostat material. I don't have much information on the resistivity of the velostat but I have tried it and I do know that it's resistance does vary with pressure - I measured it with a multimeter. The resistor R1 makes up a voltage divider circuit. When the piano key is pressed the resistance of the velostat changes which is detected by the LM358 Op-Amp. The resistor R5 and the capacitor C1 make up a low pass filter. It might not be necessary but I'm trying to ensure that no external electronic noise is presented to the op-amp. I only want to measure key presses, nothing else. The first op-amp is configured as a non-inverting amplifier with a gain of two. The 100 pF capacitor limits the bandwidth of the op-amp restricting it's operation to low frequencies, another way to limit noise being passed on to other parts of the circuit. The second op-amp stage is again a simple non-inverting op-amp stage with a gain of two. The output signal presented to the next stage will be between zero and three and a half volts. That should be more than enough range present to detect key presses with good sensitivity. The output will be connected to an analogue to digital converter which will probably be a ten bit ADC integral to the microcontroller. The op-amp is an LM358 but just about any op-amp will do for this circuit...There is nothing inherently special about that component. The circuit has been simulated connected to an oscilloscope. Here is the output:

The oscilloscope output - the pulses represent a unique keypress

The simulation appears to work perfectly which is always good...This circuit will have to be reproduced eighty-eight times so we will need to design a small and easy to build circuit.  For now I'm going to make a though-hole version because it's easy to prototype.  Once I'm happy everything works I will probably make a sixteen input version which will be connected to the analogue switch.

The Schematic of the key press circuit
I added an LED because I think it would be nice to see when the key has been pressed without having to attach it to a measurement device like an oscilloscope. It makes it easier to test the circuit. I also added a screw terminal to input the power - nearly forgot that.

The Top Layer of the PCB
The bottom Layer with dimensions in mm

Just for fun here is the circuit rendered in 3D:

ISO render of the populated PCB

Top render of the populated PCB

If the circuit works as intended I will re-engineer this board with surface mount components to reduce the physical size of the board and have eighty-eight boards made...

Here is the parts list for the key press circuit:

QtyValueDevicePartsDescriptionFarnell CodeUnit Price (£)Cost for Circuit (£)
1N/A5 mm LED - RedLED1LEDs23357250.0510.051
1100 pFCapacitorC225 V Ceramic Capacitor11417650.07090.0709
610 kΩResistorR1, R2, R3, R4, R5, R65% 1/4 Watt Carbon Film Resistor23294740.0240.144
210nFCapacitorC1, C325 V Ceramic Capacitor12164350.2750.55
1220 ΩResistorR75% 1/4 Watt Carbon Film Resistor23298990.0370.037
1LM358Dual Operational AmplifierIC1Jellybean op-amp22959800.340.34
3N/A5 mm Screw terminal connectorJP1_SENS, JP2, JP3_POWERStandard 2-pin 0.1 pitch24936140.160.48
12N7000N Channel MOSFETQ1_2N7002Jellybean N-Channel MosFET98451780.1580.158
Total in £1.8309

Not too bad at all...It does not take into account the cost of the PCB or my time building and testing the circuit.  I intend having the PCB for the surface mount version made professionally - eighty - eight times so that will cost a little more!

That's all for now - next post on this will probably show the board in operation and a prototype key press sensor:

http://langster1980.blogspot.co.uk/2016/06/designing-pressure-sensor-using-velostat.html

No comments :

Post a Comment