Connectivity Issue: Teensy 2.0 MIDI Drum Triggers (Piezo) - Pure Data - MobMuPlat

Status
Not open for further replies.

dr_d_nice

Member
Hello PJRC Community,

I have been spending the past few months building a .WAV sample play-back system for my band / tinkering interests.
The .WAV files are played using Pure Data. →https://puredata.info/
I am able to run Pd on both my laptop running OSX, and my iPhone 6 running the latest iOS. I am using MobMuPlat to run Pd on the iPhone. →http://mobmuplat.com/

I am using Teensy 2.0 as a MIDI controller.
inputs: 4x arcade buttons, 4x piezo-elements (drum triggers)
outputs: 12x 5mm LEDs

20160127-pedal-schem-001.jpg
(there is a pdf version of the schematic also attached)

The Teensy interacts very simply with Pd, or that's the idea.
The Pd patch receives inputs from both the Aarcade Buttons and Piezo-Elements, which cues different .WAV files and LEDs to turn on/off.
Each song contains a different combination of WAV files and action/reactions to I/O from the Teensy.

The issue:
Mid-song, Pd and Teensy lose connection with one-another.
Unplugging the USB connection between Teensy & Macbook/iPhone get's things working again.

Teensy does not lose power in these moments, but more so seems "frozen".

Edit 2016-01-28:
If any LEDs are on when Teensy freezes, they will remain on, however the device is no longer able to communicate with Pd.


I have also attached my sketch. I believe there are some fundamental coding concepts missing from my Teensyduino sketch.
Currently I am using the Bounce objects for the Arcade Buttons and Piezo-Elements, seems to work fine for my purposes, as the Piezo-Elements should read 0 or 1. My Pd patch only "cares" about switches going from 0→1.

Another note on Piezo-Elements:
I am using a simple RC high-pass filter with each of them. I don't think this is enough. I read the following article yesterday and am very interested in modifying my Piezo circuits to match. The circuit uses 2-diodes, a resistor and capacitor to limit the peak voltage, decay time of each transient and also make the piezo's outputs "all-positive".
Link Here


All comments and advice are welcome, thank you!


Here are some photos of the "footswitches". I have built 2, they're basically identical and I am having the same issue with both.


IMG_0877.jpg

IMG_0878.jpg

IMG_0879.jpg

IMG_0880.jpg

IMG_0881.jpg

on left: 3D printed drum trigger mount for snare (spring actuated)
on right: piezo-element sealed in heat shrink with 6.35mm jack
IMG_0882.jpg
 

Attachments

  • 20160127-pedal-schem-001.pdf
    132.5 KB · Views: 318
  • _20160124-teensy-MIDI-footswitches-005.ino
    6.2 KB · Views: 364
Last edited:
What sort of voltages are the pizeoelectrics producing?

You should at least remove the negative component with a diode and ideally cap the voltage to 3.3V with a zener

EDIT-
Your code looks pretty solid and I can't actually see any thing wrong with it.. Hopefully someone can interject.
A quick few optimisations though:

Code:
// define Control Value relationship with LED
void OnControlChange(byte channel, byte control, byte value){

	switch (control) {
		// red LEDs MIDI Out: 11, 12, 13, 14
		case 11:
			digitalWrite(red1, value);
		break;

		case 12:
			digitalWrite(red2, value);
		break;

		case 13:
			digitalWrite(red3, value);
		break;

		case 14:
			digitalWrite(red4, value);
		break;

		// green LEDs MIDI Out: 21, 22, 23, 24
		case 21:
			digitalWrite(green1, value);
		break;
		case 22:
			digitalWrite(green2, value);
		break;
		case 23:
			digitalWrite(green3, value);
		break;
		case 24:
			digitalWrite(green4, value);
		break;

		// white LEDs MIDI Out: 31, 32, 33, 34
		case 31:
			digitalWrite(white1, value);
		break;
		case 32:
			digitalWrite(white2, value);
		break;
		case 33:
			digitalWrite(white3, value);
		break;
		case 34:
			digitalWrite(white4, value);
		break;

		default:
		break;
	}
You'll find similar alterations can be made to loop().
The effects are minor though, I doubt this is causing any issues

EDIT- EDIT-
Configure an LED to blink at the end of loop(). If it stops blinking you'll know your program has frozen and we can work from there
 
Last edited:
Xenomar, thanks for your reply.

Last night I stayed late at work to use the scope. I took several readings with different circuits.
See the attached pdf.
View attachment 20160129 Piezo-electric Circuits - Signal Conditioning.pdf

Sample Images from the attached pdf:

summary.png

example.png


Readings 16-18 show the voltages that my current Piezo circuit is producing. Ranging from 8.9v~18.65 (max p2p = 25.4v).
Probably not good.

Using a 5.1v diode kept the voltages below 4v. I am happy with that, but it wouldn't be a problem to get 3.3v diodes.
That's fixed.

Next, I would like to choose RC values to get the decay time down to < 5ms. My current circuit is a High Pass filter, which seemed to have the shortest decay times, but adding the diode bumped the decay times up a bit.
The plan is to calculate appropriate RC values by revisiting my system dynamics notes from college.

I also discovered a post by Paul, who I believe is Mr. PJRC, that uses an Op-Amp to condition piezo-electric signals. Here's the link.
I'd like to see the peak voltage and decay times from this circuit.
 
It's refreshing to see such well documented research!

I also discovered a post by Paul, who I believe is Mr. PJRC, that uses an Op-Amp to condition piezo-electric signals. Here's the link.
I'd like to see the peak voltage and decay times from this circuit.
The peak voltage will be what the Op-amp can output. Powered by +5V it's most likely around 4.2V, it depends on the op-amp. (as always check the datasheet)
I'm not too sure about the decay time but I imagine it'll very small.

The circuit works by storing the peak. Once you've read it you discharge the capacitor so it is setup for another reading.

Do you want to determine the strength of the impact on the piezo? If so this method would work well, just tweak the circuit gain to get what you want.


If you think about that RC circuit you built with the zener the time constant can be reduced by either making R or C smaller. I recommend you do the prior. Try something like 1k or less.
If you have a 1k or 10k pot use that so you can find that sweet spot you want.
You can try this for both the highpass and RC circuit
 
Last edited:
It's refreshing to see such well documented research!

Thanks! It was valuable research to this project. I have had a hard time finding o-scope data for piezo-electrics. Especially piezo's used in DIY MIDI drum projects, hopefully others can find it useful. However the popularity of this thread makes me think not many will benefit from these efforts.

The peak voltage will be what the Op-amp can output. Powered by +5V it's most likely around 4.2V, it depends on the op-amp. (as always check the datasheet)
I'm not too sure about the decay time but I imagine it'll very small.

The circuit works by storing the peak. Once you've read it you discharge the capacitor so it is setup for another reading.

Do you want to determine the strength of the impact on the piezo? If so this method would work well, just tweak the circuit gain to get what you want.

Storing a peak, then discharging once read it exactly what I'd like to accomplish. I am not interested in the strength/velocity of the drum hit so much (aside from needing the sensitivity to be low enough that false triggers do not occur from outside sound sources; ie: other drums, guitar amps, PA, etc).
By "tweaking the gain" do you mean using a series resistor on the piezo's output? A potentiometer?

If you think about that RC circuit you built with the zener the time constant can be reduced by either making R or C smaller. I recommend you do the prior. Try something like 1k or less.
If you have a 1k or 10k pot use that so you can find that sweet spot you want.
You can try this for both the highpass and RC circuit

I have some 10k pots I could use for this. However over the weekend I installed the 4 Zener diodes to one of the pedals and did some testing.
During the 6 hours of testing the Teensy did not lose connnection with Pd ever. Seems the issue has been resolved. A huge relief.
Thank you Zener Diodes!

The best response time I could get, combined with my Pd script, was about 75ms. Which is probably fine. My band's music rarely gets above eighth notes at 100 bpm.
1/8th note @ 100 bpm = 150ms window
75ms will work for now, and possibly forever for this system.
 
1/8th note @ 100 bpm = 150ms window

Do you guys play doom metal?

By the way great project... I'm interested in piezos ...that said I used fsrs for a drum machine type project ...worked with very little external circuitry, but I suspect you have some quite tight requirements you are working with. I doubt fsrs would work on a snare.

I really like your project boxes... are they repurposed guitar gear?

i think this thread is great ... analog circuitry for piezos is fascinating.
 
I'm referring to the amplifier constructed like so:
noninvrt.gif
Tweaking the resistances changes the gain.
This circuit will operate the fastest as it's implementing a sample and hold technique which works very well with digital circuitry.

I'm glad to hear the Zener's have worked for you though!
 
Do you guys play doom metal?

We get compared to a lot of metal bands. The purpose of this whole MIDI system is to cue audio samples of different machinery I've recorded.

By the way great project... I'm interested in piezos ...that said I used fsrs for a drum machine type project ...worked with very little external circuitry, but I suspect you have some quite tight requirements you are working with. I doubt fsrs would work on a snare.

I think FSR might work OK for this project too, but I haven't experimented with them yet. The idea was to read drum hits without interfering with the drummer / drum set. The piezos are currently taped/held against the drums heads and hi-hat.

Aquarian makes a snare head now that uses FSR, check it out.

I really like your project boxes... are they repurposed guitar gear?

I made the boxes. Pine, sheet metal, plexi-glass, USB / D-Sub came from Parts Express, Teensy 2.0, project boards, buttons & piezos from a Chinese supplier (eBay).

i think this thread is great ... analog circuitry for piezos is fascinating.

Thanks, it's been fun!
 
I'm referring to the amplifier constructed like so:
View attachment 6267
Tweaking the resistances changes the gain.
This circuit will operate the fastest as it's implementing a sample and hold technique which works very well with digital circuitry.

I am definitely going to give these a shot. After using the current set up a bit, I think it'd be wiser to construct a 3rd Teensy unit, specifically for the drummer. I'll test the op-amps out and maybe use those in the 3rd set up.

Right now the two boxes are used by myself and the other guitarist. I made a 15' D-sub cable that runs from either of the pedals to the drum-set. The 9-pin D-sub was meant to carry the piezo signal, and green LED signal. The LEDs do not work. I didn't consider the 15' wire's impedance. Anyhow, making a 3rd Teensy would mean the drummer can have the same red/green/white LED information if I make a 3rd box and the 15' D-sub (though nice) won't really be necessary anymore. I can have all 3 devices communicate over WiFi with MobMuPlat.


I did have some other questions related to using multiplexers.
I have experimented with 4051 multiplexers, they worked well. The 4051 turns 8-analogue signals to one (as I'm sure you already know).
Is it necessary to use 8 Zener diodes with a multiplexer? Or does the 4051 limit the voltage naturally?
I'm going to spend some time reading the data sheet, but conversation always helps.

THANKS
 
If you have your drum inputs trigger interrupts you should be able to service them very quickly. I'd be surprised if you need that many Teensy's but it's your choice!

The 4051 has input clamping diodes like so:
jyZvD.gif
This will limit the voltages to the rails you supply the 4051 with.

Also from the datasheet:
ESD protection:
HBM JESD22-A114F exceeds 2000 V
MM JESD22-A115-A exceeds 200 V
CDM JESD22-C101E exceeds 1000 V
All of these should be in excess of your piezo generated voltages so the device should work well to remove negative spikes without breaking
 
Wow, that's a game changer.
I have 4 4051's. Using the 4051's could reduce the whole system down to 1 Teensy. I'm not sure why I originally gave up on the 4051.
Probably limited knowledge of Arduino → PureData Extended pduino object VS Teensy Midi → PureData Vanilla ctlin/ctlout objects.

Cool! Thanks again.
 
I really like your boxes!! And thanks for the snare drum fsr link.

If you have any clips of yr band, PM me!

I was just thinking ... if you are not interested in velocity, then, as Xeno says, there are analog circuits to help lumpy analog signals into the digital domain ...wikipaedia has a good article on schmitt triggers, for instance.
 
adrian,

Thanks and don't mention it!

The schmitt triggers would probably be perfect for my set up.
But I think I have a greater need to utilize my 4051 mux's, which will limit the piezo voltage on their own. The only remaining unknown is the kind of decay (response time) I can get using the 4051's. This will probably be another o-scope job. I will test the piezos taped to a snare drum batter head, with a 10k pull-down (a pot to try different resistances), and the 4051's attached to digital & analog pins on Teensy 2.0.
If you have any other interesting test set ups, let me know and I might be able to add them to my next "report".

I found your thread about FSRs, it's actually linked on the Teensy MIDI page, cool.
 
VCool.. I'm not familiar with 4051 muxes.

I'm really interest in yr work ...piezos are pretty cheap (I guess you are just using garden variety ones?) ...

Thanks for the PM link to 'Drose' .. I'll have a listen tonight. Work calls this morning.
 
You can read more about the 4051 mux here on arduino's site.
Also, PJRC has a blurb about using the 4051 on the same MIDI page where your thread is linked.

schematic_ioexpand.png

The mux allows you to sum 8 analogue signals into 1. You supply the 4051 chip with power, ground and 3 digital pins. The 3 pins can be linked to and control several 4051's.

Anyhow, my system currently utilizes a total of 12 inputs. 8 buttons and the 4 drum triggers. Using only 2 4051's would cover that, plus 4 more inputs. I hadn't realized that the 4051 could limit the voltage of the piezos. The diodes I bought cost $5 for 5, but the 4051 cost $0.50 each from Mouser...much cheaper.


The piezos I got on ebay. 20 for $4 shipped. There are sevearl Chinese sellers on ebay that sell these piezos. That's also where I got the LED arcade buttons.
 
UPDATE:

Almost a month ago I added 5v Zener Diodes in parallel with the Piezo sensors and it seems to have fixed my issue. Teensy has not lost connection with Pure Data since.

Lesson Learned:
Do not send > +5v spikes into Teensy. The voltage must be limited.



I have now drummed up some new issues for myself.
Going to build new MIDI controllers using 4051 multiplexers, 595 LED drivers and Teensy LC.
Things are going well, but I have a small snag, thread here.
 
Last edited:
Status
Not open for further replies.
Back
Top