88 analog + 70 digital inputs but what hardware?

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
Hello,

I'm planning on a project turning old grand piano to a midi-controller. The hammers will strike piezoelectric sensors to get velocity and there will be switches in dampers to get note-off signals. Two pedals will also have optical sensors. The algorithm will be relatively simple, though some velocity curves might be needed. The output is a midi signal.

- each analog should handle ~20 samples per sec (maximum repetition on one key)
- multiple processing at same time (kind of "polyphony")

What hardware would be the best option to take the task without worries of failure in the most extreme circumstances that might happen while playing?

I like very much the simplicity of Arduino platform but the Mega has only 16 analog inputs. I have thought the following options with Arduino:
- Multiplexers (is it possible because can't read more than one at a time, though cycling speed can be fast?)
- External ADCs, (price? still need multiplexers to digitals?)
- Multiple Aruinos (too much hassle to synchronize? price high but acceptable)

What other solutions I have that could do this? The Raspberry seems to be even more inferior in the GPIO part but would there be some modules that could solve the problem? I'm also worried if the processing power in Arduino will be enough, because there might be a lot to process in a relatively short amount of time.

I'm quite newbie in all of this, so your help would save me many hours of research time or even bad investments. If I could decide the suitable platform, I could buy the parts for a few keys and start experimenting and then just expand to 88 keys. Many thanks!

Best regards,
Tuomas Alarotu
 

Papabravo

Joined Feb 24, 2006
21,225
Don't know if I can answer all your questions at once. For digital inputs you have two choices:
  1. Parallel In Serial Out (PISO) Shift Registers
  2. 2:1 Multiplexers with Tri-state outputs
For the analog inputs you could use external analog multiplexers. If the processor ADC lacks suitable number of bits, then external ADC with multiplexer and SPI interface would be my choice.
 

djsfantasi

Joined Apr 11, 2010
9,163
Sounds like an interesting project. Please amuse me by reading my brain dump.

Let's look at some of your requirements. 20 samples per second equates to 50ms per sample. Note that the Arduino actually internally multiplexes it's analog pins to one ADC. It is recommended that the program has delays around each read, to allow the ADC time to settle (reference here)

Now, if you're going to scan all 88 keys, that means that each read can only take 0.6ms in order to process 20 samples per second. Not a lot of time. I suspect you'll have to interrupt on a key press and then perform the analog read. Thus reducing the number of scans from 88 to a more reasonable number of keys that can be played simultaneously. Figure that to be closer to ten keys. Of course, if I were playing it would be limited to nine keys.

I didn't see in your description for detecting a key press. If there was one, you could use a shift register to read all 88 keys to see which have been pressed and which needs to read it's associated piezo sensor. Diode ORing all keys to a single output will also allow processing to occur on a pin status change interrupt. If you have multiple digital pins to spare, you could even break the keyboard into subblocks, maybe even octaves.

An external multiplexor/ analog switch is likely to be necessary. Perhaps some here could recommend specific hardware.
 

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
Thank you for your answers so far!

The 20 samples/sec per analog channel was just to confirm that it wont get jammed when playing one note in a fast trill. I think even the most professional pianists cannot produce that fast trill in real life but maybe something around 10/sec. Now imagine someone would do that simultaneuosly to all 88 keys, when we actually have only ten fingers! ;)

The fact, that Arduino is already using multiplexing, bothers me. Basically the pianist is aiming to play notes as simultaneus as possible, e.g while playing chords. In real life there might be some time differencies when we go to milliseconds or microseconds, but how much? I have found so far, that in acoustic piano, the hammer stays in touch with the strings about 2 ms (bounce effect). This is also the time when the analog signal is produced.

This makes me think, if Arduino is able to do this even for the 16 analog inputs, because there would be other signals coming when it's still reading the last one.

I have also no idea what is the 16 Mhz capable of, but I'm also conserned if the 256 KB memory will be enough for my code. It's very likely I need to calibrate every key individually, who knows even with unique velocity scale. That could easily mean few thousand lines of code? Does it even fit there?

Should I forget the whole Arduino? Or is there even hardware for the project in reasonable price range?

Best regards,
Tuomas
 

ErnieM

Joined Apr 24, 2011
8,377
Is 20 samples/sec enough? What about the skew you will have between keys?

If a chord is played you want all the notes to begin at the same "instant," plus or minus I don't know but it is a small amount.

As far as the processor goes, that is the end of the specification chain. Define needs first, then pick a device that can do that and a whole lot more, to account for not only feature creep but the things you don't know that you don't know.

I would build and test and debug a single key sensor before I go about building 88 of them.
 

djsfantasi

Joined Apr 11, 2010
9,163
I had a long post that disappeared, but here is the gist of it.

If you are looking at 88 keys all the time and even worse reading an analog value from them - you are going to be spending a lot of unproductive time.Also, as I noted in a previous post, a delay before and after an analog read is necessary to obtain true values. They used a delay of 10ms. However, if you were to treat the keys as a matrix (Arduino has a library for this) you can quickly scan for pressed keys. One such arrangement is to organize the keys in 6 groups of 16 (there is a method to this choice). Then, once you identify which keys have been pressed, you can quickly read the analog values. They are also organized in 6 groups of 16 to take advantage of a 16 channel demultiplexer such as the CD4067b. See this Arduino article http://bildr.org/2011/02/cd74hc4067-arduino/

Then, instead of 20*88 = 1760 analog reads/second, you are doing 6 digital reads and then up to 100 analog reads/second (or 9 if I'm playing :D ) The total number is likely less than 100, since it is unlikely that all 10 notes are being played in a trill. 100 * 10ms is one second! The maximum elapsed time you have. So your timings are going to be tight.

I had specific detail regarding the analog and digital pin requirements a solution like this would require, but as ErnieM noted - processor choice comes after design requirements. There are also I2C port expanders, such as PCF8574 I2C.

Hopefully, this post won't disappear. I present it not as a complete solution, but as a thought process to try and help.

http://playground.arduino.cc/ is a good reference for Arduino programming. Perhaps you can find some help there.
 

THE_RB

Joined Feb 11, 2008
5,438
Why re-invent the keyboard?

You can buy a MIDI keyboard that senses all keys for note on/off and velocity, and transmits simple MIDI serial commands.

Just the work of attaching and calibrating 88 piezo sensors and note off sensors is close to insane, never mind the hassle of getting it all wired and working in code.

Any MIDI keyboard will already do what you need. You can install it in a piano's housing if you like.
 

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
Many thanks again for your input guys!

Reading so many analog inputs simultaneuosly seems not that easy as I thought. Indeed, I need to think this more further and specify the exact requirements and then design the hardware that could do that, and last check the price tag if it's still doable.

At this stage, I think it should be able to read any 10 keys from the 88 keys simultaneuosly, which means there should be atleast 10 ADCs, and every channel could be directed to any of the currently available ADCs. Sounds complicated. Alternatively, there should be 88 ADCs, whichs is way too expensive, and comlicated also.

I have been thinking, why the digital piano manufacturers don't use piezo's in the models, that use real piano actions. Well, this might very well be the reason - because they want to keep it all digital! There might be other reasons also which I might come across later on the project, and which I'm concerned already. One of them is, that there is simply too much to calibrate, and that needs a lot of working hours, which adds the costs greater than the retail price for the manufacturers.

But adding all the optical sensors as a retrofit to a real piano action would not be that easy either. Anyway, I'm not giving up yet. But right now, I'll focus to get that old grand piano. I'll also have plenty of work in the piano itself, like renovating the action and modificating the cabinet. If the idea of piezo sensor system seems impossible, I can buy that ready product which uses optical sensors under the keys, which was my initial plan anyway. I just see that a bit inferior solution and I'm also keen to learn new stuff through this project.

Now the question, why to see so much trouble when there are ready midi-controllers in the market, goes to the same category, as why to learn piano playing when there are so many piano records made ready to listen. This is also a kind of purist thing, that the action must be real grand piano action, because none of those plastic keyboards doesnt really come close to the real thing. And actually, if you wanna buy something similar, which is a real grand piano action that sends midi out, you have only one option - The Yamaha AvantGrand N1. It costs 6,500 euros in my country, so there is a lot of reason also!

As an end note, I do this project because I like it and I'm sure I'll learn a lot of stuff even if the piezo system turns out to be not doable.

If you have more inputs to this input problem (what a great way to say it :D), please share!

Best regars,
Tuomas
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
...
I have been thinking, why the digital piano manufacturers don't use piezo's in the models, that use real piano actions. ...
...
1. Because piezos are unreliable when hammered over and over. They tend to crack and fail totally, or get partial fails where they no longer produce the right voltage for the strike force.
2. Because piezos wont provide the important key pressure information (MIDI "aftertouch"), piezos can only provide dynamic info at the instant the hammer strikes the piezo.
3. Because piezos would be difficult to use physically, compared to the small reliable resistive pressure sensors they all use in electronic keyboards.
 

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
1. Because piezos are unreliable when hammered over and over. They tend to crack and fail totally, or get partial fails where they no longer produce the right voltage for the strike force.
I have been also thinking about these issues, but then again, so many sources gives the understanding that piezos would be perfectly suitable for this purpose. Thus, I thought it would be better to go and try in few keys before extending to whole keyboard. Do you have any references for this, or can you share your own experiences that proves it would't work?

2. Because piezos wont provide the important key pressure information (MIDI "aftertouch"), piezos can only provide dynamic info at the instant the hammer strikes the piezo.
3. Because piezos would be difficult to use physically, compared to the small reliable resistive pressure sensors they all use in electronic keyboards.
These two issues doesn't fit to the models of digital pianos that use action from real acoustic pianos. As far as I know, they use these slot type optical sensors in the hammer shanks, giving position over time so velocity can be calculated. They also need other sensors to make the whole system to work. But replicating these type of sensors as a retrofit, would be very difficult and way too much work. But, because the technology is mature and it works, it's already a reason for the manufacturers not to invest in R&D.

Please continue giving critics toward this project. I'm very newbie in all of this and I'm humble to listen the experiences from all of you.

Best regards,
Tuomas
 
Last edited:

takao21203

Joined Apr 28, 2012
3,702
you could use several slave controllers, and for instance, a 4bit bus for the data (shared), as well an address bus. For 16 slaves you also need 4 bits.

You also need a RDY line and a CLK signal.

then you can transfer data with a few MHz in 4bit slices.

For instance use 8bit PICs to sample the data, and PIC32 as master controller.

yes piezos do produce voltages even if they are just tapped slightly, but the dynamic range might be a problem. You get a fraction of one volt when tapping, and several volts when really striking them (preferably on the backside).

You either need to use a limitation, or you can't sample small voltages accurately.

Unless the force applied to them is too strong, they wont become damaged at all.
 

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
you could use several slave controllers, and for instance, a 4bit bus for the data (shared), as well an address bus. For 16 slaves you also need 4 bits.

You also need a RDY line and a CLK signal.

then you can transfer data with a few MHz in 4bit slices.

For instance use 8bit PICs to sample the data, and PIC32 as master controller.
But for example Arduinos have only one ADC and they use multiplexing. Now when I have been thinking this more again, I do want it to be possible for every key played simultaneuosly, i.e. every key has ADC behind them.

What if I would use 11 of these converters? Total price would be 188 USD, it is acceptable but ofcourse I try to keep the costs in minimum.

Can someone clarify, how would the connections be made with Arduino? It has SPI, can I plug multiple of these to one Arduino?

Coming this far, I could as well make custom controller. However, I'm going to do prototyping with Arduino platform, and if I could just copy paste my code with minor changes in inputs etc. to the final system, that would be great.

I'll go to take a look at one grand piano tomorrow which could be let off for free. I hope it will turn out well so the project may start already! :)
 

david.g

Joined Jul 5, 2014
1
For connections, if you look on page 21 of the data sheet of the chip you linked to, it shows how to daisy chain the ADCs so that you only need to use one spi connection to the Arduino. There is a data in port that is only used for the daisy chaining by hooking it to the data out port of the next one, so the output of one will be sent to the next one. This should make your connections fairly easy.
If you start with one chip connected, that would allow you to test everything before you connect all of the chips, and it should be simple to change the code to include the additional chips by reading more data coming through.

David
 

Thread Starter

Tuomasa

Joined Jun 25, 2014
6
Hello folks!

The project got started a couple of weeks ago when I found appropriate grand piano for this. It's a Russian grand piano from somewhere ~1900. However, it has a nice European made modern action and long keys as the piano is around 200 cm long, and not those short sticks found in baby grands.. Acoustically it's not that good, so it's perfect for this project as I don't need to feel bad cutting it half ;)

I have been experimenting with piezo sensors about a week now, using an oscilloscope. I have tried various mounting types and materials, and finally it is starting to look good. With current mounting type it is really sensitive, yet giving just a bit over 5 volts when hammering hard. I use Schotkky diodes to take out negative volts and a Zener diode to cut it in 5 volts. Now I'm experimenting with different combinations of resistors and capacitors to get a nice curve that is ease to read for ADC.

The readings looks pretty reliable and constant, but I'm still not totally convinced about using the piezos, because it involves so many variables, some of which might change during time and not easily controllable. However, I already played one note with Pianoteq, using Arduino Mega to process the signal and midi. It had also dynamics already, and it worked pretty well, but still need adjusting in the velocity curve. Thus, there might be a hell a lot of work to calibrate all 88 keys, just as I thought. However, the feeling when I played the first note was simply priceless! I had to take off headphones to check if the sound is really coming from the software or from the piano! :)

Questions:

Could you guys please help me starting to design the needed hardware? I'm totally lost in all these terms and entering a whole new world.

Let's assume I would use the above mentioned Texas Instrument ADS1178, 11 of these so every key has own converter.

The maximum sample rate is 52kSPS, and I have found that it would be just perfect to detect the peaks. The ~10 kSPS the Arduino is capable, is just slightly too low, missing the peak values sometimes, as the real peak might be between the samples.

So if the ADC is 16 bit, 52 kSPS, one channel needs 0,832 Mb/s? All 88 needs then ~74Mb/s?

I guess it is even more if the 16 bits contains only the numerical value and not the channel it came from etc??

Now, what kind of hardware can handle this and not costing thousands? Even if the ADCs could be connected nicely with daisy chaining, I still need two extra analogs for pedals, and 88 digitals for damper detectors.

Please help designing the possible hardware provided with some calculations, I'm totally lost in this. It might also be reason to ditch the piezos, if the needed hardware would be too expensive.

Best regards,
Tuomas
 
Top