ssd1306 — OLED Driver
This module provides a driver for SSD1306-based OLED displays. Two
transport variants are supported: I2C (SSD1306_I2C) and SPI
(SSD1306_SPI). Both inherit the drawing API from
SSD1306, which wraps a framebuf.FrameBuffer1.
Example:
from machine import I2C, Pin
import ssd1306
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0)
oled.text("Hello", 0, 0)
oled.show()
Classes
- class ssd1306.SSD1306(width: int, height: int, external_vcc: bool)
Base class for SSD1306 OLED displays. Subclasses must initialize
self.framebufand providewrite_cmd,write_data,write_framebufandpoweronmethods.Arguments:
width– Display width in pixels.height– Display height in pixels (must be a multiple of 8).external_vcc–Trueif an external VCC source is used,Falseto enable the internal charge pump.
Instance attributes:
width– Display width in pixels.height– Display height in pixels.external_vcc– External VCC flag.pages– Number of 8-pixel-tall pages (height // 8).
- init_display() None
Send the initialization command sequence to the display, clear the framebuffer, and refresh. Called automatically by
__init__.
- contrast(contrast: int) None
Set the display contrast.
contrast– Contrast value in the range0–255.
- invert(invert: int) None
Invert the display colors.
invert–0for normal output,1for inverted output. Only the least significant bit is used.
- fill(col: int) None
Fill the entire framebuffer with a single color.
col– Color value (0for off,1for on).
- pixel(x: int, y: int, col: int) None
Set the color of a single pixel.
x– Column coordinate.y– Row coordinate.col– Color value (0or1).
- class ssd1306.SSD1306_I2C(width: int, height: int, i2c: machine.I2C, addr: int = 0x3C, external_vcc: bool = False)
I2C-connected SSD1306 driver. Inherits from
SSD1306.Arguments:
width– Display width in pixels.height– Display height in pixels.i2c– An initializedmachine.I2C(or compatible) object.addr– 7-bit I2C device address (default0x3C).external_vcc–Truefor external VCC,Falseto use the internal charge pump.
- class ssd1306.SSD1306_SPI(width: int, height: int, spi: machine.SPI, dc: machine.Pin, res: machine.Pin, cs: machine.Pin, external_vcc: bool = False)
SPI-connected SSD1306 driver. Inherits from
SSD1306. Uses a fixed SPI clock rate of 10 MHz.Arguments:
width– Display width in pixels.height– Display height in pixels.spi– Apyb.SPI(or compatible) object.dc– Data/command select pin.res– Reset pin.cs– Chip-select pin.external_vcc–Truefor external VCC,Falseto use the internal charge pump.