Using piezo elements for a synthesizer pressure sensor - Page 1
Forum section: electronics / projects

author: Deactivated-1
author_rank: Frequent Contributor
timestamp: June 19, 2022, 03:37:59 pm
content: I had an idea of using piezo discs together with the hammer mechanism from an upright piano.but I have 2 questions:1. would the piezo elements shatter from the hammer force?2. what would be the best way to handle the key muting? because the hammer only hits the string on attack, and not again, muting the strings is handled by another level that presses a piece of foam on the strings, do I use toggle switches? magnetic sensors? cost is key, but I want it to be somewhat reliable too.( parts need to handle a LOT of force since I'm into rock n roll)

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 19, 2022, 04:05:27 pm
content: Look into analog HAL effect sensors. Mount a magnet somewhere underneath the key or on the hammer and use a MCU with an ADC to convert the readings.Used this technique long time ago on a bass recorder. Worked the HAL effect sensors into the body of the flute and glued the magnets to the valves. Worked like a charm.

author: Marco
author_rank: Super Contributor
timestamp: June 19, 2022, 04:28:31 pm
content: Quote from: ELS122 on June 19, 2022, 03:37:59 pmA small piezo disc backed by foam? Unlikely.QuoteI think you are approaching this from the wrong angle, first decide how you do the proportional measurement. Then if that is accurate/fast enough to detect a quick touch, there is no need for the piezo. How do normal synth keyboards do it?BTW, I doubt you are the first person to convert a normal piano into a synth keyboard. It's boring, but you can look up how other people did it.

author: Benta
author_rank: Super Contributor
timestamp: June 19, 2022, 06:36:55 pm
content: Quote from: pcprogrammer on June 19, 2022, 04:05:27 pmDo you mean Hall sensors?I don't see how that would work. I presume that the idea here is to measure the "heaviness" of the key stroke, and Hall sensors won't do that.Magnets on the hammers and static pick-up coils would, though. The speed of the magnet passing the coil will influence amplitude. Simple peak-detect circuits or ADC processing can easily handle that.But all in all, the Piezo idea is probably better.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 19, 2022, 07:16:30 pm
content: No an analog HAL effect sensor gives a varying signal in respect to the magnetic field. The closer the magnet comes the voltage will near its limit.https://www.instructables.com/Using-Analog-Hall-Effect-From-37-Sensors-Kit/With the changing voltage it is possible to distill the speed (velocity) of the key, and it is also possible to scale a range for after touch. Done this with a 8051 type of micro-controller in the late 80's early 90's, so with modern MCU it should work easily.

author: Benta
author_rank: Super Contributor
timestamp: June 19, 2022, 07:30:56 pm
content: I still don't know what a "HAL effect sensor" is, but perhaps my Google-Fu is weak.But yes, computing the derivative of the output from an analog Hall sensor/element with a magnet passing by would indeed give an idea of hammer speed.

author: Marco
author_rank: Super Contributor
timestamp: June 19, 2022, 08:03:31 pm
content: Quote from: ELS122 on June 19, 2022, 03:37:59 pmI needed to look up how a piano works to answer this, I never knew ... so I suppose you mean the damper connecting to the string? (Or in your case probably a piece of wood where the string would have been.) I'd say the obvious way is capacitive, more reliable than relying on closing a direct electrical connection. Put a piece of copper foil with some tape insulation on the damper, where the string would be put two slightly separated pieces of copper tape with wires attached, the damper will capacitively couple the two pieces of copper, you can detect that.As for the piezo, it would take some R&D to determine a mechanism based on a piezo to determine velocity from the piezo response. It would be all to easy to just create a system where the response would easily saturate. It's hard to calculate anything from first principles, this would have to be designed experimentally.With an analogue hall sensor embedded into wood where the string was and a small disc magnet on the hammer, it will be easier to design from first principles and datasheet.PS. there is not a lot of room in between the hammers to put a sensor, that's why I suggest putting them below where the string was. You can still determine speed using the differential of the sensor output when it's very close, just before it strikes.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 20, 2022, 04:05:14 am
content: Quote from: Benta on June 19, 2022, 07:30:56 pmhttps://en.wikipedia.org/wiki/Hall_effectAs it was so long ago (and yesterday near my bed time) I forgot the second "L" in the term HALL effect, but googling "HAL effect" gave me the link above and the "results included for HALL effect" statement.There are basically two types of HALL effect sensors that I know of. Switching ones and analog ones. With the analog one it is possible to measure the strength of the magnetic field.Search for "analog hall effect sensor" or "linear hall effect sensor" with either "hal" or "hall" and you will get plenty hits.A switching one is digital and tells you if a magnet is close enough to make it toggle it's output. (Edit: fixed the magnateinto magnet)https://en.wikipedia.org/wiki/Hall_effect_sensor

author: Fredderic
author_rank: Regular Contributor
timestamp: June 20, 2022, 08:22:49 am
content: Quote from: pcprogrammer on June 20, 2022, 04:05:14 amIt's a device that senses the size of the users bank account…?Or are you just still tired…?

author: RoGeorge
author_rank: Super Contributor
timestamp: June 20, 2022, 09:18:47 am
content: If the mechanism is like this then optical sensing might be easier.For example, place reflection sensors behind each key, and a shiny surface of the end of each key. This way would be possible to sense both the timing and the force by how fast the reflected light vanishes. Use modulated light for reliable detection.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 20, 2022, 09:43:41 am
content: Quote from: Fredderic on June 20, 2022, 08:22:49 amWell it was early in the morning and it is not my native language so I'm bound to make mistakes, but for that matter I also make this kind of f..up's in my own language. With ageing, seclusion and chronic fatigue syndrome things tend to slip. Used to be a perfectionist

author: Marco
author_rank: Super Contributor
timestamp: June 20, 2022, 03:29:51 pm
content: Quote from: ELS122 on June 20, 2022, 08:27:06 amIt wouldn't be a problem perse, it would just be experimental.With a magnet on the hammer you can make relatively accurate guesses at magnetic flux density for a given distance from magnet to sensor and the output, before you put anything together.

author: S57UUU
author_rank: Regular Contributor
timestamp: June 20, 2022, 03:33:33 pm
content: Old electronic keyboards simply used a SPDT switch, and measured the time between opening of pole 1 to closing of pole 2, which is inversely proportional to how hard you hit the key. Can be done in analog way too, with a RC circuit connected to the center contact, pole 1 to +V, pole 2 is output. When pole 1 opens, the capacitor starts to discharge through the resistor. When pole 2 closes, you get the remaining voltage. A heavy hit on the key will leave less time for discharge, producing a higher pulse on pole 2.Marko Cebokli

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 20, 2022, 04:44:51 pm
content: Quote from: ELS122 on June 20, 2022, 08:27:06 amWhen on/off is all you want then the simplest solution is just a switch underneath the key and scan that with a MCU, old fashioned matrix style. Include a diode to avoid cross talk.Or when you don't want electrical contacts use a digital HALL effect sensor. Needs a lot more io pins, but so would your piezo idea.

author: Marco
author_rank: Super Contributor
timestamp: June 20, 2022, 04:53:34 pm
content: I don't think you'll be able to preserve the feel of the piano keys and pedal with switches.

author: tooki
author_rank: Super Contributor
timestamp: June 20, 2022, 07:35:24 pm
content: Quote from: pcprogrammer on June 20, 2022, 04:05:14 amFYI, the reason that HAL doesn’t always get flagged as a typo is that HAL is also the abbreviation for a design concept called a “hardware abstraction layer” (it being an initialism that’s why it’s all-caps). Well, that and the computer in 2001: A Space Odyssey! The Hall effect (capital H only), on the other hand, is named after a Mr. Hall.

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 08:01:41 pm
content: Quote from: pcprogrammer on June 20, 2022, 04:05:14 amNo. There are different technologies for making Hall sensors, but that's not the distinction.There are basic Hall sensors (the sensing element alone) and integrated Hall sensors (the sensing element plus additional processing).The additional processing can be any number of things: amplification, amplification+filtering, additional digtalization (1/0 outputs), on top of that A/D conversion, and, and, and."If you're in a hole, stop digging". HAL in "2001, a Space Odyssey".

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 20, 2022, 08:19:09 pm
content: The "easy" part for implementing synth keyboards is to measure velocity. That's the most commonly implemented feature even on cheap ones, and all it requires is a way to determine the speed with which some key has been pressed or released - can be Hall sensors, optical, or even purely mechanical with two microswitches per key.But key velocity and key pressure are two different things. While the former is usually enough to give a sense of how hard the player hits a key, sensing pressure is another parameter than can be useful too and is usually found on more expensive keyboards.Now for the OP, make sure you already figured out that velocity only was not enough for your needs before embarking on something more involved.I'm trying to think of a reliable, yet affordable (since you'd need one sensor per key) solution for sensing key pressure. Not completely trivial, will chime in if I get ideas.

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 08:45:04 pm
content: Quote from: SiliconWizard on June 20, 2022, 08:19:09 pmI'm with you most of the way here, but piano keyboards are a bit different. Pressure is not really a thing.The key hammer hits the strings and then rebounds. Pressure against the strings would just deaden them. The hammer impact force on the string controls amplitude, which can be translated to hammer speed.Now you could certainly add one more sensor per key to detect pressure, but that's a bit out of scope here, I think.

author: jonpaul
author_rank: Super Contributor
timestamp: June 20, 2022, 09:08:47 pm
content: Bonjour cher Monsieurthe key volocity was solved in 1970s, two mechanically displaced contacts, time differenceSee work at Yamaha and Bob Moog decades agoRecent developments in pressure sensitive matériel led to fine controls of keyboards at low costs.The materials are proprietary.... many patents are pending or grantedA bit of searching should solve the problemBon chanceJon

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 20, 2022, 09:34:09 pm
content: Quote from: Benta on June 20, 2022, 08:45:04 pmYou're right about hammer action on a piano. I'm just guessing measuring pressure upon impact could be useful or interesting, but I'm not sure at all. Just measuring velocity and implementing a model of the hammer in software from velocity might be good enough, if not better, indeed.

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 09:46:48 pm
content: Quote from: jonpaul on June 20, 2022, 09:08:47 pmThe OP is talking about using an existing piano for a synthesizer keyboard. What are you on about?And why do you think we are "monsieurs"?

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 09:58:06 pm
content: Quote from: SiliconWizard on June 20, 2022, 09:34:09 pmAt least, it's an interesting intellectual exercise.On the economics, I'm not so sure. 88 magnets and 88 sensors, plus an 88-channel pre-processing/multiplexing front-end.The DSP/MCU combo will be the cheapest part, I think.I hope the OP comes back, it'll interest me a lot what comes out of this.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 20, 2022, 10:14:44 pm
content: I'd probably go with optics for sensing velocity. In any case, for sensing velocity you'll need two sensors per key (unless it's not just on/off sensors, but some kind of distance sensors, which would be more expensive), that's 176 of them...

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 10:32:04 pm
content: Quote from: SiliconWizard on June 20, 2022, 10:14:44 pmWhy?Two options:1: a magnet passing a pick-up coil. This will give you the hammer velocity directly as a voltage level. Post-processing can evaluate the player's attack/decay handling of the played key. But it'll give no static position information.2: a magnet passing a Hall sensor. This will give you the hammer velocity by extracting the derivative of the output, and by intelligent placement also the position of the key (eg, is it in neutral/untouched position?).Simple. And expensive.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 20, 2022, 10:45:02 pm
content: My answer was not detailed, but I did mention that you'd need two sensors if those were only on/off sensors. And that's the most common implementation (because cheaper and more accurate) I've seen on keyboards.You could do as you suggest but it would be less accurate IMO and probably more expensive if you manage to design something accurate and not requring any calibration.

author: Benta
author_rank: Super Contributor
timestamp: June 20, 2022, 10:57:15 pm
content: Why do you go off on a tangent like this?The OP wanted to use an existing piano keyboard.Using its existing mechanism.The option of designing an own keyboard or how a cheap Farfisa one is made is not even in the discussion.

author: SiliconWizard
author_rank: Super Contributor
timestamp: June 20, 2022, 11:18:07 pm
content: There's no tangent. I'm just saying how this is usually done, and measuring time between two on/off sensors at a fixed distance is much easier and accurate (and likely cheaper.) And equipping existing pianos with such detectors for "midifying" them is actually a thing. While I haven't looked at the existing kits for this, I'm pretty sure most of them work as I suggest.Point is again, IMHO the kind of single-sensor solution you suggested will probably require calibration if you want something similar from key to key, while timing doesn't require any.Now feel free to prototype anything else, to me the "tangent" would be to suggest something to the OP that would be trickier to get to work than what is usually done.

author: Marco
author_rank: Super Contributor
timestamp: June 21, 2022, 12:06:41 am
content: There's not a lot of room in between the hammer mechanisms to put sensors.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 21, 2022, 04:33:57 am
content: Mechanics aside the analog/linear hall effect sensor solution where it is placed underneath the key is capable of doing both velocity and pressure. But SiliconWizard is right that it needs calibration.The way to do it is to determine voltage levels on which to switch state giving it three states. Assuming voltage reading is low when key is upLevel < x, key is offLevel > x and level < y, key is on the move so measure the time until onLevel > y, key is on and pressure reading becomes activeI have done this in the late eighties when I worked at STEIM in Amsterdam. See:https://www.recorderhomepage.net/history/innovations-in-recorder-design/and search for Michael Barker. I still have "analog" pictures of this project somewhere, but would need to dig them up.I don't know what the relation is in an actual piano key between the velocity of the hammer and the down ward motion of the key and if it makes a lot of difference in sensing the motion of either the hammer or the key to determine velocity, but I would use the underneath the key option. Feels simpler to implement.For pressure Yamaha used to use a single bar of material where the resistance changes with pressure. It was placed underneath the keys and resulted in channel pressure and not after-touch. Meaning a single reading for the whole keyboard versus a reading per key. How modern day keyboards do this I don't know. When it is done with some pressure sensor this would most likely also need calibration of some sort.

author: jonpaul
author_rank: Super Contributor
timestamp: June 21, 2022, 06:59:19 am
content: Cher Monsieur bonjour (tp Silicon Wizard in France)Yes existing keyboards can be retrofitted with various pressure sensitive material, and avoiding the cost, complexity and extra space needed if separate switches or other Sensors were fitted.One can imagine a long sheet of sensitive material printed so each paino key is checked for pressures, duration time of strike, etc. with a multiplexing controller.This would seem to be a practical solution for a production keyboard. Perhaps someone in our clever group can DIY a similar keyboard.CordialementJon

author: BrianHG
author_rank: Super Contributor
timestamp: June 21, 2022, 07:11:35 am
content: Laser scanner trigger system on the hammers?Something like 1 scanning laser & MCU for every 8-16 hammers with velocity and sustain reading.I heard of such scanners for MIDI harp interfaces.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 21, 2022, 07:56:16 am
content: Sure buying a normal synth is easier and maybe cheaper but where is the fun in thatAn option for working with the piezo element is to not use the peak detector but read the levels with an ADC on a MCU. ARM-Cortex devices are fast enough to handle multiple channels and in the code you can derive both velocity and on state of the key. The off state can't be determined because the hammer bounces back after the strike, so you still need another way to detect the release of the key.

author: RoGeorge
author_rank: Super Contributor
timestamp: June 21, 2022, 07:56:36 am
content: Quote from: ELS122 on June 21, 2022, 07:33:54 amIt would be cheaper anyway, and also more reliable, to buy a MIDI keyboard or a full synth than to convert the mechanical piano keys, no matter what sensors you'll use.The main advantage of the piano would have been to preserve the feeling of pressing a piano key, which feels different to the touch than when pressing a MIDI/synth key.If you buy a new keyboard, preferably choose one with velocity and after touch capability, the cheapest ones only have on/off. Unless you want to make a carrier out of this, for a beginner on/off keys are usually enough.

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 21, 2022, 09:44:39 am
content: There are a couple of ways to approach the multiplexing to reduce the needed number of I/O pins.Get a bunch of 74HC4051 or CD4051 and make an analog multiplexer to bring down the number of piezo lines connected to the MCU. The problem here might be the scan speed becoming to low, because you have to sample more separate signals with few ADC'sGet a bunch of cheap MCU's with multiple ADC's and analog input channels and connect the MCU's in a serial chain. The last MCU can spit out the MIDI and the others generate and pass through the data on a higher speed.

author: tooki
author_rank: Super Contributor
timestamp: July 12, 2022, 11:02:30 pm
content: Quote from: Marco on June 21, 2022, 12:06:41 amIndeed. That’s why the best digital pianos (the kind where the entire key and hammer mechanism is present, just without any strings to hit) use fiber optic optocouplers to detect speed. Yamaha’s uses 4 per key IIRC.