<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt; color: #212121;">이전에&nbsp;</span><span style="font-size: 10pt; color: #212121;">아두이노에서 설정한 문자열을 라즈베리파이를 통해 Serial로 연결하여 수신받는 예제를 확인해 보았다. 이번에는 반대로 라즈베리파이에서 텍스트파일을 읽어와 아두이노에 뿌려줄 수 있는</span><span style="font-size: 10pt; color: #212121;">&nbsp;통신을 구축</span><span style="font-size: 10pt; color: #212121;">해보도록 하자. 필자의 경우에는&nbsp;</span><span style="font-size: 10pt; color: #212121;">라즈베리파이에 있는</span><span style="font-size: 10pt; color: #212121;">&nbsp;파일을 아두이노 SD카드에 전송하고자하는 특수한 목적 때문에 본 예제를 활용했을뿐 실상 잘 쓰이는 방법이</span><span style="font-size: 10pt; color: #212121;">&nbsp;아니기 때문에 그냥 이렇게도 가능하구나 정도만 이해하고 넘어가도 될 듯 하다.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt; color: #212121;">예제의 경우 이전과 같은 예제를 활용하였으며 파일을 읽어 아두이노에 전송하기 위해 약간의 수정을 가했다. 따라서 수정된 부분에 대한 설명을 위해 C언어 파일 입출력에 대한 간단한 개념을 기술하였고 이를 통해 아두이노와 직접 통신하는 부분까지 진행해보자.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 10pt; color: #212121;"><b>1. 파일 문자열 송신 예제</b></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; line-height: 2; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;">
   <table class="colorscripter-code-table" cellspacing="0" cellpadding="0" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; border-color: initial; background-color: #fafafa; border-radius: 4px;">
      <tbody>
         <tr>
            <td style="margin: 0px; padding: 6px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f; border-right: 2px solid rgb(229, 229, 229);">
               <div style="margin: 0px; padding: 0px; word-break: normal; text-align: right; color: #666666; line-height: 15.6px; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important;">
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">1</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">2</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">3</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">4</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">5</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">6</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">7</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">8</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">9</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">10</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">11</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">12</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">13</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">14</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">15</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">16</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">17</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">18</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">19</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">20</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">21</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">22</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">23</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">24</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">25</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">26</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">27</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">28</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">29</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">30</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">31</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">32</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">33</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">34</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">35</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">36</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">37</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">38</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">39</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">40</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">41</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">42</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">43</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">44</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">45</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">46</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">47</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">48</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">49</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">50</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">51</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">52</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">53</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">54</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">55</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">56</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">57</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">58</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">59</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">60</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">61</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">62</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">63</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">64</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">65</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">66</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">67</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">68</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">69</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">70</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">71</div>
                  </div>
               </td>
            <td style="margin: 0px; padding: 6px 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f;">
               <div style="margin: 0px; padding: 0px; color: #010101; line-height: 15.6px; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important;">
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#ifdef</span>&nbsp;RaspberryPi&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>stdio.h<span style="color: #ff3399;">&gt;</span>&nbsp;<span style="color: #999999;">//for&nbsp;printf</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>stdint.h<span style="color: #ff3399;">&gt;</span>&nbsp;<span style="color: #999999;">//uint8_t&nbsp;definitions</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>stdlib.h<span style="color: #ff3399;">&gt;</span>&nbsp;<span style="color: #999999;">//for&nbsp;exit(int);</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span><span style="color: #0099cc;">string</span>.h<span style="color: #ff3399;">&gt;</span>&nbsp;<span style="color: #999999;">//for&nbsp;errno</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>errno.h<span style="color: #ff3399;">&gt;</span>&nbsp;<span style="color: #999999;">//error&nbsp;output</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>wiringPi.h<span style="color: #ff3399;">&gt;</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#include</span>&nbsp;<span style="color: #ff3399;">&lt;</span>wiringSerial.h<span style="color: #ff3399;">&gt;</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">char</span>&nbsp;device[]<span style="color: #ff3399;">=</span>&nbsp;<span style="color: #993333;">"/dev/ttyACM0"</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">int</span>&nbsp;fd;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">unsigned</span>&nbsp;<span style="color: #0099cc;">long</span>&nbsp;baud&nbsp;<span style="color: #ff3399;">=</span>&nbsp;<span style="color: #308ce5;">9600</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">unsigned</span>&nbsp;<span style="color: #0099cc;">long</span>&nbsp;time<span style="color: #ff3399;">=</span><span style="color: #308ce5;">0</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">char</span>&nbsp;strHello[]&nbsp;<span style="color: #ff3399;">=</span>&nbsp;<span style="color: #993333;">"HELLO"</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">char</span>&nbsp;cTemp[<span style="color: #308ce5;">512</span>]&nbsp;<span style="color: #ff3399;">=</span>&nbsp;{<span style="color: #308ce5;">0</span>};</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">int</span>&nbsp;ch;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">char</span>&nbsp;Endc;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #999999;">//prototypes</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">int</span>&nbsp;main(<span style="color: #ff3399;">void</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">void</span>&nbsp;loop(<span style="color: #ff3399;">void</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">void</span>&nbsp;setup(<span style="color: #ff3399;">void</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">void</span>&nbsp;setup(){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(<span style="color: #993333;">"%s&nbsp;\n"</span>,&nbsp;<span style="color: #993333;">"Raspberry&nbsp;Startup!"</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;fflush(stdout);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #999999;">//get&nbsp;filedescriptor</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #ff3399;">if</span>&nbsp;((fd&nbsp;<span style="color: #ff3399;">=</span>&nbsp;serialOpen&nbsp;(device,&nbsp;baud))&nbsp;<span style="color: #ff3399;">&lt;</span>&nbsp;<span style="color: #308ce5;">0</span>){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;fprintf&nbsp;(stderr,&nbsp;<span style="color: #993333;">"Unable&nbsp;to&nbsp;open&nbsp;serial&nbsp;device:&nbsp;%s\n"</span>,&nbsp;strerror&nbsp;(errno))&nbsp;;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;exit(<span style="color: #308ce5;">1</span>);&nbsp;<span style="color: #999999;">//error</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #999999;">//setup&nbsp;GPIO&nbsp;in&nbsp;wiringPi&nbsp;mode</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #ff3399;">if</span>&nbsp;(wiringPiSetup&nbsp;()&nbsp;<span style="color: #ff3399;">=</span><span style="color: #ff3399;">=</span>&nbsp;<span style="color: #ff3399;">-</span><span style="color: #308ce5;">1</span>){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;fprintf&nbsp;(stdout,&nbsp;<span style="color: #993333;">"Unable&nbsp;to&nbsp;start&nbsp;wiringPi:&nbsp;%s\n"</span>,&nbsp;strerror&nbsp;(errno))&nbsp;;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;exit(<span style="color: #308ce5;">1</span>);&nbsp;<span style="color: #999999;">//error</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #999999;">//&nbsp;main&nbsp;function&nbsp;for&nbsp;normal&nbsp;c++&nbsp;programs&nbsp;on&nbsp;Raspberry</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">int</span>&nbsp;main(){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;setup();</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;FILE&nbsp;<span style="color: #ff3399;">*</span>&nbsp;fp<span style="color: #ff3399;">=</span>fopen(<span style="color: #993333;">"/home/pi/Desktop/Work/transfer.txt"</span>,<span style="color: #993333;">"rt"</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #ff3399;">if</span>(fp<span style="color: #ff3399;">=</span><span style="color: #ff3399;">=</span>NULL){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(<span style="color: #993333;">"file&nbsp;open&nbsp;fail\n"</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff3399;">return</span>&nbsp;<span style="color: #ff3399;">-</span><span style="color: #308ce5;">1</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}<span style="color: #ff3399;">else</span>{&nbsp;&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(<span style="color: #993333;">"file&nbsp;open&nbsp;success\n"</span>);&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;<span style="color: #ff3399;">while</span>(fgets(cTemp,&nbsp;<span style="color: #ff3399;">sizeof</span>(cTemp),fp)&nbsp;<span style="color: #ff3399;">!</span><span style="color: #ff3399;">=</span>&nbsp;NULL){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serialPuts&nbsp;(fd,&nbsp;cTemp);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(cTemp);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">if</span>(feof(fp)&nbsp;<span style="color: #ff3399;">!</span><span style="color: #ff3399;">=</span>&nbsp;<span style="color: #308ce5;">0</span>){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(<span style="color: #993333;">"file&nbsp;upload&nbsp;success\n"</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="line-height: 15.6px;">}</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;<span style="color: #ff3399;">else</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0099cc;">printf</span>(<span style="color: #993333;">"file&nbsp;upload&nbsp;fail\n"</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;fclose(fp);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;<span style="color: #ff3399;">return</span>&nbsp;<span style="color: #308ce5;">0</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0086b3;">#endif</span>&nbsp;<span style="color: #999999;">//#ifdef&nbsp;RaspberryPi</span></div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  </div>
               <div style="margin: -13px 5px 0px 0px; padding: 0px; text-align: right; font-size: 9px; font-style: italic;"><a href="http://colorscripter.com/info#e" target="_blank" style="color: #e5e5e5; text-decoration-line: none;">Colored by Color Scripter</a></div>
               </td>
            <td style="margin: 0px; padding: 0px 2px 4px 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f; vertical-align: bottom;"><a href="http://colorscripter.com/info#e" target="_blank" style="color: white; text-decoration-line: none;"><span style="font-size: 9px; word-break: normal; border-radius: 10px; padding: 1px; background-color: #e5e5e5;">cs</span></a></td>
            </tr>
         </tbody>
      </table>
   <br /></div>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; text-align: justify; line-height: 2; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;"><span style="font-size: 10pt; color: #212121;">예제를 보면 아래 int main() 부분만 다르다는 것을 알 수 있다. 동작 순서를 간단히 언급하자면 설정된 경로의 텍스트 파일을 읽어와 각 줄단위로 읽고 이를&nbsp;아두이노로 전송하며 만약 파일의 끝부분에 도달했을 경우 통신을 마치게 되는 구조이다. 그럼 각 함수에 대해 간단하게 설명하도록 하겠다.</span></div>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; text-align: justify; line-height: 2; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;"><span style="font-size: 10pt;"><br /></span></div>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; text-align: justify; line-height: 2; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;"><span style="font-size: 10pt;"><br /></span></div>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; text-align: justify; line-height: 2; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;"><span style="font-size: 10pt; color: #212121;"><b>2. 코드 설명</b></span></div>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;">&nbsp;</p>
<table class="txc-table" width="100%" cellspacing="0" cellpadding="0" border="0" align="justify" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움;"></table>
<table class="txc-table" width="681" cellspacing="0" cellpadding="0" border="0" align="justify" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움; width: 681px;">
   <tbody>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 680px; height: 38px; border-style: solid; background-color: #ffffff;">
            <p><span style="color: #4c4c4c;"><b><span style="font-size: 10pt; font-family: Dotum, 돋움;">&nbsp;&nbsp;</span></b></span><b><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">FILE&nbsp;</span><span style="font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; color: #4c4c4c; font-size: 10pt; background-color: #fafafa;">*</span><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">&nbsp;fp</span><span style="font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; color: #4c4c4c; font-size: 10pt; background-color: #fafafa;">=</span><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">fopen(</span><span style="font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; color: #4c4c4c; font-size: 10pt; background-color: #fafafa;">"transfer.txt"</span><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">,</span><span style="font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; color: #4c4c4c; font-size: 10pt; background-color: #fafafa;">"rt"</span><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">)</span></b></p>
            </td>
         </tr>
      </tbody>
   </table>
<p><br style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;" /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;">&nbsp;</p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt; color: #212121;">C언어 프로그램상에서 파일에 저장되어 있는 데이터를 읽기 위해서는 데이터가 이동할 수 있는 다리 역할을 할 수 있는 스트림을 형성해야 한다. 쉽게 말해 파일로</span><span style="font-size: 10pt; color: #212121;">부터 데이터를 읽을 수 있는 최소한의 준비를 해주는 과정이라고 생각하면 된다. &nbsp;따라서 위 fopen 함수는 스트림 형성을 요청하는 호출문 역할을 하며 괄호 안에 첫번째 인자의 경우 읽어들일 파일의 경로를 뜻하고 두번째 인자는 형성할 스트림의 종류를 뜻하며 입력스트림과 출력스트림 이렇게 2가지 형태가 존재한다. 위 코드는 "rt" 로 설정하였으므로 입력스트림을 뜻하며 파일의 데이터를 읽을 수 있는 반면에 쓰지는 못하기 때문에 만약 데이터를 쓰기 원한다면 별도로 출력스트림을 다시 형성해야 한다. C언어에서는 이러한 개념을 바탕으로 총 6가지 스트림으로 세분화 할 수 있다.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;">&nbsp;</p>
<table class="txc-table" width="681" cellspacing="0" cellpadding="0" border="0" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움; width: 681px;">
   <tbody>
      <tr>
         <td rowspan="1" style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 24px; border-style: solid; background-color: #eaeaea;">
            <p style="text-align: center;"><span style="color: #212121;">&nbsp;모드</span></p>
            </td>
         <td rowspan="1" style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 24px; border-bottom-style: solid; border-right-style: solid; border-top-style: solid; background-color: #eaeaea;">
            <p style="text-align: center;"><span style="color: #212121;">내용</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 24px; border-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">r&nbsp;</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 24px; border-bottom-style: solid; border-right-style: solid; border-top-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;오직 읽기만 가능</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 62px; border-bottom-style: solid; border-right-style: solid; border-left-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">w</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 62px; border-bottom-style: solid; border-right-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;오직 쓰기만 가능</span></p>
            <p><span style="line-height: 1.5; color: #212121;">&nbsp; &nbsp;만약 파일이 존재하지 않으면 새로운 파일을 생성해서 데이터 쓰기</span></p>
            <p><span style="line-height: 1.5; color: #212121;">&nbsp; &nbsp;만약 파일이 존재하면 기존의 데이터를 지우고 데이터&nbsp;쓰기&nbsp;</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 24px; border-bottom-style: solid; border-right-style: solid; border-left-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">a</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 24px; border-bottom-style: solid; border-right-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;w 모드와 달리 파일이 존재하면 파일 끝에 덧붙여 데이터 추가</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 41px; border-bottom-style: solid; border-right-style: solid; border-left-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">r+&nbsp;</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 41px; border-bottom-style: solid; border-right-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;읽기와 쓰기 가능</span></p>
            <p><span style="color: #212121;">&nbsp; &nbsp;만약 파일이 존재하면 기존의 데이터를 지우지 않고 데이터 덮어 쓰기</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 41px; border-bottom-style: solid; border-right-style: solid; border-left-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">w+</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 41px; border-bottom-style: solid; border-right-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;읽기와 쓰기 가능</span></p>
            <p><span style="color: #212121;">&nbsp; &nbsp;만약 파일이 존재하면 기존의 데이터를 지우고 데이터 쓰기</span></p>
            </td>
         </tr>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 136px; height: 24px; border-bottom-style: solid; border-right-style: solid; border-left-style: solid; background-color: #ffffff;">
            <p style="text-align: center;"><span style="color: #212121;">a+</span></p>
            </td>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 544px; height: 24px; border-bottom-style: solid; border-right-style: solid; background-color: #ffffff;">
            <p><span style="color: #212121;">&nbsp; &nbsp;읽기와 쓰기&nbsp;가능 (쓰기의 경우 a 모드와 특징이 같다.)</span></p>
            </td>
         </tr>
      </tbody>
   </table>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;">&nbsp;</p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 10pt;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 10pt; color: #212121;">&nbsp;</span><span style="line-height: 21px;"><span style="font-size: 10pt; color: #212121;">"rt" 에서 뒤의 t는 텍스트모드를 뜻하며 t의 텍스트모드와 b의 바이너리모드가 있다고</span><span style="font-size: 10pt; color: #212121;">만 이해하고 넘어가자.&nbsp;</span></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<table class="txc-table" width="645" cellspacing="0" cellpadding="0" border="0" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움;"></table>
<table class="txc-table" width="681" cellspacing="0" cellpadding="0" border="0" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움; width: 681px;">
   <tbody>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 680px; height: 38px; border-style: solid; background-color: #ffffff;">
            <p><span style="color: #4c4c4c;"><b><span style="font-size: 10pt; font-family: Dotum, 돋움;">&nbsp; char *</span></b></span><b><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">fgets(char *string,&nbsp;</span><span style="font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; color: #4c4c4c; font-size: 10pt; background-color: #fafafa;">sizeof</span><span style="color: #4c4c4c; font-family: Dotum, 돋움; line-height: 15.6px; white-space: pre; font-size: 10pt; background-color: #fafafa;">(*string), File *stream)</span></b></p>
            </td>
         </tr>
      </tbody>
   </table>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt; color: #212121; line-height: 2;">위 함수는 텍스트 파일에 저장된 문자를 줄 단위로 읽어들어와 반환하는 함수로서 첫번째 인자인 *string은 입력 받은 문자열을 저장할 포인터(읽은 데이터를 잠시 저장하는 공간이라고만 생각하자)를 뜻하고 두번째 인자인 sizeof()는 입력 받을 문자의 수를 설정하는 것이며 세번째 인자인 파일 포인터는 형성한 스트림의 이름을 뜻한다. &nbsp;</span><span style="color: #212121; font-size: 13.3333px; line-height: 20px;">이 함수는 읽어드린 문자열에 대한 포인터를 반환하며 파일의 끝에 도달하거나 오류가 발생할 경우 NULL을 반환한다.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><br /></p>
<table class="txc-table" width="645" cellspacing="0" cellpadding="0" border="0" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움;"></table>
<table class="txc-table" width="681" cellspacing="0" cellpadding="0" border="0" style="color: #7f7f7f; border-width: initial; border-style: none; border-color: initial; font-family: 돋움; width: 681px;">
   <tbody>
      <tr>
         <td style="margin: 0px; padding: 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; width: 680px; height: 38px; border-style: solid; background-color: #ffffff;">
            <p><span style="color: #4c4c4c;"><b><span style="font-size: 10pt; font-family: Dotum, 돋움;">&nbsp;&nbsp;</span></b></span><strong style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; overflow-wrap: break-word; color: #444444; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 15.96px; line-height: 23.94px; text-align: justify; background: rgb(252, 252, 252);"><span style="font-size: 10pt; color: #4c4c4c; font-family: Dotum, 돋움;">void&nbsp;</span><span style="font-size: 10pt; color: #4c4c4c; font-family: Dotum, 돋움;">serialPuts (int fd, char *s)&nbsp;</span></strong></p>
            </td>
         </tr>
      </tbody>
   </table>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 10pt;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2; text-align: justify;"><font color="#212121"><span style="font-size: 10pt;">위 함수는 wiringPi의 입출력 함수중 하나로 쉽게 설명하자면 fgets로 저장한 문자열을 fd(여기서 fd는 시리얼 통신할 디바이스라고 생각해두자)로 전송하게 된다. 사실 위&nbsp;함수만 제대로 활용해도 아두이노로 문자열을 송신할 수 있지만 여기서는 파일입출력까지 같이 응용하여 예제를 만들어 보았다.&nbsp;wiringPi가 지원하는 함수에 대해 보다&nbsp;자세히 알고싶다면&nbsp;공식 홈페이지를 참고하도록 하자.</span></font></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 13.3333px; line-height: 20px; color: #212121;"><a href="http://wiringpi.com/reference/serial-library/" target="_blank" class="tx-link" style="color: #959595; text-decoration-line: none; font-size: 13.3333px; line-height: 20px;">http://wiringpi.com/reference/serial-library</a></span><span style="font-size: 13.3333px; line-height: 20px; color: #212121;">&nbsp;</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><br /></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2; text-align: justify;"><span style="font-size: 10pt; color: #212121;">마지막으로&nbsp;fopen을 통해 파일을 개방하였다면 fclose 함수를 통해 파일을 꼭 닫아주어야 한다. 그 이유는 스트림을 형성하기 위해서는 시스템에서 메모리를 할당해야 하는데 파일을 닫아주지 않으면 메모리가 할당된 채로 유지되면서 손실이 일어나기 때문이다. 쉽게 말해 메모리가 유출되는 것을 막기 위한 것으로 이해하면 된다.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 10pt;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;"><span style="font-size: 10pt;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;"><span style="font-size: 10pt; color: #212121;"><b>3. 아두이노 코드</b></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;"><span style="font-size: 10pt;"><br /></span></p>
<div class="colorscripter-code" style="margin: 0px; padding: 0px; color: #010101; overflow: auto; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important; position: relative !important;">
   <table class="colorscripter-code-table" cellspacing="0" cellpadding="0" style="margin: 0px; padding: 0px; border-width: initial; border-style: none; border-color: initial; background-color: #fafafa; border-radius: 4px;">
      <tbody>
         <tr>
            <td style="margin: 0px; padding: 6px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f; border-right: 2px solid rgb(229, 229, 229);">
               <div style="margin: 0px; padding: 0px; word-break: normal; text-align: right; color: #666666; line-height: 15.6px; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important;">
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">1</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">2</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">3</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">4</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">5</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">6</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">7</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">8</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">9</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">10</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">11</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">12</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">13</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">14</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">15</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">16</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">17</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">18</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">19</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">20</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">21</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">22</div>
                  <div style="margin: 0px; padding: 0px; line-height: 15.6px;">23</div>
                  </div>
               </td>
            <td style="margin: 0px; padding: 6px 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f;">
               <div style="margin: 0px; padding: 0px; color: #010101; line-height: 15.6px; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace !important;">
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #0099cc;">char</span>&nbsp;cTemp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">String&nbsp;sReal&nbsp;<span style="color: #ff3399;">=</span>&nbsp;<span style="color: #993333;">""</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">void</span>&nbsp;setup()</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">{</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;Serial.<span style="color: #0099cc;">begin</span>(<span style="color: #308ce5;">9600</span>);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;"><span style="color: #ff3399;">void</span>&nbsp;loop()</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">{</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff3399;">while</span>(Serial.available()){</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cTemp&nbsp;<span style="color: #ff3399;">=</span>&nbsp;Serial.read();</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sReal.concat(cTemp);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff3399;">if</span>(cTemp<span style="color: #ff3399;">=</span><span style="color: #ff3399;">=</span><span style="color: #993333;">'\n'</span>)</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Serial.print(sReal);</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sReal<span style="color: #ff3399;">=</span><span style="color: #993333;">""</span>;</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;&nbsp;&nbsp;&nbsp;}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">}</div>
                  <div style="margin: 0px; padding: 0px 6px; white-space: pre; line-height: 15.6px;">&nbsp;</div>
                  </div>
               <div style="margin: -13px 5px 0px 0px; padding: 0px; text-align: right; font-size: 9px; font-style: italic;"><a href="http://colorscripter.com/info#e" target="_blank" style="color: #e5e5e5; text-decoration-line: none;">Colored by Color Scripter</a></div>
               </td>
            <td style="margin: 0px; padding: 0px 2px 4px 0px; line-height: 18px; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; color: #7f7f7f; vertical-align: bottom;"><a href="http://colorscripter.com/info#e" target="_blank" style="color: white; text-decoration-line: none;"><span style="font-size: 9px; word-break: normal; border-radius: 10px; padding: 1px; background-color: #e5e5e5;">cs</span></a></td>
            </tr>
         </tbody>
      </table>
   </div>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 10pt; color: #212121;">아두이노 소스코드는 간단하게 구현해보았는데 여기서 유의해야할 것이 Serial.read() 함수이다. 라즈베리파이의 경우 문자를 한 줄로 읽거나 쓰는 것이 가능한데 아두이노는 한 글자씩 밖에 읽기가 불가능하다. 때문에 이러한 문제점을 해결하기위해 필자의 경우에는 while문을 활용하여 라즈베리파이를 통해 송신된 문자열을 각 문자 단위로 읽고 이를 concat 함수 (문자와 문자를 이어주는 역할을 한다.)를 사용하여 한 문장으로 만든 뒤에 해당 문자열의 끝을 나타내는 개행문자가 입력으로 들어올 시 문자열을 출력하고 문자열 변수를 초기화 하는 형태로 코드를 구현해보았다. 나름대로 구현이 잘 되긴 했지만 완성도면에서 미흡하다고 생각하기 때문에 후에 더 나은 방향으로 수정이 필요해 보인다.</span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 13.3333px; line-height: 20px; color: #212121;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; text-align: justify; line-height: 2;"><span style="font-size: 13.3333px; line-height: 20px; color: #212121;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif; line-height: 2;"><span style="font-size: 13.3333px; line-height: 20px; color: #212121;"><b>4. 결과 확인</b></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;"><span style="font-size: 13.3333px; line-height: 20px; color: #212121;"><br /></span></p>
<p style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;"><font color="#212121"><span style="font-size: 13.3333px; line-height: 20px;">컴파일 방법은 기존과 동일하며 읽어올 파일을 형성하고 그 경로를 지정하여 예제 코드에 반영해주자.</span></font></p>
<p><span style="color: #7f7f7f; font-family: Dotum, 돋움;"></span><br style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;" /><br style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;" /><span style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;">출처:&nbsp;</span><a href="https://creamp.tistory.com/entry/%EB%9D%BC%EC%A6%88%EB%B2%A0%EB%A6%AC%ED%8C%8C%EC%9D%B4%EB%A1%9C-%EB%AC%B8%EC%9E%90%EC%97%B4-%EC%86%A1%EC%8B%A0%ED%95%98%EA%B8%B0%ED%8C%8C%EC%9D%BC-%EC%9E%85%EC%B6%9C%EB%A0%A5" style="color: #959595; text-decoration-line: none; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;" target="_blank">https://creamp.tistory.com/entry/라즈베리파이로-문자열-송신하기파일-입출력</a><span style="color: #7f7f7f; font-family: &quot;Nanum Gothic&quot;, 돋움, Tahoma, AppleGothic, sans-serif;">&nbsp;[CreAmp]</span></p>