{"id":7151,"date":"2021-12-23T14:50:25","date_gmt":"2021-12-23T14:50:25","guid":{"rendered":"https:\/\/www.qec.tw\/?p=7151"},"modified":"2022-05-04T10:03:17","modified_gmt":"2022-05-04T10:03:17","slug":"serial","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/zh\/86duino-reference\/serial\/","title":{"rendered":"Serial"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[Communication]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Used for communication between the 86Duino board and a computer or other devices. All 86Duino boards have at least one serial port (also known as a UART or USART):&nbsp;<strong>Serial1<\/strong>. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer (via a TTL USB-to-serial adaptor). Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the 86Duino or Arduino environments\u2019 built-in serial monitor to communicate with an 86Duino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to&nbsp;<code>begin()<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The 86Duino One and EduCake have two additional serial ports:&nbsp;<strong>Serial2<\/strong>&nbsp;on pins 17 (RX) and 16 (TX) and&nbsp;<strong>Serial3<\/strong>&nbsp;on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will also need an additional TTL USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device\u2019s RX pin, the RX to your device\u2019s TX pin, and the ground of your 86Duino to your device\u2019s ground. (Don\u2019t connect these pins directly to an RS232 serial port; RS232 ports operate at +\/- 12V and can damage your 86Duino board.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, for all 86Duino boards, there is a native USB-serial port,&nbsp;<strong>Serial<\/strong>. This port is used for USB CDC communication, and its usage is the same as the Arduino Leonardo. For more information, you may refer to the Arduino Leonardo&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Guide\/ArduinoLeonardo\" target=\"_blank\" rel=\"noopener\">getting started<\/a>&nbsp;page and&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Main\/ArduinoBoardLeonardo\" target=\"_blank\" rel=\"noopener\">hardware<\/a>&nbsp;page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">86Duino-Specific Half-Duplex Mode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each of the TTL serial ports&nbsp;<code>Serial1<\/code>,&nbsp;<code>Serial2<\/code>, and&nbsp;<code>Serial3<\/code>&nbsp;supports the half-duplex mode, in which you can transmit and receive serial data using only the TX pin. This mode allows that you connect 86Duino directly to certain of AI servos, such as&nbsp;<a href=\"http:\/\/www.robotis.com\/xe\/dynamixel_en\" target=\"_blank\" rel=\"noopener\">Robotis Dynamixel AX-12<\/a>, without external tri-state interface circuits. The half-duplex mode can be selected by the&nbsp;<code>begin()<\/code>&nbsp;function of&nbsp;<code>Serial1<\/code>,&nbsp;<code>Serial2<\/code>, and&nbsp;<code>Serial3<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The RS232 and RS485 Serial Ports<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The 86Duino EduCake and 86Duino PLC support a 9-pin&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/RS-232\" target=\"_blank\" rel=\"noopener\">RS232<\/a>&nbsp;serial port, operating at +\/- 12V, and you can access it using&nbsp;<strong>Serial232<\/strong>. The 86Duino One and 86Duino PLC support a&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/RS-485\" target=\"_blank\" rel=\"noopener\">RS485<\/a>&nbsp;serial port and you can access it using&nbsp;<strong>Serial485<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The usage of both&nbsp;<code>Serial232<\/code>&nbsp;and&nbsp;<code>Serial485<\/code>&nbsp;is the same as&nbsp;<code>Serial1<\/code>,&nbsp;<code>Serial2<\/code>, and&nbsp;<code>Serial3<\/code>, but the half-duplex mode isn\u2019t defined for these two ports.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Functions<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/if-serial\/\">if (Serial)<\/a><\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-available\/\">available<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-begin\/\">begin<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-end\/\">end<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-find\/\">find<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-finduntil\/\">findUntil<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-flush\/\">flush<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-parsefloat\/\">parseFloat<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-parseint\/\">parseInt<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-peek\/\">peek<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-print\/\">print<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-println\/\">println<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-read\/\">read<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-readbytes\/\">readBytes<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-readbytesuntil\/\">readBytesUntil<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-settimeout\/\">setTimeout<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serial-write\/\">write<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-reference\/serial\/serialevent\/\">serialEvent<\/a>()<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Examples<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following are&nbsp;<code>Serial<\/code>&nbsp;examples from the&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Tutorial\/HomePage\" target=\"_blank\" rel=\"noopener\">Arduino Tutorial<\/a>&nbsp;that can work on the 86Duino boards:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/ReadASCIIString\" target=\"_blank\" rel=\"noreferrer noopener\">ReadASCIIString<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/ASCIITable\" target=\"_blank\" rel=\"noreferrer noopener\">ASCII Table<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/Dimmer\" target=\"_blank\" rel=\"noreferrer noopener\">Dimmer<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/Graph\" target=\"_blank\" rel=\"noreferrer noopener\">Graph<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/PhysicalPixel\" target=\"_blank\" rel=\"noreferrer noopener\">Physical Pixel<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/VirtualColorMixer\" target=\"_blank\" rel=\"noreferrer noopener\">Virtual Color Mixer<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/SerialCallResponse\" target=\"_blank\" rel=\"noreferrer noopener\">Serial Call Response<\/a><\/li><li><a href=\"http:\/\/arduino.cc\/en\/Tutorial\/SerialCallResponseASCII\" target=\"_blank\" rel=\"noreferrer noopener\">Serial Call Response ASCII<\/a><\/li><\/ul>\n\n\n<hr>\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.qec.tw\/86duino\/86duino-language-reference\/\">Language Reference Home<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The text of the 86Duino reference is a modification of&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Reference\/HomePage\" target=\"_blank\" rel=\"noopener\">the Arduino reference<\/a>&nbsp;and is licensed under a&nbsp;<a href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/\" target=\"_blank\" rel=\"noopener\">Creative Commons Attribution-ShareAlike 3.0 License<\/a>. Code samples in the reference are released into the public domain.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Communication] Description Used for communication between the 86Duino board and a computer or other devices. All 86Duino boards have at least one serial port (also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7152,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[195],"tags":[162],"class_list":["post-7151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-86duino-reference","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/7151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/comments?post=7151"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/7151\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media\/7152"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media?parent=7151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/categories?post=7151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/tags?post=7151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}