# 2.42 吋 OLED模組（I2C版本）

<figure><img src="/files/4eZFl1ryiTBO3jK3HZWG" 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="/files/gsS6EhObFBy2GuuFuZ17" 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="/files/oVoaPAcqJcS8YkoWTLTY" alt=""><figcaption></figcaption></figure>


---

# 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://cavedu.gitbook.io/cavedu/sheng-wu-yi-xue-cai-liao-bao/2.42-cun-oled-mo-zu-i2c-ban-ben.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.
