|
|
(4 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | __TOC__
| |
| | | |
− | <h1>Serial ports on the Arduino Due</h1>
| |
− |
| |
− | <h2>Native port Serial USB</h2>
| |
− |
| |
− | <p>The Native USB port is connected directly to the SAM3X MCU.</p>
| |
− | <p>The USB connector of the Native port is directly connected to the USB host pins of the SAM3X. Using the Native port enables you to use the Due as a client USB peripheral (acting as a mouse or a keyboard connected to the computer) or as a USB host device so that devices can be connected to the Due (like a mouse, keyboard, or an Android phone). This port can also be used as a virtual serial port using the '''"SerialUSB"''' object in the Arduino programming language. It is not necessary set a baud rate because Arduino Due will offer the maximun baud rate.</p>
| |
− |
| |
− | <h2>Programming port Serial</h2>
| |
− | <p>The Programming port is connected to an ATMEL 16U2 which acts as a USB-to-Serial converter. This Programming port is the default for uploading sketches and communicating with the Arduino.</p>
| |
− | <p>The USB-to-serial converter of the Programming port is connected to the first UART of the SAM3X. It's possible to communicate over this port using the '''"Serial"''' object in the Arduino programming language.</p>
| |
− |
| |
− |
| |
− | <h1>Automatic (Software) Reset</h1>
| |
− |
| |
− | <h2>Native port</h2>
| |
− | <p>To use the serial monitor, and see what your sketch does from the beginning, you'll need to add few lines of code inside the setup(). This will ensure the SAM3X will wait for the SerialUSB port to open before executing the sketch:
| |
− | <pre>
| |
− | while (!Serial);
| |
− | </pre>
| |
− | <p>Pressing the Reset button on the Due causes the SAM3X reset as well as the USB communication. This interruption means that if the serial monitor is open, it's necessary to close and reopen it to restart the communication.</p>
| |
− |
| |
− | <h2>Programming port</h2>
| |
− | <p>The USB-to-serial chip has two pins connected to the Reset and Erase pins of the SAM3X. When you open this serial port, the USB-to-Serial activates the Erase and Reset sequence before it begins communicating with the UART of the SAM3X.</p>
| |
− | <p> The Programming port resets the board each time you open the serial monitor (or any other serial communication).</p>
| |
− |
| |
− | <h1>Communication Arduino Due-PC. Native Port</h1>
| |
− | <p>To send information from the Arduino Due to the PC using the Native port, you need write</p>:
| |
− | <pre>
| |
− | SerialUSB.println("String");
| |
− | </pre>
| |
− | <p>where String is the information that you want to transmit.</p>
| |
− | <p>To receive this information in your PC is neccesary open the USB port</p>
| |
− | <pre>
| |
− | int fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
| |
− |
| |
− | /* wait for the Arduino to reboot */
| |
− | usleep(500000);
| |
− |
| |
− | if (fd == -1){
| |
− | /*
| |
− | * Could not open the port.
| |
− | */
| |
− |
| |
− | perror("open_port: Unable to open /dev/ttyCOM0 - ");
| |
− | }else{
| |
− | fcntl(fd, F_SETFL, 0);
| |
− | }
| |
− | </pre>
| |
− | <p>By default the connection between Arduino Due and PC is performed thought COM0 port, if this port is already in use you must see the active port using the command:</p>
| |
− | <pre>
| |
− | ll /dev/ttyACM*
| |
− | </pre>
| |