Micropython SSD1327 display driver.
- Adapted from several popular/available drivers found online.
- SPI interface
from ssd1327 import SSD1327_SPI
- I2C interface
from ssd1327 import SSD1327_I2C
from ssd1327 import SSD1327_SPI
import framebuf
import logo_data
# Setup display on SPI bus
spi = SPI(0, sck=Pin(6), mosi=Pin(7))
dc = Pin(8)
res = Pin(9)
cs = Pin(5)
# Initialize SSD1327 OLED Display
ssd1327 = SSD1327_SPI(128, 128, spi, dc, res, cs)
# Fill a local framebuffer with logo splash screen
a = bytearray(logo_data.data())
fbuf = framebuf.FrameBuffer(a, 128, 128, framebuf.GS4_HMSB)
# Show logo splash screen
ssd1327.fill(0)
ssd1327.blit(fbuf, 0, 0, 0)
ssd1327.show()
I used the excellent graphics program Aseprite to generate the 'logo_data' shown in the example above.
There are three important points to remember when generating imagery for the ssd1327:
- Create or import a 128x128 pixel image.
- Use a 4-bit color palette (4-bit if you want full-range, 2-bit, or black-and-white, will also work just fine).
- Export the data in a compatible Python format.
Here are the steps I used with Aseprite:
-
Install the Lua Python export script (4_bit_export.lua) which can be found in the /tools directory of this repository.
- To find the folder in which Aseprite places its scripts, click on File->Scripts->Open Scripts Folder
- Copy 4_bit_export.lua into this folder
- You should not have to restart Aseprite, but you should exit the File menu and then reopen so the script can be found.
-
Load or create a 4-bit color palette. An example palette (4_bit_color_palette.aseprite) can be found in the /tools directory of this repository.
-
Load or create your 128x128 pixel image in Asperite, make sure to use your 4-bit palette.
-
Export your image data using the 4_bit_export.lua script; when prompted for 'select file' click on button and choose filename for exported Python data file. I used 'logo_data' as the name of the exported file for the example code shown above.
- The exported Python script should contain rows of byte data which corresponds to your image and a single function definition, data which will return a memoryview to this data. Import this script into your project and access the data using the data function, logo_data.data() for this example.