Forums > MaxMSP

Read analog input from arduino

August 6, 2009 | 7:23 pm

Hi,

I’m building a sample trigger whit arduino based on a piezo input, all max patch is set except, when i read the analog values from arduino, as i see the values came without stopping, and i have a very hard time trying to extract only the maximum value and stop the values flow, and when the sample is played i must have all back to get the new maximum value.
Here is what i got so far.

thanks for any help.

Luis Marques

– Pasted Max Patch, click to expand. –

August 7, 2009 | 12:27 am

Try
a combo w. [clip] so you can have the values trapped between a max and min values. Then use [scale] to change how the values are output.

Or as you phrased it, you can use [peak] the have the max N < - then you can reset it.

Sorry I am not on a computer that has MAXMSP installed, so I can’t do a patch for you.

Again, maybe what is not necessarily to stop the values flow < - but what what is let through.

have a look @ N matching objects like:

[Select]
[route]
[match]

You might gate w. Value (very practical)
[int]
[float]

Maybe even

[Split]< - although I have always found it very weak to respond to fast changing data.

good luck

phil


August 7, 2009 | 6:07 am

hi,

thanks for the answer.

I really need to stop that flow… When you hit the piezo he give a value between 0. and 100. (for example), if i let trough values between 70 and 100 whit split object, it will constant outputting values from 70 to 100 and back, from 100 to 70, so i got not one bang, but 60 bangs (if all values are captured), i really need something that stops the flow to get only one output bang and extract the peak of that impact.

thanks

Luis Marques


August 7, 2009 | 7:42 am

Hey

here is a patch that is a complete hack but works fine to do what I think you wanted (only output once if between 70-100, anything under 70 will reset it)

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 194 70 100 196617 work fine @ 30 ms;
#P window linecount 2;
#P comment 182 139 100 196617 < - manipulate manually to see;
#P window linecount 4;
#P comment 164 382 100 196617 anything above 70 will only output once until will goes under 70 again;
#P button 88 376 15 0;
#P window linecount 1;
#P newex 135 151 40 196617 t i i i;
#P number 113 378 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 101 348 27 196617 i;
#P newex 101 324 32 196617 sel 1;
#P message 131 279 14 196617 0;
#P toggle 100 306 15 0;
#P message 73 278 14 196617 1;
#P button 73 257 15 0;
#P newex 40 225 40 196617 change;
#P newex 131 204 32 196617 sel 1;
#P number 135 132 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 131 258 15 0;
#P newex 132 179 36 196617 < = 70;
#P toggle 40 206 15 0;
#P newex 86 225 55 196617 onebang;
#P newex 86 204 32 196617 sel 1;
#P newex 86 178 36 196617 >= 70;
#P toggle 135 49 15 0;
#P newex 135 109 27 196617 + 1;
#B color 1;
#P newex 135 90 58 196617 random 99;
#B color 1;
#P newex 135 69 52 196617 metro 30;
#B color 1;
#P window linecount 2;
#P comment 200 91 100 196617 < -arduino value simulator;
#P connect 3 0 11 0;
#P connect 1 0 2 0;
#P connect 4 0 1 0;
#P fasten 5 0 8 0 91 200 45 200;
#P connect 5 0 6 0;
#P connect 19 0 22 0;
#P connect 19 0 20 0;
#P fasten 21 0 5 0 140 173 91 173;
#P fasten 21 1 9 0 155 175 137 175;
#P fasten 21 2 19 1 170 344 123 344;
#P connect 16 0 18 0;
#P connect 18 0 19 0;
#P connect 11 0 21 0;
#P fasten 17 0 16 0 136 299 105 299;
#P connect 10 0 17 0;
#P fasten 15 0 16 0 78 299 105 299;
#P connect 14 0 15 0;
#P fasten 13 1 14 0 60 249 78 249;
#P connect 8 0 13 0;
#P connect 9 0 12 0;
#P connect 12 0 7 1;
#P connect 7 1 10 0;
#P connect 6 0 7 0;
#P connect 2 0 3 0;
#P window clipboard copycount 26;


August 7, 2009 | 8:08 am

hi,

yes, it’s working. but it’s not precise between 2 impulses.
For making that i think it needs something to update the < = value.
this is needed because if it hit the piezo once it gives me the value of 80, and then the sound is triggered, but after i hit again and the value that is checked have no time to get under the 70, so it miss one shot…

Luis Marques

Update:

Is is possible to extract only the first bang of 30 from the arduino?


August 7, 2009 | 3:02 pm

maybe this is what you mean. Sorry if these patches are of no help. I’m not sure I understand. (If in zone above 70/bang once unless a new peak is reached while still in that zone)< - is this it?

#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#P comment 265 538 91 196626 AND ->;
#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 526 522 161 196617 < -1st bang of 30 from arduino question.;
#P number 413 654 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 375 560 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 412 505 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 413 632 27 196617 i;
#P newex 413 584 45 196617 onebang;
#N counter 1 30;
#X flags 0 0;
#P newobj 413 530 68 196617 counter 1 30;
#P user panel 364 500 153 180;
#X brgb 255 255 255;
#X frgb 0 178 248;
#X border 3;
#X rounded 20;
#X shadow 0;
#X done;
#P window linecount 4;
#P comment 651 387 100 196617 < -this way it doesn't have to go under 70 to reset the highest peak;
#P window linecount 1;
#P newex 551 376 27 196617 i;
#P message 592 382 20 196617 69;
#P number 554 420 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 554 400 46 196617 peak;
#P message 601 270 14 196617 1;
#N counter 1 30;
#X flags 0 0;
#P newobj 558 292 68 196617 counter 1 30;
#B color 5;
#P comment 621 87 100 196617 work fine @ 30 ms;
#P window linecount 2;
#P comment 653 152 100 196617 < - manipulate manually to see;
#P window linecount 1;
#P newex 562 168 40 196617 t i i i;
#P newex 558 221 32 196617 sel 1;
#P number 562 149 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 558 275 15 0;
#P newex 559 196 36 196617 < = 70;
#P newex 513 242 55 196617 onebang;
#P newex 513 221 32 196617 sel 1;
#P newex 513 195 36 196617 >= 70;
#P toggle 562 66 15 0;
#P newex 562 126 27 196617 + 1;
#B color 1;
#P newex 562 107 58 196617 random 99;
#B color 1;
#P newex 562 86 52 196617 metro 30;
#B color 1;
#P window linecount 2;
#P comment 627 108 100 196617 < -arduino value simulator;
#P comment 248 393 100 196617 when above 70 only 1st 30 are seen;
#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#P comment 355 201 91 196626 OR ->;
#P window setfont "Sans Serif" 9.;
#P number 209 388 35 9 0 0 0 3 0 0 0 246 183 183 222 222 222 0 0 0;
#P newex 206 367 29 196617 gate;
#P message 181 260 14 196617 1;
#N counter 1 30;
#X flags 0 0;
#P newobj 138 282 68 196617 counter 1 30;
#B color 5;
#P comment 201 77 100 196617 work fine @ 30 ms;
#P window linecount 2;
#P comment 233 142 100 196617 < - manipulate manually to see;
#P button 94 421 15 0;
#P window linecount 1;
#P newex 142 158 40 196617 t i i i;
#P number 119 423 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 107 393 27 196617 i;
#P newex 107 369 32 196617 sel 1;
#P message 138 316 14 196617 0;
#P toggle 106 351 15 0;
#P message 80 285 14 196617 1;
#P button 80 264 15 0;
#P newex 47 232 40 196617 change;
#P newex 138 211 32 196617 sel 1;
#P number 142 139 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 138 265 15 0;
#P newex 139 186 36 196617 < = 70;
#P toggle 47 213 15 0;
#P newex 93 232 55 196617 onebang;
#P newex 93 211 32 196617 sel 1;
#P newex 93 185 36 196617 >= 70;
#P toggle 142 56 15 0;
#P newex 142 116 27 196617 + 1;
#B color 1;
#P newex 142 97 58 196617 random 99;
#B color 1;
#P newex 142 76 52 196617 metro 30;
#B color 1;
#P window linecount 2;
#P comment 207 98 100 196617 < -arduino value simulator;
#P user panel 521 344 116 106;
#X brgb 255 255 255;
#X frgb 0 178 248;
#X border 3;
#X rounded 20;
#X shadow 0;
#X done;
#P connect 58 0 55 0;
#P fasten 58 0 57 1 498 520 498 620 435 620;
#P connect 55 0 59 0;
#P connect 55 0 56 0;
#P fasten 55 3 56 1 475 565 453 565;
#P connect 57 0 60 0;
#P connect 56 0 57 0;
#P connect 42 0 44 0;
#P connect 42 0 52 1;
#P connect 38 0 39 0;
#P connect 38 0 52 0;
#P connect 52 0 49 0;
#P connect 47 3 51 0;
#P connect 49 0 50 0;
#P connect 51 0 49 1;
#P connect 43 0 39 1;
#P fasten 43 0 48 0 563 240 606 240;
#P connect 37 0 38 0;
#P connect 35 0 42 0;
#P connect 33 0 34 0;
#P connect 36 0 33 0;
#P fasten 44 0 37 0 567 190 518 190;
#P fasten 44 1 40 0 582 192 564 192;
#P connect 40 0 43 0;
#P connect 39 1 41 0;
#P connect 34 0 35 0;
#P connect 41 0 47 0;
#P connect 48 0 47 3;
#P connect 13 0 8 1;
#P fasten 13 0 27 0 143 230 186 230;
#P connect 17 0 19 0;
#P connect 17 0 28 0;
#P connect 12 0 22 0;
#P fasten 12 0 28 1 147 156 230 156;
#P connect 20 0 23 0;
#P connect 20 0 21 0;
#P connect 28 0 29 0;
#P fasten 26 3 18 0 200 308 143 308;
#P connect 27 0 26 3;
#P connect 11 0 26 0;
#P connect 3 0 4 0;
#P connect 7 0 8 0;
#P connect 8 1 11 0;
#P connect 10 0 13 0;
#P connect 9 0 14 0;
#P fasten 14 1 15 0 67 256 85 256;
#P connect 15 0 16 0;
#P fasten 16 0 17 0 85 306 111 306;
#P fasten 18 0 17 0 143 332 111 332;
#P connect 19 0 20 0;
#P fasten 22 2 20 1 177 388 129 388;
#P fasten 22 1 10 0 162 182 144 182;
#P fasten 22 0 6 0 147 180 98 180;
#P connect 6 0 7 0;
#P fasten 6 0 9 0 98 207 52 207;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 4 0 12 0;
#P window clipboard copycount 63;


August 7, 2009 | 3:27 pm

hi,

thank you so much for your help. as i moved forward in the patch and knowing better how the arduino acts, i decided that it’s better for precision to have both inputs on, analog and digital, one gives me the voltage, which i convert to dynamics, and the digital for the hit precision. the main problem here is the piezo connected to digital input don’t give me only 1 or 0, but a bunch of 0′s and 1′s all together, it’s about 30, but sometimes when you hit more constantly i get more that 30, so i don’t really know how much bangs the digital input have.
I need some kind of a filter that stops once he gets the first bang or number and starts when another bang/number is received.

Luis Marques


August 7, 2009 | 3:35 pm

>>I need some kind of a filter that stops once he gets the first bang or number and starts when another bang/number is received.

a bit confusion.As this could mean

N
|
stop
|
next N

start

which means it never stops.

OR

you mean 1st value is kept, then nothing for N times Then start again

Or

!st value , then stop . Start if N is between specific range.

Anyways, I wish you good luck.

phil


August 7, 2009 | 4:05 pm

ok,
The last is the better i think, only know for sure if i tested, 1st value then stop, only start in a specific range.


August 9, 2009 | 4:43 pm
IcedDragon wrote on Fri, 07 August 2009 09:27
hi,
I need some kind of a filter that stops once he gets the first bang or number and starts when another bang/number is received.

change?


August 9, 2009 | 6:11 pm

hi,

change doesn’t work because i do want to filter a number but i need to read again the same number…

Luis Marques


August 9, 2009 | 9:36 pm

would this very simple solution work? But I’m sure you thought of this.

sometimes things are so simple, they slips through ideas Wink

#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 404 106 100 196617 bang when want to reuse;
#P number 337 174 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 337 117 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 396 132 26 0;
#P window linecount 1;
#P newex 337 144 40 196617 change;
#P number 118 184 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 118 155 27 196617 i;
#P number 118 95 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 178 126 15 0;
#P newex 118 122 40 196617 change;
#P comment 215 148 31 196617 OR;
#P window linecount 2;
#P comment 171 98 100 196617 bang when want to reuse;
#P connect 8 0 10 0;
#P connect 7 0 10 0;
#P connect 9 0 7 0;
#P connect 3 0 5 0;
#P connect 5 0 6 0;
#P connect 2 0 5 1;
#P connect 4 0 2 0;
#P window clipboard copycount 12;


August 12, 2009 | 4:24 pm

If you want the peak to trigger, you can use [peak], for reset use a [trough]. Or just block a retrigger while you play the sample, or block for a specific time. This depends a lot how your input looks like…

Two versions to try:

– Pasted Max Patch, click to expand. –

Viewing 13 posts - 1 through 13 (of 13 total)