SSD1351 Module¶
This Module exposes all functionalities of Solomon SSD1351 Color OLED Display driver (datasheet).
Note
Only 65k color depth is supported; 262k color depth will be available soon.
class SSD1351(drv, cs, rst, dc, pwr, clock=8000000)¶
class SSD1351(drv, cs, rst, dc, pwr, clock=8000000)
Creates an intance of a new SSD1351.
- spidrv: SPI Bus used '( SPI0, ... )'
- cs: Chip Select
- rst: Reset pin
- dc: Data/Command control pin
- pwr: Power On pin
- clk: Clock speed, default 8MHz
init¶
init(screen_width=128, screen_height=128)
Initialize the SSD1351 setting all internal registers and the display dimensions in pixels.
Arguments:
- screen_width – width in pixels of the display (max 128); default 12
- screen_height – height in pixels of the display (max 128); default 128
SSD1351.on¶
on()
Turns on the display.
SSD1351.off¶
off()
Turns off the display.
SSD1351.set_contrast¶
set_contrast(contrast=0x7F)
Sets the contrast of the display.
Arguments: contrast – value of the contrast to be set (from 0 to 255), default 0x7F.
SSD1351.clear¶
clear()
Clears the display.
SSD1351.fill_screen¶
fill_screen(color, encode=True)
Fills the entire display with color code provided as argument.
Arguments:
- color – hex color code for the screen
- encode (bool) – flag for enabling the color encoding; default True
Note
To be compatible with the 65k color format, if a stadard hex color code (24 bit) is provided it is necessary to encode it into a 16 bit format.
If a 16 bit color code is provided, the encode flag must be set to False.
SSD1351.fill_rect¶
fill_rect(x, y, w, h, color, encode=True)
Draws a rectangular area in the screen colored with the color code provided as argument.
Arguments:
- x – x-coordinate for left high corner of the rectangular area
- y – y-coordinate for left high corner of the rectangular area
- w – width of the rectangular area
- h – height of the rectangular area
- color – hex color code for the rectangular area
- encode(bool) – flag for enabling the color encoding; default True
Note
To be compatible with the 65k color format, if a stadard hex color code (24 bit) is provided it is necessary to encode it into a 16 bit format.
If a 16 bit color code is provided, the encode flag must be set to False.
SSD1351.draw_img¶
draw_img(image, x, y, w, h)
Draws a rectangular area in the screen colored with the color code provided as argument.
Arguments:
- image – image to draw in the oled display converted to hex array format and passed as bytearray
- x – x-coordinate for left high corner of the image
- y – y-coordinate for left high corner of the image
- w – width of the image
- h – height of the image
Note
To obtain a converted image in hex array format, you can go and use this online tool.
After uploading your image, you can resize it setting the width and height fields; you can also choose the code format (HEX:0x recommended) and the color format (65K color recommended).
Clicking on the “Get C string” button, the tool converts your image with your settings to a hex string that you can copy and paste inside a bytearray in your project and privide to this function.
SSD1351.draw_pixel¶
draw_pixel(x, y, color, encode=True)
Draws a single pixel in the screen colored with the color code provided as argument.
Arguments:
- x – pixel x-coordinate
- y – pixel y-coordinate
- color – hex color code for the pixel
- encode(bool) – flag for enabling the color encoding; default True
Note
To be compatible with the 65k color format, if a stadard hex color code (24 bit) is provided it is necessary to encode it into a 16 bit format.
If a 16 bit color code is provided, the encode flag must be set to False.
SSD1351.draw_text¶
draw_text(text, x=None, y=None, w=None, h=None, color=None, align=None, background=None, encode=True)
Prints a string inside a text box in the screen.
Arguments:
- text – string to be written in the display
- x – x-coordinate for left high corner of the text box; default None
- y – y-coordinate for left high corner of the text box; default None
- w – width of the text box; default None
- h – height of the text box; default None
- color – hex color code for the font; default None
- align – alignment of the text inside the text box (1 for left alignment, 2 for right alignment, 3 for center alignment); default None
- background – hex color code for the background; default None
- encode (bool) – flag for enabling the color encoding of the font and background color; default True
Note
To be compatible with the 65k color format, so if a stadard hex color code (24 bit) is provided
it is necessary to encode it into a 16 bit format.
If a 16 bit color code is provided, the encode flag must be set to False.
Note
If only text argument is provided, an automatic text box is created with the following values:
- x = 0
- y = 0
- w = min text width according to the font
- h = max char height according to the font
- color = 0xFFFF
- align = 3 (centered horizontally)
- background = 0x4471