.. module:: ssd1351 ************** 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): Creates an intance of a new SSD1351. :param spidrv: SPI Bus used '( SPI0, ... )' :param cs: Chip Select :param rst: Reset pin :param dc: Data/Command control pin :param pwr: Power On pin :param clk: Clock speed, default 8MHz Example: :: from solomon.ssd1351 import ssd1351 ... oled = ssd1351.SSD1351(SPI0,D57,D58,D59,D71) oled.init() oled.on() oled.fill_screen(color=0xFFFFFF) .. method:: init(screen_width=128, screen_height=128) Initialize the SSD1351 setting all internal registers and the display dimensions in pixels. :param screen_width: width in pixels of the display (max 128); default 128 :param screen_height: height in pixels of the display (max 128); default 128 .. method:: on() Turns on the display. .. method:: off() Turns off the display. .. method:: set_contrast(contrast=0x7F) Sets the contrast of the display. :param contrast: value of the contrast to be set (from 0 to 255), default 0x7F .. method:: clear() Clears the display. .. method:: fill_screen(color, encode=True) Fills the entire display with color code provided as argument. :param color: hex color code for the screen :param 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. .. method:: fill_rect(x, y, w, h, color, encode=True) Draws a rectangular area in the screen colored with the color code provided as argument. :param x: x-coordinate for left high corner of the rectangular area :param y: y-coordinate for left high corner of the rectangular area :param w: width of the rectangular area :param h: height of the rectangular area :param color: hex color code for the rectangular area :param 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. .. method:: draw_img(image, x, y, w, h) Draws a rectangular area in the screen colored with the color code provided as argument. :param image: image to draw in the oled display converted to hex array format and passed as bytearray :param x: x-coordinate for left high corner of the image :param y: y-coordinate for left high corner of the image :param w: width of the image :param 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. .. method:: draw_pixel(x, y, color, encode=True) Draws a single pixel in the screen colored with the color code provided as argument. :param x: pixel x-coordinate :param y: pixel y-coordinate :param color: hex color code for the pixel :param 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. .. method:: 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. :param text: string to be written in the display :param x: x-coordinate for left high corner of the text box; default None :param y: y-coordinate for left high corner of the text box; default None :param w: width of the text box; default None :param h: height of the text box; default None :param color: hex color code for the font; default None :param align: alignment of the text inside the text box (1 for left alignment, 2 for right alignment, 3 for center alignment); default None :param background: hex color code for the background; default None :param 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