Multiple Arduinos Fixed Comport

Hi, I am looking for a solution to my project that I have to assign the comport to each Arduinos.
So I have 4 Arduinos, each connected to the PC or to a USB hub. Since I am using Matlab, I need to know and grab the ComPort # for each Arduino.
However, for the future user, they may not know which one is which (as in which one should be configured to be input or output). Thus, I was trying to see if there is a way to find the unique information about the arduino, then I can select that comport.

If not, I was looking into some programmable USB hub then where I can set the port 1 from the USB hub1 is COM 6 or whatever.

In this case then the user only needs to know where that hub is connected to and rest of them will be configured by itself.

Does anyone has any ideas or known solution for this?

Thanks!

why would It need to be fixed?

You connect to an arduino and the Arduino reboots when the Serial line opens, and in the setup you send some sort of handshake message that describes what this arduino does like "I'm the temperature sensor" or "I'm the motor driver".

Then , based on this message, the Matlab code adjusts dynamically.

The answer by @J-M-L is probably the most universal one.

You don't mention which Arduinos you're using; for boards with native USB you can program them so they identify themselves as to what they are; see the right two devices in below screenshot which are actually SparkFun Pro Micros.

image

Note:
I only have experience with 32U4 based boards for this.

Sorry I forgot to inform you what it was.
The Arduinos that I am using are Due.

Sorry I am still not familiar with programming the Arduino itself to say 'Hey I am the number 1'. Would you be able to share a link or something that I can read of from?

Thanks!

Are you programming the Arduinos ?

I've never done it but if I have to do to obtain the handshake information then yeah.
Not sure how to do it at this moment. :frowning:

For @J-M-L's solution

void setup()
{
  // initialise serial port on Due
  Serial.begin(115200);
  // wait for communication channel with PC to be opened
  while(!Serial);
  // identify myself to app that opened the communication channel
  Serial.println("Board1");

  Other code
}

void loop()
{
  More code
}

What does run on the Arduino then ?

Hi JML

I am not sure what it runs on the Arduino.
It has the default information in it then Matlab creates server into Arduino to control the I/Os.

I am trying to understand @sterretje 's code to see if I can convert to Matlab code or run from Matlab. If not, is there a way to hardcode Arduino to say "I am 1" when the unit is on?

Thanks!

The code I presented is Arduino code, so that will do the trick. Converting it to MatLab is not the way to go.

Than you have a problem. Ask whoever wrote it to give you the source code.

So the arduino is just controlled by matlab and does not have a specialized code or sensors reporting data etc ?

Then it means you are using a default script. The MATLAB support package for Arduino generates a generic Arduino sketch that is designed to handle standard I/O operations and communication (pins, pwm, i2C,..).

This sketch is not customized for specific user applications, meaning it provides a baseline functionality that users can interact with through MATLAB.

If you don’t want to have to mess with the generated code, one process could go like this:

Say you have three Arduinos to connect and identify: Start with no arduino connected and the MATLAB code could prompt the user to connect each Arduino sequentially, create Arduino objects for each one based on the automatically detected new COM ports, and assign them to specific roles, such as arduinoMotors, arduinoSensors, and arduinoControlPanel.

1 Like

Hi JML,

That is unfortunate. I think the method that you suggested might be an alternative option for me. With this method I might be able to use a USB hub with on off switch to specify the roles.
Maybe using one of these 4 Port USB 3.0 & 3.2 Gen 1 Splitter Hub with Long 5ft Cable (manhattanproducts.us)

This is a great progress for me. Thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.