> 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/sheng-wu-yi-xue-cai-liao-bao/2.42-cun-oled-mo-zu-i2c-ban-ben.md).

# 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>
