Go Down

Topic: Max/MSP to arduino_Serial object_problem after re-opening (Read 434 times) previous topic - next topic

hellsinki

Hi everybody,
I have an arduino code that enables me to send 3-byte MIDI messages (MIDI channel, MIDI note number, Velocity) from Max/MSP to arduino over the serial port. Just to make sure I seperate the MIDI messages with a carriage return (13). This basically works like expected and fine.

However, when closing the Max [serial] and opening it again, I ALWAYS get a wrong result the first time. Assuming I close and re-open [serial] and then send it a message like [144, 66, 66, 13] I will get a result like [254, 254, 144]. Sending the same message a second time outputs the correct result.

I really don't understand that. Does anybody have a clue why it behaves like that?

I also tested it with Pure data and got the same result.
Below the arduino code with the simple Max patch.
I currently work under Windows XP with Max 5 and Arduino 1.0.1.

Thanks a lot for your time and help!

Quote


byte buffer[] = {1, 2, 3};  // Serial Input-Buffer containing our 3-byte MIDI messages
byte SerialData = 0; 
byte index;   

void setup(){
  Serial.begin(57600); }

void loop(){/* empty */}

void serialEvent(){
   SerialData = Serial.read();
   buffer[index] = SerialData;
   index++;
   if(SerialData == 13) // Just to make sure we send a carriage return after each MIDI message
     evalSerialData();
   }

void evalSerialData(){
    Serial.write(buffer[0]);
    Serial.write(buffer[1]);
    Serial.write(buffer[2]);
   
     buffer[0] = 0; buffer[1] = 0; buffer[2] = 0;
     index = 0; 
   
 }
 
 /*
 
----------begin_max5_patcher----------
727.3ocwW0yaaCCDc1AH+GNnYWCQpu6VQ6PyPlR2BBJnkNayBIRCIpJmFz+6
kjRxw1Io9K4jA6y9HEuGeu6HO8z0WMxYpbEV4.eFtGFM5IsmQVeFOi5cLxof
sJMmUYmnSprn.EJmwcCpvUJ6.eMWVg.SjAxkn.pvRNKGjS+ElprtaXpzE.Th
U04JfKfaYq.EVVvEr70qWNWfoxZgcQo8dE05YkiJKFH8dmIEpJ9ePqS5D2d+
KMQhKl+yRcra2djjP83.Ip0j3ZLd9SbgG1HFxZUePb2LHBVgMHNewroViUdl
0odO9IB0w57uWekwpMiOeJ8GK3Ufcy.r7bYSEnjZhUykEXUEaNVAyJkEsDoD
XkY0bgbB7cYC9arbLjp0DMOrVUL+Vs.2QbZ344PJqVKepELkcFy3kJc33EHz
fvRsnUAx5R31a91M8Q2Lh8YmiZEFZJk5kuSdumF3OFreQ78eXxqqu9aRxyXo
3Vx6YK5w9FUlFa0ZRjwDRGNI28BH42YT2sH4mEVmAiXnjDaY.0qsnvRMT2Ai
ZRNclQfM5U3kDSWJKBAQgttCGUPhBra9DhwDGtOlX8QRs9TOtDaWHGtQOAGm
mexCLOZ3IqkkZv.2gaExghp77ZOCkDOvYMmwQncEKujIzG9nK5Ca+P7dcxfd
JjQ64I8kPtsl32lLHuYhyQmw3M7YLJXJLjoJcrSf0DEe5UUSYh4mTYk+vSRY
XN6QsVeLMqbN4Vw1So8I6qWEx+m8NVlK3BTGZ5DAGtpOJs8JKhka7idGK9Bu
.rio2rAjbRnaPNdumjSztjS6BXKT18EMrH2LvNTVktOyzdDzdA4XXCvmgUJ8
qLn3RwFSht8jVvyxPwVWBUvyVJ02K1gC3g2VGOXn4qiJYePi7g.sfCg0NZnQ
ngSBLM1aMDcG18+aP.c3EAzTuNPmrEnSFHP6cHf1+CK+buPK3CAZQWDo1ykb
nRswg17OwTd2t.
-----------end_max5_patcher-----------

*/




Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy