Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
oled.py plugin
#1
Hi Dan,

I expanded ssd1306.py plugin to include other oled devices.

This oled.py plugin mimics the ssd1306.py plugin.

It uses the luma-oled library which has to be installed as:

sudo -H pip3 install --upgrade luma.oled

reference:
https://luma-oled.readthedocs.io/en/late...tware.html

The library works with these drivers:
SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SSD1362 / SH1106 / WS0010

I used the built-in functions in luma-oled library. 
So I am able to shorten the code base, from 1488 lines to 700+ lines.

For reference, I make the following modifications on ssd1306.py.

The following three classes are all combined into one LCD class:
1. Screen
2. Screenblock
3. LCD

Some of the functions in ssd1306.py have corresponding functions in luma-oled library:

ssd1306 function --> luma-oled function
set_power(on=True) --> show()
_force_power_off() --> hide()
clear() --> clear()

The display syntax is also simplified.
Instead of the write_line() function specifying which lines to write on which row, and what font_size to use,
a new write_para() takes a block of text in one go and splits it into separate lines for display, and automatically calculates the appropriate font_size and row number for each line.

The text block contains a line separator -- semicolon followed by a space: "; "
For example, txt_block = 'line_1; line_2; [line_3]'

Any line_x too long is automatically further split via a wrap(width=wrap_width) function with a global wrap_width parameter specifying max number of characters per line.
So wrap_width is a factor that will determine font_size, but it is set once to apply globally to all lines. 

I use wrap_width = 20 to allow for very long line (small font_size) for the short 128x64 display.
And wrap_width = 15 for larger text size on the tall 128x128 display.

The wrap_width is not configurable to avoid confusion; but can be made so if necessary.

See attached oled.luma.plugin.pdf for examples of txt_blocks.

Screen dimensions (height and width in pixels) are pre-configured in the drivers.  So no need to provide configuration settings.

The 'rotate' setting allows for display rotation in 90degree increments.

I use i2c_write_addr (e.g. 0x3C) instead of the i2c_hw_addr (correspondingly 0x78), since the plugin does not need the latter.
And the former is conveniently accessible via the 'i2cdetect -y 1' command.

I have not tried a color oled (e.g. ssd1327, ssd1331, ssd1351). 
The ssd1306 yellow-blue display is actually monochromatic in signal but is rendered different colors in the two areas.
The ssd1327 I have is capable of 4-bit grayscale. I have placed an order for an RGB version.  Will try it out and report.
The sh1106 I have does not work properly: the top line is never displayed. I am not sure if I have a defective unit.

It would be interesting to see how well it works on other displays.


Attached Files
.zip   oled_plugin.zip (Size: 364.79 KB / Downloads: 4)
Reply


Messages In This Thread
oled.py plugin - by paul - 2021 Oct 09, 08:41 AM
RE: oled.py plugin - by dan - 2021 Oct 10, 03:56 PM
RE: oled.py plugin - by dan - 2021 Oct 10, 08:24 PM
RE: oled.py plugin - by paul - 2021 Oct 10, 08:56 PM
RE: oled.py plugin - by paul - 2021 Oct 10, 08:25 PM
RE: oled.py plugin - by dan - 2021 Oct 10, 08:48 PM
RE: oled.py plugin - by paul - 2021 Oct 11, 04:20 AM
RE: oled.py plugin - by astrogerard - 2021 Oct 11, 08:30 PM
RE: oled.py plugin - by paul - 2021 Oct 13, 01:52 AM
RE: oled.py plugin - by astrogerard - 2021 Oct 13, 09:32 AM
RE: oled.py plugin - by paul - 2021 Oct 13, 04:22 AM
RE: oled.py plugin - by paul - 2021 Oct 14, 12:28 AM
RE: oled.py plugin - by astrogerard - 2021 Oct 14, 01:28 PM
RE: oled.py plugin - by paul - 2021 Oct 14, 08:22 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)