MAX MSP and Arduino serial Crashes half way through program help!


I'm running solenoid patterns off of midi playing from a simple max msp patch outputting to the arduino. When I hit start in the msp patch it plays the midi for about 30 seconds perfectly, then the solenoids stop running, the patch keeps playing but my mouse freezes and the computer crashes, and the program stops. The only way I've seen that will prevent the computer from crashing is if I keep my mouse active by moving it around, but the solenoids and everything else stop. The computer still basically needs to be restarted. When I run the patch on its own it runs fine (with no serial connect) Anyways, I really am not sure where I'm going wrong here. I'm running a macbook Air 10.73. I've tried it also with a few different boards.

Here is the code I'm working with right now.

int incomingByte = 0;

void setup() { Serial.begin(9600); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(14, OUTPUT); pinMode(15, OUTPUT);

} void loop() {

if (Serial.available() > 0) { incomingByte =; Serial.print ("I received: "); Serial.println(incomingByte, DEC);


if (incomingByte == 148) { digitalWrite(2, HIGH); }

if (incomingByte == 48) { digitalWrite(2, LOW);


if (incomingByte == 149) { digitalWrite(3, HIGH); }

if (incomingByte == 49) { digitalWrite(3, LOW);}

if (incomingByte == 150) { digitalWrite(4, HIGH); }

if (incomingByte == 50) { digitalWrite(4, LOW);


if (incomingByte == 151) { digitalWrite(5, HIGH);}

if (incomingByte == 51) { digitalWrite(5, LOW); }

if (incomingByte == 152) { digitalWrite(6, HIGH); }

if (incomingByte == 52) { digitalWrite(6, LOW);


if (incomingByte == 153) { digitalWrite(7, HIGH); }

if (incomingByte == 53) { digitalWrite(7, LOW);


if (incomingByte == 156) { digitalWrite(10, HIGH); }

if (incomingByte == 56) { digitalWrite(10, LOW);


if (incomingByte == 157) { digitalWrite(11, HIGH); }

if (incomingByte == 57) { digitalWrite(11, LOW);


if (incomingByte == 158) { digitalWrite(12, HIGH); }

if (incomingByte == 58) { digitalWrite(12, LOW);


if (incomingByte == 159) { digitalWrite(13, HIGH); }

if (incomingByte == 59) { digitalWrite(13, LOW);


if (incomingByte == 154) { digitalWrite(14, HIGH); }

if (incomingByte == 54) { digitalWrite(14, LOW);


if (incomingByte == 155) { digitalWrite(15, HIGH); }

if (incomingByte == 55) { digitalWrite(15, LOW); }


Thanks for the help!!

Schematic? Code tags?

How many of those if statements can be true at once? There is a reason that else if exists.

Perhaps the thing to test is simply having the Arduino read, and use, the serial data. What it does with it can not affect the PC that is sending the data. But, sending more data back to the serial port than you get from it could cause the PC to have issues.

So, stop doing that.

hi Paul - thanks for responding.

I'm very much a beginner at this. I'm unclear as to how I'm sending more data back to the computer, or how to modify that? I've changed the code to include the else if's still no change in the results.

I should also mention, that I've been running this set up successfully using the built in arduino chip for a few months now.


Serial.print ("I received: "); Serial.println(incomingByte, DEC);

I'm unclear as to how I'm sending more data back to the computer, or how I'm doing that?

if (Serial.available() > 0) {
    incomingByte =;
    Serial.print ("I received: ");
    Serial.println(incomingByte, DEC);

If you get one byte (character) you send it AND 12 more back to the PC.

thanks!! that solved it!