Once luma.oled is installed and your display is wired up, you can have content on screen in fewer than ten lines of Python. This guide walks through connecting to a display over I2C, initializing the ssd1306 device driver, and drawing a rectangle and text using the Pillow-compatible canvas.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rm-hull/luma.oled/llms.txt
Use this file to discover all available pages before exploring further.
Import the required modules
Import the interface class for your connection type, the You only need to import the interface and device classes you actually use. The example above imports all available options for reference.
canvas renderer, and the device class that matches your display’s controller chip.Create the serial interface
Instantiate the interface class that matches how your display is connected to the board. This example uses I2C on port 1 at the default address If your display uses SPI instead, pass
0x3C.spi(device=0, port=0) to the device constructor in the next step. For 6800-style parallel, use bitbang_6800(RS=7, E=8, PINS=[25,24,23,27]).Initialize the device
Pass the serial interface to the device constructor for your controller chip. This sends the required initialization sequence to the display.Substitute
ssd1331, sh1106, ssd1309, or another class if you are using a different controller. See the device reference for the full list.Draw with the canvas
Use the
canvas context manager to open a drawing surface. Inside the with block, call Pillow’s ImageDraw methods to render content.When the
with block exits, the canvas is automatically flushed to the display’s memory. You do not need to call a separate display() or show() method.Complete example
Here is the full working script combining all of the steps above:When your program ends, the display is cleared automatically. If your script runs very quickly, the image may not be visible long enough to see. Add a
time.sleep() call after the with block to keep the content on screen.Next steps
- Drawing guide — render text, images, and shapes using the full canvas API
- Color and greyscale — use color on SSD1331/SSD1351 or greyscale on SSD1322/SSD1325
- Orientation — rotate the display output in software