# 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.

init(screen_width=128, screen_height=128)

Initialize the SSD1351 setting all internal registers and the display dimensions in pixels.

Parameters: screen_width – width in pixels of the display (max 128); default 128 screen_height – height in pixels of the display (max 128); default 128
on()

Turns on the display.

off()

Turns off the display.

set_contrast(contrast=0x7F)

Sets the contrast of the display.

Parameters: contrast – value of the contrast to be set (from 0 to 255), default 0x7F
clear()

Clears the display.

fill_screen(color, encode=True)

Fills the entire display with color code provided as argument.

Parameters: 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.

fill_rect(x, y, w, h, color, encode=True)

Draws a rectangular area in the screen colored with the color code provided as argument.

Parameters: 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.

draw_img(image, x, y, w, h)

Draws a rectangular area in the screen colored with the color code provided as argument.

Parameters: 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.

draw_pixel(x, y, color, encode=True)

Draws a single pixel in the screen colored with the color code provided as argument.

Parameters: 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.

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.

Parameters: 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