# 使用序列埠輸出資訊

&#x20;在使用micro:bit常常遇到要同時顯示溫度與光線等多個數據，但在主板上只有5×5的LED矩陣顯示，非常沒有效率，因此micro:bit提供了序列傳輸的功能，能夠將micro:bit讀取到的值，透過序列埠傳輸到電腦中顯示在電腦螢幕上，讓開發者可以更容易地閱讀到需要的資訊。

要在micro:bit中使用序列埠傳送資料，可以使用以下這些積木：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOL_m4Qx_rh943FeVyN%2F-LOLb-mXxMva88ZIu-ir%2F2018-10-09_10-15-05.png?alt=media\&token=462b11a4-3814-47fb-8f63-f76c105b855a)

由上圖所示有許多的積木可以使用，但是在程式中對序列埠寫入一些資訊之後，這些資訊要如何傳送到電腦中，而且顯示出來讓我們看到呢？要完成這個目標需要三個步驟：

1. 使用上述的積木放在程式中，然後把程式燒錄到micro:bit的板子上。
2. 在你的電腦中安裝micro:bit的驅動程式，這此板可以擁有一個序列埠。
3. 在電腦中安裝序列埠連線軟體（如Windows的PuTTY），連接到該序列埠即可。

接著就來做一個簡易的練習。

#### 步驟一：編寫輸出到序列埠的程式

以下這個程式可以對序列埠輸出目前的亮度值以及溫度值，每一秒即更新一次：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOL_m4Qx_rh943FeVyN%2F-LOLdFN1su610FgmW8xX%2F2018-10-09_10-23-44.png?alt=media\&token=7260a2a7-6408-495d-9461-9af703cdf279)

#### 步驟二：安裝micro:bit的序列埠驅動程式

{% hint style="info" %}
這個動作在同一部電腦中只要做一次就好了
{% endhint %}

請把micro:bit連接到電腦上，然後前往網站： [mbed Windows serial port drive](https://os.mbed.com/handbook/Windows-serial-configuration)下載及安裝驅動程式，裝完成後即可至裝置管理員查看並記錄mbed Serial Port為的編號，（在此例為COM9，你的電腦可能會是其它的數值)，如下圖所示：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOLeaL-Ei5nnAxAfity%2F-LOLdzJRuRmwjzdf22lP%2F2018-10-09_10-28-46.png?alt=media\&token=35c6c76b-b510-4033-8044-78dab135b0dd)

#### 步驟三：使用序列埠連線程式進行連線

序列埠連線程式中，在Windows作業系統裡最常用的是PuTTY，其載點在此：  [putty載點](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html)

下載之後完成程式的安裝（其實只是一個可執行檔，直接放在桌面上就可以了，也沒有什麼安裝的手續啦）。執行PuTTY之後，可以看到以下的連線設定畫面：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOLeaL-Ei5nnAxAfity%2F-LOLfDtzqTuMOiqVn9yn%2F2018-10-09_10-33-52.png?alt=media\&token=6c768308-003f-4963-a8bd-2a7646eb07cc)

在用紅色箭頭所指的地方就是要切換的選項，預設是Telnet，要把它改為Serial，接著就是設定COM的號碼以及連線速度115200即可。如下所示：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOLeaL-Ei5nnAxAfity%2F-LOLfXfILNT9QGp0urKx%2F2018-10-09_10-35-32.png?alt=media\&token=8eceb758-ede9-47da-9992-a7c1620ae3b6)

在設定完畢之後，請直接按下Open就可以看到執行結果了，如下所示：

![](https://2988174335-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMo8UCGGycRFYs2Gx9M%2F-LOLeaL-Ei5nnAxAfity%2F-LOLfhrkBpxyZNpFD47H%2F2018-10-09_10-36-21.png?alt=media\&token=e63ac251-b22c-4d44-84f5-fd7495734dd9)

有了這個方法，日後在編寫micro:bit程式的時候就不需要再等待那個又慢又小的LED顯示出我們想要的數字了。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nkust.gitbook.io/micro-bit/shi-yong-xu-lie-bu-chu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
