How to separate analog inputs from Arduino in Max/MSP
Kael Hauptmann
6月 15 2019 | 2:56 午後
Hello Y'all,
So I'm kind of new to Arduino and Max/MSP and I'm having some issues. Basically, I have two separate piezo sensors that send out date when I tap them. In Arduino it shows the separate values, but when I use Max I don't know how to separate these values from the serial. Here's what I've got in Arduino:
Now the numbers should actually both read zero, but that's another problem I'll worry about after I figure this out. Here's my Max:
Holland Hopson
6月 24 2019 | 9:46 午後
Hi Kael,
I solve this problem by combining all the data I want to send into one long message followed by a carriage return character. In your case the Arduino code might contain:
Serial.print(AnalogPin); //print the data from analog pin
Serial.print(" "); // print a space to separate data from each source
Serial.println(AnalogPin1); // P rint the data from another analog pin followed by a line-feed. We'll use this to determine the end of our message
And a bit of Max patching to group together and parse the relevant messages.
Source Audio
6月 25 2019 | 4:35 午後
I see that You want to make drum trigger
from piezos and arduino.
One wants that to execute fast, so the delay(100) would not be really helpful.
Another issue would be retriggering when above threshold.
I would do the following :
try to set threshold in Arduino, and declare one piezo trigger as
high when above , but send that info only once, so analog input needs to fall
below threshold and cross it again to retrigger, same as change in max.
Then one could send a number for each input, if only trigger has to be reported.
Otherwise one could append measured value and use it as velocity or volume etc.
This would be arduino code for 6 piezos :
unsigned long Sensor[6] = {0,0,0,0,0,0};
unsigned long Trigger[6] = {0,0,0,0,0,0};
unsigned long exTrigger[6] = {0,0,0,0,0,0};
int THRESHOLD = 100; // threshold
void setup() { Serial.begin(57600); }
void loop() {
for(int i=0; i<6; i++) {Sensor[i] = analogRead(i);
if(Sensor[i] > THRESHOLD) {Trigger[i] = 1;}
else {Trigger[i] = 0; exTrigger[i] = 0;}
if (Trigger[i] == 1 and Trigger[i] != exTrigger[i])
{Serial.print(i); Serial.print(" "); Serial.println(Sensor[i]); exTrigger[i] =Trigger[i]; }}}
----------
Max patch :