# How to program Due serial ports

**URL:** <https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911>\
**Category:** Due\
**Created:** [January 27, 2014, 12:42am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911 "2014-01-27T00:42:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![grimdon](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@grimdon](https://forum.arduino.cc/u/grimdon)\
**Post date:** [January 27, 2014, 12:42am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/1 "2014-01-27T00:42:35Z")

</div>

In my own clumsy way, I quote here from the **Serial** section of the Language reference.

"The Arduino Due has three additional 3.3V TTL serial ports: Serial1 on pins 19 (RX) and 18 (TX); Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX). Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip, which is connected to the USB debug port. Additionally, there is a native USB-serial port on the SAM3X chip, SerialUSB'. "  
This is all of interest to me but useless if I don't know how to program the several ports. There is no hint that I could see on the associated functions/methods appropriate to these Due ports. There should be some kind of hyperlink here. I also get the feeling that some of these ports have different names in other places.

Are pins 0 and 1 really connected to two different ports?  
Where is more documentation of the debug port? Is this the Serial Monitor?  
How is the word **SerialUSB** related to the native port? Is it a software keyword?  
From browsing documentation for other boards I gather that, for example, **Serial1.begin()** would activate pins 18 and 19. Is that correct?

Thank you for any information.

---

<div class="post-metadata">

**Author:** ![jmparatte](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jmparatte/32/217258_2.png) [@jmparatte](https://forum.arduino.cc/u/jmparatte)\
**Post date:** [January 30, 2014, 8:29am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/2 "2014-01-30T08:29:57Z")

</div>

Hi grimdon,

I think all answers are in these 3 links:

> **[Due | Arduino Documentation](https://docs.arduino.cc/hardware/due)**
>
> The Arduino Due is the first Arduino board based on a 32-bit ARM core microcontroller. With 54 digital input/output pins, 12 analog inputs, 2 DAC and 2 CAN it is the perfect board for powerful larger…

> **[Serial - Arduino Reference](https://www.arduino.cc/reference/en/language/functions/communication/serial/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

> **[arduino-Due-schematic.pdf](https://www.arduino.cc/en/uploads/Main/arduino-Due-schematic.pdf)**
>
> 67.77 KB

But I'm right with you, it's difficult to understand, it's complex schemas.  
I've tried some cases and I can confirm that docs are right.

Case of Serial1, Serial2 and Serial3 are simple: The pins 14 to 19 are connected to the AVR and can have other usages.

Case of Serial is more complex: Pins 0 and 1 are connected to the AVR and to the USB programming port. If the USB programming port is in use (when you program the AVR or when you communicate with the AVR), pins 0 and 1 are connected to the programming port and don't be used for any other usages.

Case of SerialUSB is different: No pins are used and you must use the native USB port to communicate with the AVR.

Take care of special RESET/ERASE actions at 1200Bps on the USB programming port and the USB native port.

Take care of NO RESET action at open/close of the USB native port.

---

<div class="post-metadata">

**Author:** ![KevinA](https://avatars.discourse-cdn.com/v4/letter/k/ee59a6/32.png) [@KevinA](https://forum.arduino.cc/u/KevinA)\
**Post date:** [September 6, 2017, 11:13pm UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/3 "2017-09-06T23:13:10Z")

</div>

I have to agree with @grimdon, this is crap;  
sketch serialpassthrough does not work on the Due. As configured it has serial and serial1 configured BUT the USB programming port shows up on the PC as COM11 and the USB (AB is the only thing I found) shows up on the PC as COM12 BUT (again) what do you call the USB (AB) in the sketch?

A simple pass through loop that fails out of the box... I am not getting a warm and fuzz with the Due...  
More GoogleFu produced: [How To Use The Native USB Of The Arduino Due For High-Speed Communication - Copperhill](http://copperhilltech.com/blog/how-to-use-the-native-usb-of-the-arduino-due-for-highspeed-communication/)  
and that resulted in modification of MultiSerial:  
`
/*
Multple Serial test`

`
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc
The circuit:

Any serial device attached to Serial port 1
Serial monitor open on Serial port 0:

created 30 Dec. 2008
modified 20 May 2012
by Tom Igoe & Jed Roach
modified 27 Nov 2015
by Arturo Guadalupi
This example code is in the public domain.
Modified 9/7/2017 for Due support with SerialUSB
*/
void setup() {
// initialize both serial ports:
Serial.begin(9600);
SerialUSB.begin(9600); // Initialize Native USB port
}
void loop() {
// read from port 1, send to port 0:
if (SerialUSB.available()) {
int inByte = SerialUSB.read();
Serial.write(inByte);
}
`

`// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
SerialUSB.write(inByte);
}
}
`

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [September 7, 2017, 4:48am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/4 "2017-09-07T04:48:49Z")

</div>

This sketch works (BTW post your code between code tags).

SerialUSB is the communication function used with the native USB port, Serial with UART (RX/TX) and Serialn(RXn/TXn) with the corresponding USARTp (Serial1 for USART0, Serial2 for USART1, Serial3 for USART3 and Serial4 for USART2 with a few more lines of code for this last one).

In a first Arduino IDE window, select Arduino DUE(Programming Port), Connect the board to your PC, select a Com port accordingly, i.e. for me it's "Port: Com4 (Arduino DUE Programming Port)". Upload this skectch.

Then in another IDE window opened with a right click in your short-cut IDE, select Arduino DUE (Native USB Port), connect the board to your PC with a USB cable, select a Com port accordingly, i.e. for me it's Com 8 (Arduino DUE Native USB Port)".

Sometimes the correct port doesn't show the first time you connect your cable, unconnect and connect again your cable until the correct port shows in Menu \> Tools \> Port.

---

<div class="post-metadata">

**Author:** ![Bigoldsofty](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bigoldsofty/32/1099004_2.png) [@Bigoldsofty](https://forum.arduino.cc/u/Bigoldsofty)\
**Post date:** [November 6, 2017, 8:55pm UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/5 "2017-11-06T20:55:02Z")

</div>

Whilst Serial1 and Serial2 light up orange when you have them in the code, when you try to compile it results in and 'undefined' error. So that is not much help when you wish to use pins 18 and 19 to communicate with another device using that port.  
How does one make sure Serial1 is actually defined and assigned to the correct pins?

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [November 7, 2017, 4:31am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/6 "2017-11-07T04:31:56Z")

</div>

Prior compiling your sketch, select the correct board in Menu\>Tools\>Boards (Arduino Due) !

---

<div class="post-metadata">

**Author:** ![Bigoldsofty](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bigoldsofty/32/1099004_2.png) [@Bigoldsofty](https://forum.arduino.cc/u/Bigoldsofty)\
**Post date:** [November 16, 2017, 5:38am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/7 "2017-11-16T05:38:57Z")

</div>

Well I can't get a Due, using Serial1 to talk to a ProMini (3.3V version). Triple checked the connection but the Due is not receiving few bytes that are sent by the ProMini.

Is there something special that needs to be done? Debug messages from the ProMini are turned off so they cannot interfere.

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [November 16, 2017, 6:03am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/8 "2017-11-16T06:03:31Z")

</div>

Check each side separately.

Have you checked Serial1 on the DUE side ? The sketch below checks Serial1 and Serial2: connect a jumper wire between RX1/TX2 and another one between RX2/TX1, connect your DUE to the PC side via the programming port:

```cpp
char c = 0;
void setup() {
 
  Serial.begin(250000);
  Serial1.begin(250000);
  Serial2.begin(250000);

  Serial2.print("Hello");
}

void loop() {
  String s;
  s = "";

  while (Serial1.available() > 0) {
    c = Serial1.read();
    s += c;

  }
  if (s.length() > 0) {
    Serial.println(s);
    Serial2.print(s);
  }
  delay(1000);
}

```

Have you connected the grounds together ?

Have you connected RX1(DUE) to TX(Pro Mini) and RX1(DUE) to TX(Pro Mini) ?

---

<div class="post-metadata">

**Author:** ![Bigoldsofty](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bigoldsofty/32/1099004_2.png) [@Bigoldsofty](https://forum.arduino.cc/u/Bigoldsofty)\
**Post date:** [November 16, 2017, 6:57am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/9 "2017-11-16T06:57:32Z")

</div>

Yes grounds are connected. The ProMini side works independently.  
RX1(DUE) is connected TX(Pro Mini) and RX1(DUE) is connected to TX(Pro Mini).; checked multiple times to make sure I hadn't accidentally connected TX to TX etc.

I tried testing the Due by looping Serial1 back to Serial2 or 3 and that never worked either.  
Everything else works: as in the 7" LCD display, FontIC etc.

I have even reduced the baud rate in case the ProMini was having problems with it.

I can't understand why something that should be so simple is causing me such a hassle.

The Due handles all the LCD driving and the ProMini handles the programmable configuration data and the LocoNet interface. Not a huge amount of data has to flow between them; mostly touch screen info to the ProMini and a few screen change instructions the other way.

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [November 16, 2017, 7:22am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/10 "2017-11-16T07:22:34Z")

</div>

If the sketch in my reply #7 doesn't work, I guess your board is out of order.

---

<div class="post-metadata">

**Author:** ![Bigoldsofty](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bigoldsofty/32/1099004_2.png) [@Bigoldsofty](https://forum.arduino.cc/u/Bigoldsofty)\
**Post date:** [November 16, 2017, 10:40am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/11 "2017-11-16T10:40:20Z")

</div>

Am I allowed to swear on here?  
I finally found the problem. A dry solder join on the header on the Due board. It may have even been through plating fault. Reapplying a little flux on both sides and resoldering has fixed it. I gave the board to a friend who inspected it under a microscope at work and just phoned me that it now works.

Thanks for your suggestions.

---

<div class="post-metadata">

**Author:** ![OzZemberek](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ozzemberek/32/1165189_2.png) [@OzZemberek](https://forum.arduino.cc/u/OzZemberek)\
**Post date:** [May 8, 2018, 7:17pm UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/12 "2018-05-08T19:17:34Z")

</div>

Hi , I'm a new starter in a way.

I'm working on a project that uses a laser range finder that communicates with arduino through TTL, and I have this sketch obtained by the seller of the LRF and it is for UNO which works fine ....  
And it uses SoftwareSerial...

How ever I'd like to be able to run it un DUE, as far as I know (as Due has 3 other native serial ports or for some other reason) SoftwareSerial can not be loaded to Due.

I changed some definitions. (ex: portOne =\> Serial1 ) and some functions to make the sketch compatible with Due.

It loads without errors. When I enter the commands through serial monitor, all I get is errors defined in sketch.

What I tried is to change Softwareserial commands with the compatible ones which will work on Serial1 but my knowledge is limited. Thus it failed ...

If someone could convert this sketch to work on Due it will be mush appreciated. Thanks in advance...

Original Sketch is like this (for UNO and using SoftwareSerial)

#include \<Wire.h\>  
#include \<Arduino.h\>  
#include \<SoftwareSerial.h\>  
//ARDUNIO Serial control command

**#define LASER\_OPEN "O"//Open the module**  
**#define MEASURE\_ONE "D"//Single measurement**  
**#define MEASURE\_CONTINUE "C"//Continuous measurement**  
**#define STOP\_MEASURE "S"//Stop measuring**  
**// software serial : TX = digital pin 7, RX = digital pin 6**  
**SoftwareSerial portOne(7, 6);**  
**//Measuring state machine status**  
**#define STEP\_LASER\_OPEN 0//Open the module**  
**#define STEP\_MEASURE\_ONE 1//Single measurement**  
**#define STEP\_MEASURE\_CONTINUE 2//Continuous measurement**  
**#define STEP\_STOP\_MEASURE 3//Stop measuring**  
**#define MEASURE\_CONTINUE\_N 200//Continuous measurement**  
**#define SUCCESS 0//measurement**  
**#define FAIL -1//measurement**  
**unsigned char measure\_continu\_cnt=0;**  
**unsigned char measure\_continue\_flag=0;**  
**//Function declaration**  
**String ReadData(char Length);**  
**String Serial\_One\_ReadData(char Length);**  
**void Measure(char MEASURE\_COMMEND);//distance measurement**  
**String LaserOpen();**  
**String MeasureOne();**  
**String MeasureContinue();**  
**void measure\_continue\_data();**  
**String StopMeasure();**  
**void setup() {**  
\*\* // put your setup code here, to run once:\*\*  
\*\* Serial.begin(9600);//Serial debug baud rate\*\*  
\*\* while (!Serial) {\*\*  
\*\* ; // wait for serial port to connect. Needed for native USB port only\*\*  
\*\* }\*\*  
\*\* // Start both software serial ports\*\*  
\*\* portOne.begin(115200); //Laser ranging module baud rate\*\*  
**}**  
**void loop() {**  
\*\* String temp="";\*\*  
\*\* temp= ReadData();\*\*  
\*\* if(temp == LASER\_OPEN)\*\*  
\*\* Measure(STEP\_LASER\_OPEN);\*\*  
\*\* else if(temp == MEASURE\_ONE)\*\*  
\*\* Measure(STEP\_MEASURE\_ONE);\*\*  
\*\* else if(temp == MEASURE\_CONTINUE)\*\*  
\*\* Measure(STEP\_MEASURE\_CONTINUE);\*\*  
\*\* else if(temp == STOP\_MEASURE)\*\*  
\*\* Measure(STEP\_STOP\_MEASURE);\*\*  
\*\* else if(temp != "")\*\*  
\*\* Serial.print("UNDEFINED COMMEND\r\n");\*\*  
\*\* if(measure\_continue\_flag==1)\*\*  
\*\* {\*\*  
\*\* measure\_continue\_data();\*\*  
\*\* }\*\*  
**;**  
**}**  
**void Measure(char STEP\_MEASURE\_COMMEND)//distance measurement**  
**{**  
\*\* String temp="";\*\*  
\*\* switch(STEP\_MEASURE\_COMMEND)\*\*  
\*\* {\*\*  
\*\* case STEP\_LASER\_OPEN:\*\*  
\*\* temp = LaserOpen();\*\*  
\*\* if(temp!= "-1")\*\*  
\*\* {\*\*  
\*\* Serial.print("LASER OPEN SUCCEED\r\n");\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* Serial.print("LASER OPEN FAILD\r\n");\*\*  
\*\* }\*\*  
\*\* break;\*\*  
\*\* case STEP\_MEASURE\_ONE:\*\*  
\*\* temp = MeasureOne();\*\*  
\*\* if(temp!= "-1")\*\*  
\*\* {\*\*  
\*\* if(temp.indexOf("&")==9 | temp.lastIndexOf("$")==10)\*\*  
\*\* {\*\*  
\*\* temp=temp.substring(20,22)+"."+temp.substring(22,27);\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* temp=temp.substring(10,12)+"."+temp.substring(12,17);\*\*  
\*\* }\*\*  
\*\* temp="distanc="+temp+"m"+"\r\n";\*\*  
\*\* Serial.print(temp);\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* Serial.print("MEASURE\_ONE FAILD\r\n");\*\*  
\*\* }\*\*  
\*\* break;\*\*  
\*\* case STEP\_MEASURE\_CONTINUE:\*\*  
\*\* Serial.print("MEASURE\_CONTINUE START\r\n");\*\*  
\*\* temp=MeasureContinue();\*\*  
\*\* measure\_continu\_cnt=0;\*\*  
\*\* measure\_continue\_flag=1;\*\*  
\*\* if(temp!= "-1")\*\*  
\*\* {\*\*  
\*\* if(temp.indexOf("&")==9 | temp.lastIndexOf("$")==10)\*\*  
\*\* {\*\*  
\*\* temp=temp.substring(24,26)+"."+temp.substring(26,29);\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* temp=temp.substring(14,16)+"."+temp.substring(16,19);\*\*  
\*\* }\*\*  
\*\* temp="distanc="+temp+"m"+"\r\n";\*\*  
\*\* Serial.print(temp);\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* Serial.print("MEASURE\_ONE FAILD\r\n");\*\*  
\*\* } \*\*  
\*\* break;\*\*  
\*\* case STEP\_STOP\_MEASURE:\*\*  
\*\* temp = StopMeasure();\*\*  
\*\* measure\_continu\_cnt=0;\*\*  
\*\* measure\_continue\_flag=0;\*\*  
\*\* Serial.print("MEASURE STOP\r\n"); \*\*  
\*\* break; \*\*  
\*\* default:\*\*  
\*\* break;\*\*  
\*\* }\*\*  
**}**  
**//Turn on the laser pointer**  
**String LaserOpen()**  
**{**  
\*\* String return\_data="";\*\*  
\*\* unsigned char temp=0;\*\*  
\*\* portOne.listen();\*\*  
\*\* if (portOne.isListening()) {\*\*  
\*\* portOne.flush();\*\*  
\*\* portOne.print("$0003260130&");\*\*  
\*\* return\_data = Serial\_One\_ReadData(22);\*\*  
\*\* return return\_data;//Turn on the laser module\*\*  
\*\* }\*\*  
**}**  
**//Single range measurement**  
**String MeasureOne()**  
**{**  
\*\* String return\_data="";\*\*  
\*\* unsigned char temp=0;\*\*  
\*\* portOne.listen();\*\*  
\*\* if (portOne.isListening()) {\*\*  
\*\* portOne.flush();\*\*  
\*\* portOne.print("$00022123&");\*\*  
\*\* return\_data = Serial\_One\_ReadData(28);\*\*  
\*\* return return\_data;\*\*  
\*\* }\*\*  
**}**  
**//Continuous ranging**  
**String MeasureContinue()**  
**{**  
\*\* String return\_data="";\*\*  
\*\* unsigned char temp=0;\*\*  
\*\* portOne.listen();\*\*  
\*\* if (portOne.isListening()) {\*\*  
\*\* portOne.flush();\*\*  
\*\* portOne.print("$00022426&");\*\*  
\*\* return\_data = Serial\_One\_ReadData(48);\*\*  
\*\* return return\_data;\*\*  
**}**  
**}**  
**void measure\_continue\_data()**  
**{**  
\*\* String temp="";\*\*  
\*\* temp=Serial\_One\_ReadData(38);\*\*  
\*\* measure\_continu\_cnt++;\*\*  
\*\* if(temp.substring(17,19)=="15"|temp.substring(17,19)=="16"|temp.substring(17,19)=="")\*\*  
\*\* {\*\*  
\*\* Serial.print( measure\_continu\_cnt);\*\*  
\*\* Serial.print("ERROR\r\n");\*\*  
\*\* temp=MeasureContinue();\*\*  
\*\* temp=temp.substring(24,26)+"."+temp.substring(26,29);;//¼ÓÈëĞ¡Êıµã\*\*  
\*\* Serial.print( measure\_continu\_cnt);\*\*  
\*\* temp=" distanc="+temp+"m"+"\r\n";\*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* temp=temp.substring(14,16)+"."+temp.substring(16,19);;//¼ÓÈëĞ¡Êıµã\*\*  
\*\* Serial.print( measure\_continu\_cnt);\*\*  
\*\* temp=" distanc="+temp+"m"+"\r\n";\*\*  
\*\* }\*\*  
\*\* Serial.print(temp); \*\*  
**}**  
**//Stop measurement**  
**String StopMeasure()**  
**{**  
\*\* String return\_data="";\*\*  
\*\* unsigned char temp=0;\*\*

\*\* portOne.listen();\*\*  
\*\* if (portOne.isListening()) {\*\*  
\*\* portOne.flush();\*\*  
\*\* portOne.print("$0003260029&");\*\*  
\*\* return\_data = Serial\_One\_ReadData(22);\*\*  
\*\* return return\_data;\*\*  
**}**  
**}**  
**//Read serial port to return data**  
**String ReadData()**  
**{**  
\*\* int wait\_time=0;\*\*  
\*\* String return\_data="";\*\*  
\*\* do\*\*  
\*\* {\*\*  
\*\* delay(1);\*\*  
\*\* wait\_time++;\*\*  
\*\* while(Serial.available()\>0)//serial data read\*\*  
\*\* {\*\*  
\*\* char CharRead=Serial.read();\*\*  
\*\* if(CharRead!=10&&CharRead!=13)\*\*  
\*\* {\*\*  
\*\* return\_data +=CharRead;\*\*  
\*\* }\*\*  
\*\* wait\_time=0;\*\*  
\*\* }\*\*  
\*\* }\*\*  
\*\* while(wait\_time\<500); //Wait for 1 second, no data is returned, the read is finished.\*\*  
\*\* return return\_data;\*\*  
**}**  
**//Read serial port to return data**  
**String Serial\_One\_ReadData(char Length)**  
**{**  
\*\* int wait\_time=0;\*\*  
\*\* String return\_data="";\*\*  
\*\* do\*\*  
\*\* {\*\*  
\*\* delay(1);\*\*  
\*\* wait\_time++;\*\*  
\*\* while( portOne.available()\>0)//serial data read\*\*  
\*\* {\*\*  
\*\* char CharRead= portOne.read();\*\*  
\*\* if(CharRead!=10&&CharRead!=13)\*\*  
\*\* {\*\*  
\*\* return\_data +=CharRead;\*\*  
\*\* }\*\*  
\*\* wait\_time=0;\*\*  
\*\* if(return\_data.length()\>=Length)\*\*  
\*\* {\*\*  
\*\* wait\_time=6000;\*\*  
\*\* }\*\*  
\*\* }\*\*  
\*\* }\*\*  
\*\* while(wait\_time\<2000); //Wait for 1 second, no data is returned, the read is finished.\*\*  
\*\* unsigned char last\_byte=(unsigned char)return\_data.charAt(return\_data.length()-1);\*\*  
\*\* if( wait\_time == 6000)\*\*  
\*\* { \*\*  
\*\* }\*\*  
\*\* else\*\*  
\*\* {\*\*  
\*\* return\_data="-1";\*\*  
\*\* }\*\*  
\*\* return return\_data;\*\*  
**}[/color]**

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [May 9, 2018, 6:25am UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/13 "2018-05-09T06:25:16Z")

</div>

Do not cross post :

[https://forum.arduino.cc/index.php?topic=546114.msg3723044#msg3723044](https://forum.arduino.cc/index.php?topic=546114.msg3723044#msg3723044)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 5:37pm UTC](https://forum.arduino.cc/t/how-to-program-due-serial-ports/207911/14 "2021-05-06T17:37:42Z")

</div>


