USB native port - Serial connection

Hi!

I am trying to establish connection between Arduino Due and another serial port device, so that Arduino Due would control this device without PC.

I have already established communication with this device with Matlab using this code:

function test_TEC
handles.TEC1.port = 'COM8';
handles.TEC1.con = serial(handles.TEC1.port);
    set(handles.TEC1.con,'Parity','no');
    set(handles.TEC1.con,'BaudRate',115200);
    set(handles.TEC1.con,'Timeout',2);
    set(handles.TEC1.con,'Terminator','CR');
    
    set(handles.TEC1.con,'DataBits', 8);
    set(handles.TEC1.con, 'InputBufferSize', 1024);
    set(handles.TEC1.con,'OutputBufferSize', 1024)
    fopen(handles.TEC1.con);

%Check for any error codes on TEC1
        status=getStatus(handles.TEC1.con);
        status = status(1:end-4);
        if isempty(status)
            fprintf('TEC1: No connection.\n')
            fclose(handles.TEC1.con);
        end
    setFan1Mode(handles.TEC1.con,1);
fclose(handles.TEC1.con);
    delete(handles.TEC1.con);
    
function val = getStatus(con)
fprintf(con,'$S?')
fscanf(con,'%s')
val = fscanf(con,'%s')

function setFan1Mode(con, val)
command = strcat('$R16=',val)
fprintf(con,command)
fscanf(con,'%s')
fscanf(con,'%s')

Now I want that Arduino Due sends a command to this divice throug serial port, but I do not now how establish communication or how to send data to the divice correctly.

I used this code:

void setup() {
  Serial.begin(9600);
  SerialUSB.begin(115200);
  Serial.setTimeout(2000); 
}

void loop() {
  String msg1 = "$S?"; // this is command to get status from divice.
  String msg2 = "";
  SerialUSB.println(msg1);
  if (SerialUSB.available() > 0)
  {
    while (SerialUSB.available() > 0)
    {  
      msg2 = char (SerialUSB.read());
      delay(50);
    }
  Serial.println(msg2); // Printing on PC Serial Monitor
  }
  delay(500);
}

I have also managed to send this commant to PC through USB Native port and also send data to Arduino with Serial monitor.

But when I am try to send command to external serial divice I do not get any answer.

For comunication I am using USB OTG converter from micro USB to USB type A and than a USB to RS232 converter.

I would be very thankful if someone could give me some advice.

SerialUSB.begin() only establishes a connection with a host PC. You want your Due to be the host. The standard Arduino USB Host library allows you to host mice and keyboards but nothing else.

I thought that someone had asked this question recently but I can't find the question or the answer. Googling for "Arduino Due USB serial host" doesn't return any useful information. There's probably a key word that I don't know.

If you just want a simple plug-and-play solution, it seems like the only answer I can find right now is a USB host shield

If you feel up to it, this would be a useful addition to the Arduino Playground.

Well, thank you for you explanation.

What if change serialUSB port for Serial port in pins 0 and 1? In that case I wanted to use MAX232 converter to RS232 port.

Will ther still be a problem with host divice or is this only for USB protocol.

I found a website where someone communicates over Serial communication between two Arduinos.

I think that comunication between Arduino and other Serial device (not PC) should be possible since it is a basic level of communication.

OK, that's a different question.

Yes, you can use any of the hardware serial on the Due to talk to another RS232 device, so long as you have the MAX232 chip as a level converter. Sometimes your device is "3.3V TTL serial" which means it is using low voltage and can be connected directly to the Due. 5V TTL serial can't be directly connected, so I would recommend you choose one of the 5V Arduino boards for that case.