Problems with Max and 2 serial port connections (2 sensors/arduino)

Jeff's icon

Hi everyone,

For a few years, I have been working with a sing sensor (accelerometer) connected to an Arduino Uno and into Max using the patch Arduino to Max. With no problems. I use some basic Arduino code to read analog and digital pins.

For a new project, I need to work with multiple sensors/arduino(s) but when connecting two arduinos into separate USB ports on
a 2016 MacBook Pro 2.8Ghz (not the new release version), they seem to interfere with each other and make the other's data streams
randomly fluctuate.

I use a modified version of 'Arduino To Max' patch, which allows the population of current ports to a umenu. I use 2 of these 'Arduino to Max' patches and set them to different ports, based on the menu selection.

I am a bit perplexed because it seems like I am setting everything correctly so that different instances of the serial object would read different ports, but there is still something going on.

It seems there must be something important I am missing. If you can see any issues in the patch I attached, I'd greatly appreciate some feedback and/or solutions.

Thanks!

Jeff

NL_proximity_sensor2.maxpat
Max Patch
musinou's icon

So, you used twice this patch, and you have a different port for each Arduino and you think that some data is leaking from one to the other? If that is the case, my first guess is that is probably hardware. Do you have the same problem when your computer is plug-in the power with the ground cable? And if the Arduino are grounded too?

Source Audio's icon

Serial Ports are delicate, if one initialises them in a wrong order
they could missbehave or freeze the ports.
If You plan using several serial objects, give them different
port arguments to start with ( serial a 57600, serial b 57600 etc)
Like that You can avoid having several objects connect to same hardware.
Later You can send port messages and set them as wished.
I never liked the idea of more than 1 serial object.
There are many ways to extend 1 arduino to have more inputs,
cascading arduinos using i2c, or inter serial communication,
and have only one of them talking to serial object.

Jeff's icon

Hi and thanks for the replies.

I don't have a problem when my computer is plugged in. I went back to the arduinos to double check the grounds, which seem to be ok.

The two patches are named differently (although they are identical with different named serial objects and no send/receive programming).

I did notice the sensitivity re. reading the serial ports when plugging/unplugging the arduinos, and your advice on initializing them in a correct order may be the problem. They seem to be 'bleeding' data between the two, but w/this initialization issue, the two patches might be reading the same port (even though the populated list of ports shows them reading different ports).

I think cascading might be the solution for my proximity sensor arrays.

But I also have another project where an ensemble will be using five wireless (Xbee/arduino) accelerometers for live performance. Do you know if there data limits in what a cascading setup could handle (e.g. incoming analog for accelerometer x-y-z data x5)?

Jeff's icon

Let me correct 1st sentence of my previous post: I don't have a problem with one adruino when the computer is plugged in or not plugged in. I have a problem reading 2 arduinos both when the computer power cable is and is not plugged in.

Source Audio's icon

I don't know if the patch You uploaded is still actual, but in case it is,
there is a simple mistake in there. You can't send port 1, or port 2 message to serial object.
Connect the middle outlet of menu to set port.
I also don't see what is the sense of appending port numbers to menu, instead of using,
simple way of populating menu... clear, append, select desired port .
You can just loadbang port xxx message.
And avoid unplugging and plugging Arduinos while max is running.
That will definitely put You into trouble.
There is alternative object comport from Jasch worth having alook at.
It worked better for me for some tests where I had to release Arduino from Max, and monitor it
through other software, and back.