Max Arduino Serial conflict

moris526's icon

Hi all.

Here is the thing.

If i open a patch, then plug the arduino uno board via usb, and then open Serial object, evething works fine.

But if a have the arduino pluged in and then open the patch, i cant open serial port: ¨Error opening serial port¨.

Ive try delaying the opening of the port a few seconds, but doesnt seem to be a timing thing.

Any idea helps

Thnaks.

balam's icon

post code and patch

moris526's icon

Patch.maxpat
Max Patch
Max patch

Arduino Code

#include "Adafruit_NeoTrellis.h"
Adafruit_NeoTrellis trellis;

#define INT_PIN 10

TrellisCallback blink(keyEvent evt){

if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
Serial.println(evt.bit.NUM+1);
else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
Serial.println(1000 +(evt.bit.NUM+1) );

return 0;
}

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];

int a = 0;
int b = 0;
int c = 0;
int d = 0;

boolean newData = false;

void setup() {

Serial.begin(38400);
pinMode(INT_PIN, INPUT);

trellis.begin();

//activate all keys and set callbacks
for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
trellis.registerCallback(i, blink);
}

}

void loop() {
if(!digitalRead(INT_PIN)){
trellis.read(false);
}

recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);

parseData();

newData = false;
}
delay(2);

}

void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;

while (Serial.available() > 0 && newData == false) {
rc = Serial.read();

if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0';
recvInProgress = false;
ndx = 0;
newData = true;

}
}

else if (rc == startMarker) {
recvInProgress = true;
}
}
}

void parseData() {

char * strtokIndx;

strtokIndx = strtok(tempChars," ");

a = atoi(strtokIndx);

strtokIndx = strtok(NULL, " ");
b = atoi(strtokIndx);

strtokIndx = strtok(NULL, " ");
c = atoi(strtokIndx);

strtokIndx = strtok(NULL, " ");
d = atoi(strtokIndx);

trellis.pixels.setPixelColor(a-1, b,c,d);
trellis.pixels.show();

}
balam's icon

Try to remove the whileserial available

moris526's icon

Thanks for your time.

Same behaviour with all the While deleted.

Do i need some special driver for COM3 on windows 10 ?

moris526's icon


More data

With Arduino Pluged in. If I load a patch with ¨Serial c 9600¨ Gives error, but....

If I create a new patch and create the Serial object, then it connects..

moris526's icon

Correction:

When i load the patch it opens the port. When I open the patch to edit it disconects the serial

Source Audio's icon

at least set same baud rate in both arduino and max patch.
error opening serial port is usually caused by some other app
using arduino serial port, or another max patch.
Only 1 at a time.

pjeve's icon


What Source Audio says is exactly what I meant in the other post.
It is possible that when you launch the Max application to edit the patch, the serial object tries to access the port that is already in use by the instance of the object in the M4L device ...

moris526's icon

Oh.
Yes.
That makes sense.

Thank you