라즈베리 파이 피코 MicroPython OLED SSD1309
이 튜토리얼은 Raspberry Pi Pico(또는 Pico W)와 SSD1309 OLED 디스플레이를 사용하여 텍스트, 숫자, 이미지, 도형을 표시하는 방법을 안내합니다. 다루는 내용:
- SSD1309 OLED 디스플레이를 Raspberry Pi Pico에 연결하는 방법
- SSD1309 OLED 디스플레이에 텍스트 표시하는 방법
- SSD1309 OLED 디스플레이에 도형 그리는 방법
- SSD1309 OLED 디스플레이에서 텍스트 스크롤하는 방법
- SSD1309 OLED 디스플레이의 대비 및 밝기 조절하는 방법
- SSD1309 OLED 디스플레이에 비트맵 이미지 표시하는 방법
필요한 하드웨어
| 1 | × | Raspberry Pi Pico W | 쿠팡 | 아마존 | |
| 1 | × | Raspberry Pi Pico (alternative) | 쿠팡 | 아마존 | |
| 1 | × | 마이크로 USB 케이블 | 아마존 | |
| 1 | × | SSD1309 I2C OLED Display 128x64 | 아마존 | |
| 1 | × | 점퍼케이블 | 쿠팡 | 아마존 | |
| 1 | × | (추천) 라즈베리 파이 피코용 스크루 터미널 확장 보드 | 아마존 |
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
SSD1309 OLED 디스플레이에 대하여
핀아웃
SSD1309 OLED 디스플레이에는 네 개의 핀이 있습니다:
- GND 핀: 접지 핀
- VCC 핀: 전원 공급 핀(3.3V~5V)
- SCL 핀: I2C 클럭 핀
- SDA 핀: I2C 데이터 핀

image source: diyables.io
배선도
SSD1309 OLED 디스플레이를 Raspberry Pi Pico에 연결합니다.
| SSD1309 OLED Display | Raspberry Pi Pico |
|---|---|
| GND | GND (핀 38) |
| VCC | 3V3(OUT) (핀 36) |
| SCL | GP1 (핀 2) |
| SDA | GP0 (핀 1) |

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.
라이브러리 설치 방법
- Thonny IDE를 엽니다. 인터프리터를 MicroPython (Raspberry Pi Pico)로 설정합니다.
- Pico가 연결되어 있는지 확인합니다.
- Tools > Manage packages...를 클릭합니다.
- 검색창에 "DIYables-MicroPython-OLED-SSD1309"를 입력하고 Search on PyPI를 클릭합니다.
- 목록에서 DIYables-MicroPython-OLED-SSD1309를 선택합니다.
- Install을 클릭합니다.
- 설치가 완료될 때까지 기다립니다.
Raspberry Pi Pico 코드 - Hello World
빠른 시작
- 배선도에 따라 Raspberry Pi Pico에 부품을 배선합니다.
- Micro USB 케이블을 사용하여 Raspberry Pi Pico를 컴퓨터에 연결합니다.
- Thonny IDE를 열고 인터프리터를 MicroPython (Raspberry Pi Pico)로 설정합니다.
- 아래 코드를 Thonny IDE에 복사합니다.
/*
* 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다
* 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다.
* 상세한 지침 및 연결도에 대해서는 다음을 방문하세요:
* https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-ssd1309-oled-display
*/
"""
Example: Hello World – basic text on SSD1309 OLED
Works with: Raspberry Pi Pico
Product page: https://diyables.io/products/2.4-inch-oled-display-module-ssd1309-128x64
Wiring guide:
Raspberry Pi Pico:
OLED SSD1309 Raspberry Pi Pico
──────────── ─────────────────
SDA -> GP0 (pin 1)
SCL -> GP1 (pin 2)
VCC -> 3V3(OUT) (pin 36)
GND -> GND (pin 38)
"""
from machine import I2C, Pin
from DIYables_MicroPython_OLED_SSD1309 import OLED_SSD1309
# ── Pin configuration ────────────────────────────────────────────────────────
SCL_PIN = 1 # GP1
SDA_PIN = 0 # GP0
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
SCREEN_ADDRESS = 0x3C
# ── Setup ────────────────────────────────────────────────────────────────────
i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=400_000)
oled = OLED_SSD1309(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, addr=SCREEN_ADDRESS)
# ── Draw ─────────────────────────────────────────────────────────────────────
oled.fill(0)
# Line 1 – normal 8×8 font
oled.text("Hello, World!", 0, 0)
# Line 3
oled.text("DIYables", 0, 16)
# Line 4
oled.text("SSD1309 OLED", 0, 32)
oled.text("128 x 64", 0, 40)
oled.show()
- 코드를 Raspberry Pi Pico에 업로드합니다.
- OLED 디스플레이에 "Hello World!" 텍스트가 표시됩니다.
Raspberry Pi Pico 코드 - 도형 그리기
/*
* 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다
* 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다.
* 상세한 지침 및 연결도에 대해서는 다음을 방문하세요:
* https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-ssd1309-oled-display
*/
"""
Example: Draw Shapes – lines, rectangles, and circles on SSD1309 OLED
Works with: Raspberry Pi Pico
Product page: https://diyables.io/products/2.4-inch-oled-display-module-ssd1309-128x64
Wiring guide:
Raspberry Pi Pico:
OLED SSD1309 Raspberry Pi Pico
──────────── ─────────────────
SDA -> GP0 (pin 1)
SCL -> GP1 (pin 2)
VCC -> 3V3(OUT) (pin 36)
GND -> GND (pin 38)
Note:
framebuf.FrameBuffer provides: pixel, fill, fill_rect, rect, line,
hline, vline, text, blit, scroll, and (on newer MicroPython) ellipse & poly.
Circles and triangles require manual drawing or the ellipse/poly helpers.
"""
from machine import I2C, Pin
from DIYables_MicroPython_OLED_SSD1309 import OLED_SSD1309
import time
# ── Pin configuration ────────────────────────────────────────────────────────
SCL_PIN = 1 # GP1
SDA_PIN = 0 # GP0
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
SCREEN_ADDRESS = 0x3C
# ── Setup ────────────────────────────────────────────────────────────────────
i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=400_000)
oled = OLED_SSD1309(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, addr=SCREEN_ADDRESS)
def demo_pixels():
"""Scatter individual pixels diagonally."""
oled.fill(0)
w, h = SCREEN_WIDTH, SCREEN_HEIGHT
for i in range(0, w, 4):
oled.pixel(i, i * h // w, 1)
oled.show()
time.sleep_ms(1500)
def demo_lines():
"""Fan of lines from the top-left corner.
"""
oled.fill(0)
w, h = SCREEN_WIDTH, SCREEN_HEIGHT
for i in range(0, w, 8):
oled.line(0, 0, i, h - 1, 1)
for i in range(0, h, 8):
oled.line(0, 0, w - 1, i, 1)
oled.show()
time.sleep_ms(1500)
def demo_h_v_lines():
"""Horizontal and vertical lines."""
oled.fill(0)
w, h = SCREEN_WIDTH, SCREEN_HEIGHT
# horizontal lines
for y in range(0, h, 8):
oled.hline(0, y, w, 1)
# vertical lines
for x in range(0, w, 16):
oled.vline(x, 0, h, 1)
oled.show()
time.sleep_ms(1500)
def demo_rectangles():
"""Nested rectangle outlines.
"""
oled.fill(0)
w, h = SCREEN_WIDTH, SCREEN_HEIGHT
for i in range(0, h // 2, 4):
oled.rect(i, i, w - 2 * i, h - 2 * i, 1)
oled.show()
time.sleep_ms(1500)
def demo_filled_rects():
"""Alternating filled rectangles."""
oled.fill(0)
w, h = SCREEN_WIDTH, SCREEN_HEIGHT
for i in range(0, h // 2, 6):
color = 1 if (i // 6) % 2 == 0 else 0
oled.fill_rect(i, i, w - 2 * i, h - 2 * i, color)
oled.show()
time.sleep_ms(1500)
def demo_ellipse():
"""Ellipses (requires MicroPython 1.20+ for framebuf.ellipse).
"""
oled.fill(0)
cx, cy = SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2
try:
for r in range(4, min(cx, cy), 8):
oled.ellipse(cx, cy, r, r, 1) # circle outline
oled.show()
except AttributeError:
# ellipse not available; fall back to a manual Bresenham circle
_draw_circle(cx, cy, 20, 1)
oled.show()
time.sleep_ms(1500)
def _draw_circle(cx, cy, r, c):
"""Bresenham circle (fallback when framebuf.ellipse is unavailable)."""
x, y, err = r, 0, 1 - r
while x >= y:
for dx, dy in [(x, y), (y, x), (-y, x), (-x, y),
(-x, -y), (-y, -x), (y, -x), (x, -y)]:
oled.pixel(cx + dx, cy + dy, c)
y += 1
if err < 0:
err += 2 * y + 1
else:
x -= 1
err += 2 * (y - x) + 1
# ── Main loop ────────────────────────────────────────────────────────────────
while True:
demo_pixels()
demo_lines()
demo_h_v_lines()
demo_rectangles()
demo_filled_rects()
demo_ellipse()
"""
빠른 시작
- 위와 같이 코드를 업로드합니다.
- OLED 디스플레이에 다양한 도형이 표시됩니다.
Raspberry Pi Pico 코드 - 텍스트 스크롤
/*
* 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다
* 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다.
* 상세한 지침 및 연결도에 대해서는 다음을 방문하세요:
* https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-ssd1309-oled-display
*/
"""
Example: Scroll Text – hardware scrolling on SSD1309 OLED
Works with: Raspberry Pi Pico
Product page: https://diyables.io/products/2.4-inch-oled-display-module-ssd1309-128x64
Wiring guide:
Raspberry Pi Pico:
OLED SSD1309 Raspberry Pi Pico
──────────── ─────────────────
SDA -> GP0 (pin 1)
SCL -> GP1 (pin 2)
VCC -> 3V3(OUT) (pin 36)
GND -> GND (pin 38)
"""
from machine import I2C, Pin
from DIYables_MicroPython_OLED_SSD1309 import OLED_SSD1309
import time
# ── Pin configuration ────────────────────────────────────────────────────────
SCL_PIN = 1 # GP1
SDA_PIN = 0 # GP0
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
SCREEN_ADDRESS = 0x3C
# ── Setup ────────────────────────────────────────────────────────────────────
i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=400_000)
oled = OLED_SSD1309(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, addr=SCREEN_ADDRESS)
# ── Draw static content ───────────────────────────────────────────────────────
oled.fill(0)
oled.text("DIYables", 20, 28) # centred-ish on 128×64
oled.show()
time.sleep_ms(2000)
# ── Scroll loop ───────────────────────────────────────────────────────────────
while True:
# Scroll right across all pages (0–7)
oled.scroll_right(0x00, 0x07)
time.sleep_ms(3000)
oled.stop_scroll()
time.sleep_ms(500)
# Scroll left
oled.scroll_left(0x00, 0x07)
time.sleep_ms(3000)
oled.stop_scroll()
time.sleep_ms(500)
# Diagonal scroll right
oled.scroll_diag_right(0x00, 0x07)
time.sleep_ms(3000)
oled.stop_scroll()
time.sleep_ms(500)
# Diagonal scroll left
oled.scroll_diag_left(0x00, 0x07)
time.sleep_ms(3000)
oled.stop_scroll()
time.sleep_ms(500)
빠른 시작
- 위와 같이 코드를 업로드합니다.
- OLED 디스플레이에서 텍스트가 스크롤됩니다.
Raspberry Pi Pico 코드 - 대비 및 밝기 조절
/*
* 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다
* 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다.
* 상세한 지침 및 연결도에 대해서는 다음을 방문하세요:
* https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-ssd1309-oled-display
*/
"""
Example: Contrast & Dim – contrast control on SSD1309 OLED
Works with: Raspberry Pi Pico
Product page: https://diyables.io/products/2.4-inch-oled-display-module-ssd1309-128x64
Wiring guide:
Raspberry Pi Pico:
OLED SSD1309 Raspberry Pi Pico
──────────── ─────────────────
SDA -> GP0 (pin 1)
SCL -> GP1 (pin 2)
VCC -> 3V3(OUT) (pin 36)
GND -> GND (pin 38)
"""
from machine import I2C, Pin
from DIYables_MicroPython_OLED_SSD1309 import OLED_SSD1309
import time
# ── Pin configuration ────────────────────────────────────────────────────────
SCL_PIN = 1 # GP1
SDA_PIN = 0 # GP0
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
SCREEN_ADDRESS = 0x3C
# ── Setup ────────────────────────────────────────────────────────────────────
i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=400_000)
oled = OLED_SSD1309(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, addr=SCREEN_ADDRESS)
# ── Draw a test pattern ───────────────────────────────────────────────────────
oled.fill(0)
oled.fill_rect(0, 0, 64, 32, 1) # top-left filled block
oled.fill_rect(64, 32, 64, 32, 1) # bottom-right filled block
oled.text("Contrast Demo", 8, 28) # label over the blocks
oled.show()
time.sleep_ms(2000)
# ── Contrast / dim loop ───────────────────────────────────────────────────────
while True:
# Gradually increase contrast 0 → 255
for c in range(0, 256, 5):
oled.set_contrast(c)
time.sleep_ms(30)
time.sleep_ms(1000)
# Gradually decrease contrast 255 → 0
for c in range(255, -1, -5):
oled.set_contrast(c)
time.sleep_ms(30)
time.sleep_ms(1000)
# Dim on / off toggle
oled.dim(True)
time.sleep_ms(2000)
oled.dim(False)
time.sleep_ms(2000)
빠른 시작
- 위와 같이 코드를 업로드합니다.
- OLED 디스플레이의 대비와 밝기가 변경됩니다.
Raspberry Pi Pico 코드 - 비트맵 이미지 표시
/*
* 이 라즈베리 파이 피코 코드는 newbiely.kr 에서 개발되었습니다
* 이 라즈베리 파이 피코 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다.
* 상세한 지침 및 연결도에 대해서는 다음을 방문하세요:
* https://newbiely.kr/tutorials/raspberry-pico/raspberry-pi-pico-ssd1309-oled-display
*/
"""
Example: Bitmap – display a monochrome bitmap image on SSD1309 OLED
Works with: Raspberry Pi Pico
Product page: https://diyables.io/products/2.4-inch-oled-display-module-ssd1309-128x64
Wiring guide:
Raspberry Pi Pico:
OLED SSD1309 Raspberry Pi Pico
──────────── ─────────────────
SDA -> GP0 (pin 1)
SCL -> GP1 (pin 2)
VCC -> 3V3(OUT) (pin 36)
GND -> GND (pin 38)
How bitmap drawing works:
framebuf.FrameBuffer.blit() copies one FrameBuffer onto another.
Bitmap data must be stored row-by-row, MSB first → use framebuf.MONO_HMSB.
The blit() call then handles the conversion into the display's MONO_VLSB
layout automatically.
"""
import framebuf
from machine import I2C, Pin
from DIYables_MicroPython_OLED_SSD1309 import OLED_SSD1309
import time
# ── Pin configuration ────────────────────────────────────────────────────────
SCL_PIN = 1 # GP1
SDA_PIN = 0 # GP0
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
SCREEN_ADDRESS = 0x3C
# ── Bitmap data – 16 × 16 heart, stored row-by-row MSB first ─────────────────
# Each row uses 2 bytes (ceil(16 / 8) = 2).
HEART_W = 16
HEART_H = 16
heart_data = bytearray([
0x00, 0x00, # ................
0x0C, 0x30, # ....##....##....
0x1E, 0x78, # ...####..####...
0x3F, 0xFC, # ..############..
0x7F, 0xFE, # .##############.
0x7F, 0xFE, # .##############.
0xFF, 0xFF, # ################
0xFF, 0xFF, # ################
0xFF, 0xFF, # ################
0x7F, 0xFE, # .##############.
0x3F, 0xFC, # ..############..
0x1F, 0xF8, # ...##########...
0x0F, 0xF0, # ....########....
0x07, 0xE0, # .....######.....
0x03, 0xC0, # ......####......
0x01, 0x80, # .......##.......
])
# ── Setup ────────────────────────────────────────────────────────────────────
i2c = I2C(0, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), freq=400_000)
oled = OLED_SSD1309(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, addr=SCREEN_ADDRESS)
# Wrap the raw bytes in a FrameBuffer using MONO_HMSB (row-major, MSB first)
heart_fb = framebuf.FrameBuffer(heart_data, HEART_W, HEART_H, framebuf.MONO_HMSB)
# ── Draw and animate ──────────────────────────────────────────────────────────
while True:
# Draw the heart centred on the display
x = (SCREEN_WIDTH - HEART_W) // 2
y = (SCREEN_HEIGHT - HEART_H) // 2
oled.fill(0)
oled.blit(heart_fb, x, y)
oled.text("DIYables", 24, 50)
oled.show()
time.sleep_ms(800)
# Invert colours for a "pulse" effect
oled.fill(1)
oled.blit(heart_fb, x, y, 1) # key=1 → blit only pixels that are OFF in source
oled.show()
time.sleep_ms(400)
빠른 시작
- 위와 같이 코드를 업로드합니다.
- OLED 디스플레이에 비트맵 이미지가 표시됩니다.
동영상
비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.
함수 참조
- 자세한 라이브러리 참조는 DIYables MicroPython OLED SSD1309 라이브러리 참조를 확인하세요.