<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="font-size: 18pt;">ESP32 , 아두이노로 시리얼 통신</span></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><b>아두이노&nbsp; ESP32 통신 함수 참고</b></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><a href="https://esp32io.com/ko/reference/esp32-serial" target="_blank" class="con_link" style="text-decoration-line: none; overflow-wrap: break-word;">https://esp32io.com/ko/reference/esp32-serial</a></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">괜찮음</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">예제도 있음</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><b>참고</b></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">ESP32 Serial 통신 라이브러리, software Serial</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="color: #ef007c;">아래 참고 사이트의&nbsp;</span><span style="color: #ef007c;">내용을 그대로 정리해놓는다.</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><a href="https://postpop.tistory.com/35" target="_blank" class="con_link" style="text-decoration-line: none; overflow-wrap: break-word;">https://postpop.tistory.com/35</a></p>
<div align="" style="line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff; margin-left: 40px;">
   <div class="og" style="display: inline-block; width: 513px; margin-top: 7px; text-align: left; font-family: Dotum; box-shadow: rgb(249, 249, 249) 0px 1px 0px; line-height: 1.5;">
      <div class="box" style="display: inline-block; overflow: hidden; position: relative; width: 513px; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: top; line-height: 1.5;">
         <div class="txt" style="overflow: hidden; width: 471px; height: 134px; padding: 0px 20px; border: 1px solid rgb(226, 226, 226); background: rgb(252, 252, 252); cursor: pointer; line-height: 1.5;"><a href="https://postpop.tistory.com/35" target="_blank" style="text-decoration-line: none;">
               <div class="tit" style="overflow: hidden; max-height: 40px; margin-top: 17px; font-weight: bold; font-size: 14px; color: #222222; word-break: keep-all; overflow-wrap: break-word; line-height: 1.5;">ESP32 Serial 통신 라이브러리, software Serial?</div>
               <div class="dsc" style="overflow: hidden; max-height: 34px; margin: 8px 0px 3px; font-size: 11px; color: #4f4f4f; letter-spacing: -1px; word-break: keep-all; overflow-wrap: break-word; line-height: 1.5;">ESP32 DevKit ESP-WROOM-32 core를 장착하고 듀얼 CPU, Clock Speed가&nbsp;240 Mhz인 아두이노 IDE 개발환경에서 사용할 수 있...</div>
               <div class="cp" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; color: #9197a3; overflow-wrap: normal; line-height: 1.5;">postpop.tistory.com</div>
               </a></div>
         </div>
      </div>
   <div align="left" style="line-height: 1.5;"><img src="https://ssl.pstatic.net/static/blog/blank.gif" class="m20 egjs-visible" alt="" style="border: none; display: block; width: 1px; height: 20px;" /></div>
   </div>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">ESP32는&nbsp;<span style="color: #ef007c;">하드웨어 시리얼 3개를 제공</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">소프트웨어 시리얼 라이브러리 대신 하드웨어 시리얼 라이브러리를 통해 시리얼 관련 설정</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">소프트웨어 시리얼 라이브러리가 없다</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">include &lt;HardwareSerial.h&gt; // 하드웨어 시리얼 라이브러리</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">시리얼 통신: Serial (UART0), Serial1 (UART1), Serial2 (UART2) 3개의 하드웨어 시리얼을 제공</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="color: #0075c8;">시리얼 통신에 할당된 기본 핀번호</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO01 TX0 - HardwareSerial (0), 핀번호 변경 불가&nbsp;&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO03 RX0 - HardwareSerial (0), 핀번호 변경 불가&nbsp; &nbsp;&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO10 TX1 - HardwareSerial (1), FLASH 연결에 사용, 핀번호 변경 가능</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO09 RX1 - HardwareSerial (1), FLASH 연결에 사용, 핀번호 변경 가능&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO17 TX2 - HardwareSerial (2), 핀번호 변경 가능&nbsp; &nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">GPIO16 RX2 - HardwareSerial (2), 핀번호 변경 가능</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">하지만 GPIO&nbsp;<span style="color: #ef007c;">6, 7, 8, 9, 10, 11</span>&nbsp;(the integrated SPI flash)은 플레시 메모리연결에 할당되어 있어서&nbsp;<span style="color: #ef007c;">해당&nbsp;</span><span style="color: #ef007c;">핀을 사용할 수 없다</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">하드웨어 Serial1의 TX1과 RX1에 할당된 GPIO 핀의 번호는 10번과 9번이다. 이 핀을 이용해서는 Serial1을 사용할 수 없다. 그러므로 Serial1을 위한 TX1과 RX1에 플래시 메모리에 사용되지 않은 핀을 할당해주어야 한다. 이를 위한 규칙이 있는데 아래와 같다.&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="color: #ff0000;"><b>1.</b></span>&nbsp;시리얼 장치의 이름으로 Serial, Serial1, Serial2를 사용하고 기본 할당핀을 사용 할 경우 setup() 함수에서만 시작하면 된다.</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp;<span style="color: #7820b9;"><b>Serial.begin(115200);</b></span>&nbsp; &nbsp;// UART0 -&gt; usb 연결과 공유,&nbsp;<span style="color: #ef007c;">핀번호 변경 불가</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp;Serial1.begin(115200); // 통신에 할당된 기본핀이 플래시 메모리에 할당된 GPIO 10번과 9번이므로&nbsp;<span style="color: #ef007c;">사용불가</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;&nbsp;<b><span style="color: #7820b9;">&nbsp;</span><span style="color: #7820b9;">Serial2.begin(115200);</span></b>&nbsp;// UART2&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><b><span style="color: #ff0000;">2.</span></b>&nbsp;시리얼 장치의 이름을 Serial, Serial1, Serial2이 아닌 사용자 이름을 사용할 경우 장치명을 선언해주고 setup() 함수에서 시작시 핀번호를 포함하는 통신 규칙을 설정해주어야 한다.&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; HardwareSerial mySerial(1);&nbsp; // 장치명 선언(시리얼 번호)</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;&nbsp;<span style="color: #7820b9;"><b>HardwareSerial dfSerial(2);</b></span>&nbsp; // 장치명 선언(시리얼 번호)</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; mySerial.begin(115200,SERIAL_8N1, 4, 2);&nbsp; // (통신속도, UART모드, RX핀번호, TX핀번호) - 핀번호 지정가능</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;&nbsp;<span style="color: #7820b9;"><b>dfSerial.begin(115200, SERIAL_8N1, 16, 17);</b></span>&nbsp; // 핀번호는 기본으로 할당된 번호도 사용할 수 있다.&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">하드웨어 시리얼 3개를 동시에 사용하기 위해서는 Serial1을 사용자 장치명으로 선언해주고 시작시 규칙을 설정 해주어야 하는데, 이 때에는 사용상 주의가 필요하다.</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">스케치 업로드시 발생할 수 있는 "A fatal error occurred: Timed out waiting for packet header" 에러</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">상기에러는 하드웨어 "Serial1"을 사용하기 위해 gpio 6 ~ 11번을 제외한 핀번호를 할당하고 사용할 때 전원이 들어가 있는 연결된 장치의 통신용 핀이 스케치 업로드시 연결되어 있을경우 발생 한다. 기본 할당된 시리얼 통신용 핀에서는 연결장치가 연결되고 전원이 들어가 있는 상태에서도 오류없이 스케치 업로드가 잘된다.&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">mySerial.begin(115200,SERIAL_8N1, 4, 2); // "Serial1"을 시리얼 통신용 사용자 핀번호(4, 2)로 지정하고 전원이 인가된 연결장치의 통신선이 연결되어 있다. -&gt; 스케치 업로드시 오류 발생</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">해결 방법</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">1. 꼭 필요한 경우가 아니면 하드웨어&nbsp;<span style="color: #ef007c;">시리얼 1번을 사용하지 않는다.&nbsp;&nbsp;</span></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><span style="color: #000000;">2. 시리얼 1번을 사용자 핀번호 지정으로 사용할 경우 연결장치의 전</span><span style="color: #000000;">원</span>을 끄거나 시리얼 통신의 연결을 제거하고 스케치를 업로드 해본다.&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">참고 2</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><a href="https://arduinoblog.tistory.com/6" target="_blank" class="con_link" style="text-decoration-line: none; overflow-wrap: break-word;">https://arduinoblog.tistory.com/6</a></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">UART(Serial) 통신</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; ESP32에는 Serial 통신 핀이 3가지가 있지만&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; 그중 한 가지는 업로드때 사용해서 못 쓰고,&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; 다른 한가지는 쓸 수 없는 핀에 연결되어 있어서 다른 방법으로 핀을 바꿔줘야 쓸 수 있어서&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp;&nbsp;<span style="color: #ef007c;">쉽게 쓸 수 있는 Serial 통신 핀은 한 가지밖에 없다</span>.</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; Serial</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; RX : RXD</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; TX : TXD</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; Serial 1 *이거 쓰고 싶으면 핀을 바꿔야 한다.</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; RX : SD2</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; TX : SD3</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; Serial2</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; RX : 16번</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp; TX : 17번</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; *컴퓨터에서 소스코드를 업로드할 때 RXD, TXD를 이용해서 통신하고,&nbsp;</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; &nbsp;SD2, SD3는 ESP32 Flash 메모리와 연결되어있어서 RXD, TXD, SD2, SD3를 이용하면 업로드 오류가 날 수도 있어서</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;&nbsp;&nbsp;<span style="color: #ef007c;"><b>ESP32에서는 보통 Serial2를 이용해야 한다</b></span>.</p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp; *ESP32에서는 SoftwareSerial을 지원하지 않음</p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><b><span style="color: #3a32c3; font-size: 12pt;">예제</span></b></p>
<p style="margin-left: 40px; padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<div style="line-height: 19px; text-align: justify; color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, &quot;Courier New&quot;, monospace; font-size: 14px; white-space: pre;">
   <div style="line-height: 1.5;"><span style="color: #c586c0;">#include</span><span style="color: #569cd6;">&nbsp;</span><span style="color: #ce9178;">&lt;HardwareSerial.h&gt;</span></div>
   <div style="line-height: 1.5;">HardwareSerial&nbsp;<span style="color: #dcdcaa;">mySerial</span>(<span style="color: #b5cea8;">2</span>);&nbsp;<span style="color: #6a9955;">//3개의&nbsp;시리얼&nbsp;중&nbsp;2번&nbsp;채널을&nbsp;사용</span></div>
   <br />
   <div style="line-height: 1.5;"><span style="color: #569cd6;">void</span>&nbsp;<span style="color: #dcdcaa;">setup</span>()&nbsp;{</div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #9cdcfe;">Serial</span>.<span style="color: #dcdcaa;">begin</span>(<span style="color: #b5cea8;">115200</span>);&nbsp;<span style="color: #6a9955;">//기존의&nbsp;기본&nbsp;시리얼</span></div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #9cdcfe;">mySerial</span>.<span style="color: #dcdcaa;">begin</span>(<span style="color: #b5cea8;">115200</span>,&nbsp;SERIAL_8N1,&nbsp;<span style="color: #b5cea8;">12</span>,&nbsp;<span style="color: #b5cea8;">13</span>);&nbsp;<span style="color: #6a9955;">//추가로&nbsp;사용할&nbsp;시리얼.&nbsp;RX:12&nbsp;/&nbsp;TX:13번&nbsp;핀&nbsp;사용</span></div>
   <div style="line-height: 1.5;">}</div>
   <br />
   <div style="line-height: 1.5;"><span style="color: #569cd6;">void</span>&nbsp;<span style="color: #dcdcaa;">loop</span>()&nbsp;{</div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #c586c0;">if</span>(<span style="color: #9cdcfe;">mySerial</span>.<span style="color: #dcdcaa;">available</span>()&nbsp;&gt;&nbsp;<span style="color: #b5cea8;">0</span>){</div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;command&nbsp;=&nbsp;<span style="color: #9cdcfe;">mySerial</span>.<span style="color: #dcdcaa;">readStringUntil</span>(<span style="color: #ce9178;">'</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">'</span>);&nbsp;<span style="color: #6a9955;">//추가&nbsp;시리얼의&nbsp;값을&nbsp;수신하여&nbsp;String으로&nbsp;저장</span></div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #9cdcfe;">Serial</span>.<span style="color: #dcdcaa;">println</span>(command);&nbsp;<span style="color: #6a9955;">//기본&nbsp;시리얼에&nbsp;추가&nbsp;시리얼&nbsp;내용을&nbsp;출력</span></div>
   <div style="line-height: 1.5;">&nbsp;&nbsp;&nbsp;&nbsp;}</div>
   <div style="line-height: 1.5;">}</div>
   </div>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;"><br /></p>
<p style="padding: 0px; line-height: 1.5; color: #615652; font-family: 돋움; text-align: justify; background-color: #ffffff;">&nbsp;</p>
<p>
   <p>&nbsp;</p>
   </p>
<div class="autosourcing-stub-extra" style="line-height: 1.5; zoom: 1; opacity: 1;">
   <p style="margin: 11px 0px 7px; padding: 0px; line-height: 1.5; font-size: 12px; font-family: Dotum; font-style: normal; font-weight: normal;"><strong style="padding: 0px 7px 0px 0px;">[출처]</strong><span>&nbsp;</span><a href="https://blog.naver.com/heennavi1004/222316035038" target="_blank" style="text-decoration: none;">[ESP32, Serial] ESP32 시리얼 통신 (1)</a><span style="padding: 0px 7px 0px 5px;">|</span><strong style="padding: 0px 7px 0px 0px;">작성자</strong><span>&nbsp;</span><a href="https://blog.naver.com/heennavi1004" target="_blank" style="text-decoration: none;">초초</a></p>
   </div>