|
1 | | -# MicroPython library for SSD1327 128x128 4-bit greyscale OLED displays |
| 1 | +# SSD1327 MicroPython Driver |
2 | 2 |
|
3 | | -This library is a port of the [MicroPython library for SSD1327 128x128 4-bit greyscale OLED displays](https://github.com/mcauser/micropython-ssd1327). |
| 3 | +MicroPython driver for the **SSD1327 128x128 4-bit greyscale OLED display controller**. |
4 | 4 |
|
5 | | -The examples could be easily tested with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) with the following command : |
| 5 | +This library is a port of [micropython-ssd1327](https://github.com/mcauser/micropython-ssd1327). |
6 | 6 |
|
7 | | -```sh |
8 | | - mpremote mount . run examples/hello_world.py |
| 7 | +## Supported Display |
| 8 | + |
| 9 | +| Feature | Value | |
| 10 | +| ----------- | ----------------- | |
| 11 | +| Controller | SSD1327 | |
| 12 | +| Resolution | 128 × 128 pixels | |
| 13 | +| Color depth | 4-bit (16 levels) | |
| 14 | +| Interfaces | I²C, SPI | |
| 15 | +| Default I²C address | `0x3C` | |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +* 128x128 OLED display support |
| 20 | +* 4-bit greyscale (16 levels) |
| 21 | +* I²C and SPI interfaces |
| 22 | +* FrameBuffer-based rendering API |
| 23 | +* Drawing primitives: pixels, lines, text, scrolling |
| 24 | +* Display control: contrast, invert, rotation |
| 25 | +* Power management: display on/off |
| 26 | + |
| 27 | +## Basic Usage |
| 28 | + |
| 29 | +```python |
| 30 | +from machine import I2C |
| 31 | +from ssd1327 import WS_OLED_128X128_I2C |
| 32 | + |
| 33 | +i2c = I2C(1) |
| 34 | +display = WS_OLED_128X128_I2C(i2c) |
| 35 | + |
| 36 | +display.fill(0) |
| 37 | +display.text("Hello STeaMi", 0, 0) |
| 38 | +display.show() |
| 39 | +``` |
| 40 | + |
| 41 | +## FrameBuffer Integration |
| 42 | + |
| 43 | +The driver extends `framebuf.FrameBuffer` and exposes the following drawing methods directly: |
| 44 | + |
| 45 | +* `fill(color)` — fill entire display |
| 46 | +* `pixel(x, y, color)` — set a single pixel |
| 47 | +* `line(x1, y1, x2, y2, color)` — draw a line |
| 48 | +* `text(string, x, y, color=15)` — render text |
| 49 | +* `scroll(dx, dy)` — scroll buffer contents |
| 50 | + |
| 51 | +Other FrameBuffer methods (`rect()`, `fill_rect()`, etc.) are accessible via `display.framebuf`. |
| 52 | + |
| 53 | +The buffer is stored in 4-bit greyscale format (GS4_HMSB). The internal buffer uses `width × height / 2` bytes (8192 bytes for 128×128). Call `show()` to push the buffer to the display. |
| 54 | + |
| 55 | +## API Reference |
| 56 | + |
| 57 | +### Initialization |
| 58 | + |
| 59 | +#### I2C (STeaMi board) |
| 60 | + |
| 61 | +```python |
| 62 | +from ssd1327 import WS_OLED_128X128_I2C |
| 63 | + |
| 64 | +display = WS_OLED_128X128_I2C(i2c, address=0x3C) |
| 65 | +``` |
| 66 | + |
| 67 | +For custom resolutions: |
| 68 | + |
| 69 | +```python |
| 70 | +from ssd1327 import SSD1327_I2C |
| 71 | + |
| 72 | +display = SSD1327_I2C(width, height, i2c, address=0x3C) |
| 73 | +``` |
| 74 | + |
| 75 | +#### SPI |
| 76 | + |
| 77 | +```python |
| 78 | +from ssd1327 import WS_OLED_128X128_SPI |
| 79 | + |
| 80 | +display = WS_OLED_128X128_SPI(spi, dc, res, cs) |
| 81 | +``` |
| 82 | + |
| 83 | +**Note:** `SSD1327_SPI` (custom resolution) is available via `from ssd1327.device import SSD1327_SPI` but is not exported by the package by default. |
| 84 | + |
| 85 | +### Display Control |
| 86 | + |
| 87 | +* `show()` — push the framebuffer to the display (required after any drawing) |
| 88 | +* `contrast(value)` — set brightness (0–255) |
| 89 | +* `invert(enable)` — enable/disable display inversion |
| 90 | +* `rotate(enable)` — rotate display 180° |
| 91 | + |
| 92 | +### Power Management |
| 93 | + |
| 94 | +* `power_on()` — turn display on |
| 95 | +* `power_off()` — turn display off (low power mode) |
| 96 | + |
| 97 | +### SPI-only |
| 98 | + |
| 99 | +* `reset()` — hardware reset via the reset pin (SSD1327_SPI only) |
| 100 | + |
| 101 | +## Examples |
| 102 | + |
| 103 | +| File | Description | |
| 104 | +| --------------------- | ---------------------------------------------------- | |
| 105 | +| `bitmap.py` | Display a 16x15 smiley bitmap with greyscale shading | |
| 106 | +| `framebuf_lines.py` | Draw diagonal lines across the screen | |
| 107 | +| `framebuf_pixels.py` | Plot individual pixels at various positions | |
| 108 | +| `framebuf_rects.py` | Draw rectangles using the FrameBuffer API | |
| 109 | +| `framebuf_scroll.py` | Scroll text horizontally across the display | |
| 110 | +| `framebuf_text.py` | Render text strings at different positions | |
| 111 | +| `hello_world.py` | Minimal "Hello World" display example | |
| 112 | +| `illusion.py` | Render an optical illusion pattern | |
| 113 | +| `invert.py` | Toggle display inversion on and off | |
| 114 | +| `lookup_table.py` | Display a greyscale gradient using all 16 levels | |
| 115 | +| `micropython_logo.py` | Display the MicroPython logo as a bitmap | |
| 116 | +| `random_pixels.py` | Fill the screen with randomly placed pixels | |
| 117 | +| `rotating_3d_cube.py` | Animate a rotating wireframe 3D cube | |
| 118 | +| `rotation.py` | Demonstrate 180° display rotation | |
| 119 | +| `shades.py` | Display 15 shades of grey as vertical bands | |
| 120 | + |
| 121 | +```bash |
| 122 | +mpremote mount lib/ssd1327 run lib/ssd1327/examples/hello_world.py |
9 | 123 | ``` |
0 commit comments