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
#2
Hi Paul,

Very cool!
This looks like it will be a useful plugin. However I found a couple of problems.

When the luma module is not installed on the Pi the plugin will not load and the user will not be able to read the documentation that describes hot to install luma.
I am planning to include the line for the luma installation on the plugin description on the plugin download page.

But when I tried testing the plugin after installing luma I got the following error:

"Ignoring exception while loading the oled plug-in.
libopenjp2.so.7: cannot open shared object file: No such file or directory"

Not sure what to do about that. I don't have an oled display. I wonder of that might be part of the problem.

Dan
<p><br></p>
Reply
#3
I did a bit of googling on the error and tried

sudo apt install libopenjp2-7
That fixed the problem but then it couldn't find libtiff5 so:

sudo apt install libtiff5
Then I got:

luma.core.error.DeviceNotFoundError: I2C device not found on address: 0x3D

So I guess the plugin won't load unless an oled display is connected to the pi?

Dan
<p><br></p>
Reply
#4
When I unplug my oled device, this is the error message I got:

pi@sip:~/SIP $ sudo python3 sip.py
...
luma.core.error.DeviceNotFoundError: I2C device not found on address: 0x3C
Ignoring exception while loading the oled plug-in.
I2C device not found on address: 0x3C

This is different from what you got.  So our software setups are different.

The error message you found is related to Pillow:
https://stackoverflow.com/questions/4801...or-directo

To test if you have pillow installed, see if you can import it in python3:
from PIL import Image

The OS I installed on my rPi is the full 2.8Gb Desktop version (released 2021-05-07) which comes pre-installed with Pil.

Pil has many dependencies. 

Which version of raspberry pi OS do you have?
If you give me your version, I can try to reproduce your error.

If PIL is not installed on your system, you can try to install it here:
https://pillow.readthedocs.io/en/stable/...ation.html


I also found a mistake on the wiring instruction in oled-docs.html
original: you need to wire Vcc to either 5V (pins 4 or 6) or 3.3V (pin 1)
correction: you need to wire Vcc to either 5V (pins 2 or 4) or 3.3V (pin 1)

Also "python smbus package" is not required for this plugin, so Hardware instruction # 5 has been removed.

This error is corrected in this attachment.

In the plugin oled.py in the first attachment, I include a switch (gv.sd[u"eod"], eod for "enable oled display") to toggle on and off the oled display in the options page. 
This function is now commented out since it entails modifying sd.json, gv.py, webpages.py and options.html. 
(In my options page, I have an extra "human-machine interface" section that includes toggles for buzzer, oled_display and gesture_sensor.)

I just found this out when installing afresh the rpi os and re-cloning SIP to troubleshoot the error message you found above.

So oled.py and oled-docs.html need to be updated.
But all files are included for the sake of completeness in the attachment.


Attached Files
.zip   oled_plugin 2.zip (Size: 364.74 KB / Downloads: 1)
Reply
#5
PIL is installed and imports in Python3.

I am running Raspbian GNU/Linux 10 (buster)

There is not an oled display connected to my Pi. I don't have one.

Some plugins have a check box at the top of the setup page to enable plugin functionality. This allows the plugin to load without trying to run and avoids errors from not having required hardware connected. That way a user can access the docs and setup info.

Dan
<p><br></p>
Reply
#6
(2021 Oct 10, 08:24 PM)dan Wrote: I did a bit of googling on the error and tried

sudo apt install libopenjp2-7
That fixed the problem but then it couldn't find libtiff5 so:

sudo apt install libtiff5
Then I got:

luma.core.error.DeviceNotFoundError: I2C device not found on address: 0x3D

So I guess the plugin won't load unless an oled display is connected to the pi?

Dan

Hi Dan,

I unplug my oled and install SSD1306.py plugin.  The error message is more informative and user friendly:

pi@sip:~/SIP $ sudo python3 sip.py
SSD1306 plugin: LCD initialize...
SSD1306 plugin: Failed to execute sequence. Is the hardware connected and the right address selected?:
[Errno 121] Remote I/O error
SSD1306 plugin: Done (LCD initialize)
....
SSD1306 plugin: active

So I will change my code to give the same kind of alert message.

Paul

(2021 Oct 10, 08:48 PM)dan Wrote: PIL is installed and imports in Python3.

I am running Raspbian GNU/Linux 10 (buster)

There is not an oled display connected to my Pi. I don't have one.

Some plugins have a check box at the top of the setup page to enable plugin functionality. This allows the plugin to load without trying to run and avoids errors from not having required hardware connected. That way a user can access the docs and setup info.

Dan

Okay, I will include this checkbox as well.  This is useful.

Paul
Reply
#7
I make three changes:

1. A more user-friendly error message ala SSD1306 plugin to warn that no i2c device is detected.

2. A checkbox "enable plugin?" which is unchecked by default to allow plugin page to load so user can access the documentation page even when no i2c device is detected.

3. Installation instruction for additional packages needed for luma.oled library.

Paul


Attached Files
.zip   oled_plugin 3.zip (Size: 364.91 KB / Downloads: 2)
Reply
#8
Not sure if this is or might be an issue but I have some 2cts.
This plugin looks nice but is having another i2c/smbus driver not disturbing the functioning of potential other plugins?
I'm also working on a (port expander) plugin which uses the i2c bus and have chosen the same driver as the other i2c plugins so that no driver conflict can occur. 

--Gerard
Reply
#9
(2021 Oct 11, 08:30 PM)astrogerard Wrote: Not sure if this is or might be an issue but I have some 2cts.
This plugin looks nice but is having another i2c/smbus driver not disturbing the functioning of potential other plugins?
I'm also working on a (port expander) plugin which uses the i2c bus and have chosen the same driver as the other i2c plugins so that no driver conflict can occur. 

--Gerard

Do you mean I should make i2c_bus_number a modifiable parameter?

If so, I can definitely do that.  

I did not make it modifiable following SSD1306 plugin.

But now I think I should. Thanks.

--Paul
Reply
#10
Here is an update to include i2c_bus_number as a modifiable parameter.

Also I found some bugs (related to checkboxes) and fixed them in this attachment.

--Paul

I forgot to remove extraneous print() statements (for debugging purposes) in the previous attachment.

Here I removed them all.

--Paul


Attached Files
.zip   oled_plugin 4.zip (Size: 365.25 KB / Downloads: 2)
.zip   oled_plugin 5.zip (Size: 365.04 KB / Downloads: 5)
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)