Arduino mega to max serial communication freezes
Hi,
We have a set up of an Arduino Mega 2560 that sends and receives data via USB to mac mini with Max/MSP patch. 14 capacitive sensors are connected to 28 digital pins on the board. 14 pin sends data to max and 14 recieve data from max. After an hour or so the serial communication freezes. When the serial port is re-opened from Max/MSP it starts again. We created a patch where the serial port is re-opened when the connection freezes. Working in this mode after several hours the computer blocks - no mouse and keyboard also. We did some tests and the arduino is working fine. We have used this type of connection on Max/MSP also without any problem before. Any ideas what we can try next?
The max patch we use is :
The arduino sketch is:
const int readPin[] = {23, 24, 27, 28, 31, 32, 36, 39, 40, 43, 44, 47, 48, 51};
const int writePin[] = {22, 25, 26, 29, 30, 33, 34, 38, 41, 42, 45, 46, 49, 53};
byte outV[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte outV_last[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte inByte = 0;
boolean SendOnChange = false;
void setup(){
Serial.begin(9600);
for (int rpCount = 0; rpCount < 14; rpCount ++) {
pinMode(readPin[rpCount], INPUT);
}
delay(30);
for (int wpCount = 0; wpCount < 14; wpCount ++) {
pinMode(writePin[wpCount], OUTPUT);
}
//delay(5000);
}
void loop(){
if(Serial.available()){
inByte = Serial.read();
if (inByte == 0){
for (int offCount = 0; offCount < 14; offCount++){
digitalWrite(writePin[offCount], LOW);
}
}
if (inByte == 1){digitalWrite(writePin[0], HIGH);}
if (inByte == 2){digitalWrite(writePin[1], HIGH);}
if (inByte == 3){digitalWrite(writePin[2], HIGH);}
if (inByte == 4){digitalWrite(writePin[3], HIGH);}
if (inByte == 5){digitalWrite(writePin[4], HIGH);}
if (inByte == 6){digitalWrite(writePin[5], HIGH);}
if (inByte == 7){digitalWrite(writePin[6], HIGH);}
if (inByte == 8){digitalWrite(writePin[7], HIGH);}
if (inByte == 9){digitalWrite(writePin[8], HIGH);}
if (inByte == 10){digitalWrite(writePin[9], HIGH);}
if (inByte == 11){digitalWrite(writePin[10], HIGH);}
if (inByte == 12){digitalWrite(writePin[11], HIGH);}
if (inByte == 13){digitalWrite(writePin[12], HIGH);}
if (inByte == 14){digitalWrite(writePin[13], HIGH);}
}
for (int rc = 0; rc < 14; rc++){
if (digitalRead(readPin[rc])){
delay(8);
if (digitalRead(readPin[rc]))
outV[rc] = 1;
}else{
outV[rc] = 0;
}
if (outV[rc] != outV_last[rc]){
outV_last[rc] = outV[rc];
SendOnChange = true;
}
}
// if (SendOnChange){
// SendOnChange = false;
Serial.print("##11 ");
Serial.print(outV[0]);
Serial.print(" ");
Serial.print(outV[1]);
Serial.print(" ");
Serial.print(outV[2]);
Serial.print(" ");
Serial.print(outV[3]);
Serial.print(" ");
Serial.print(outV[4]);
Serial.print(" ");
Serial.print(outV[5]);
Serial.print(" ");
Serial.print(outV[6]);
Serial.print(" ");
Serial.print(outV[7]);
Serial.print(" ");
Serial.print(outV[8]);
Serial.print(" ");
Serial.print(outV[9]);
Serial.print(" ");
Serial.print(outV[10]);
Serial.print(" ");
Serial.print(outV[11]);
Serial.print(" ");
Serial.print(outV[12]);
Serial.print(" ");
Serial.println(outV[13]);
delay(50);
// }
}
Does anyone had something like this before? Thanks
Hello,
Not sure it might apply in your case, but once I had a similar issue and it was caused by a pin left floating on a sensor breakout board instead of being connected to ground.