# 2.42 吋 OLED模組（I2C版本）

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2F5NDeH5DyrcrpuB8wCPyj%2Fimage.png?alt=media&#x26;token=12e845fe-047c-47d7-92df-23ef207f7f49" alt="" width="268"><figcaption></figcaption></figure>

### **2.42 吋 OLED模組電路圖**

* Raspberry Pi Pico W
* Raspberry Pi Pico W 擴充板
* 2.42 吋 OLED 模組
* 母 – 母 杜邦線

{% hint style="success" %}
*<mark style="color:$warning;">**OLED 顯示器模組是I2C訊號輸入。本範例之模組 SDA 腳位需接至Raspberry Pi Pico擴充板D4腳位，模組SCL腳位需接至Raspberry Pi Pico擴充板D5腳位。**</mark>*
{% endhint %}

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FGfhS8GomJPZ6Hkskxdeh%2Fimage.png?alt=media&#x26;token=e8eb31b3-1018-4cf7-819c-4cb1c321a8cf" alt=""><figcaption></figcaption></figure>

### **Arduino 程式如下**

```
#include <Arduino.h>
#include <Wire.h>
#include <U8g2lib.h>

// 根據你原本的設定：SSD1306 128x64 I2C
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(
  U8G2_R0,        // 旋轉角度：不旋轉
  U8X8_PIN_NONE   // 不使用 reset 腳
);

void setup() {
  // 初始化序列埠
  Serial.begin(115200);
  delay(1000);

  // 初始化 OLED
  u8g2.begin();

  // 清畫面
  u8g2.clearBuffer();

  // 設定字型
  u8g2.setFont(u8g2_font_6x10_tf);

  // 在 (x=0, y=16) 顯示第一行
  u8g2.drawStr(0, 16, "Hello OLED!");

  // 第二行
  u8g2.drawStr(0, 32, "Pico W Test");


  // 把畫面送到 OLED
  u8g2.sendBuffer();
}

void loop() {
  
}

```

### 程式執行結果

OLED 螢幕會顯示 「Hello OLED ! Pico W Test」

<figure><img src="https://1275793585-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LaZQFBYOS3O0ksiEmR1%2Fuploads%2FBVrqsCJFou8iOZ9a7MkK%2Fimage.png?alt=media&#x26;token=238bfc29-a594-4f2b-b1d4-93af30127a4c" alt=""><figcaption></figcaption></figure>
