> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/cavedu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/cavedu/rk005/module_ui/oled.md).

# OLED 顯示器模組

## OLED 顯示器模組 <a href="#hlk168941899" id="hlk168941899"></a>

專案說明

使用「Raspberry Pi Pico W」連接「OLED 顯示器模組」, 可顯示訊息或感測器的數值。此 OLED 顯示器模組包含於「洞洞五教學材料包」內。

### OLED 顯示器模組電路圖

·        Raspberry Pi Pico W

·        Raspberry Pi Pico W 擴充板

·        OLED 顯示器模組

| OLED 顯示器模組是I2C訊號輸入。本範例連接到模組SDA腳位需接至Raspberry Pi Pico擴充板D4腳位，模組SCL腳位需接至Raspberry Pi Pico擴充板D5腳位。 |
| ----------------------------------------------------------------------------------------------- |

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FEPccjCJ3T0a1DRcgGuQt%2Fimage.png?alt=media&amp;token=7dcbe909-ab8f-42da-aecf-1d2aa3e6e3ed" alt=""><figcaption></figcaption></figure>

### &#x20;BlocklyDuino 程式 (OLED)

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FmnjJD5JFLOW9Ye2JFKr3%2Fimage.png?alt=media&amp;token=51d3b3e1-19ed-4f93-bfd2-d8867134fef9" alt=""><figcaption></figcaption></figure>

### &#x20; Arduino 程式(OLED.ino)如下

```
#include "Wire.h"
#include "U8g2lib.h"
 
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
 
void setup()
{
  u8g2.begin();
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
 
  u8g2.clearDisplay();
}
 
void loop()
{
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 0);
    u8g2.print(String("HELLO").c_str());
    u8g2.drawLine(0, 11, 30, 11);
 
    u8g2.sendBuffer();
  } while (u8g2.nextPage());
}
```

### 程式執行結果:

程式執行結果，會在OLED螢幕中顯示「HELLO」，下面也會顯示底線。

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FQwyQbJY2Y1PcvSS7oUWA%2Fimage.png?alt=media&amp;token=18e771db-ee47-408d-ba46-eecff0cd5895" alt=""><figcaption></figcaption></figure>
