PiicoDev OLED Display Module (128x64) SSD1306

Using a Raspberry Pi Zero W I hit an error trying to load the library in the very first line.

File “line.py”, line 1, in
from PiicoDev_SSD1306 import *
File “/home/pi/.local/lib/python3.7/site-packages/PiicoDev_SSD1306.py”, line 43, in
from PIL import Image
ModuleNotFoundError: No module named ‘PIL’

I made a guess that PIL is the Python Imaging Library but it seems that this is now superceded by a fork called pillow. pip3 could not install PIL but did install pillow. With pillow installed the library progresed a little further but crashed again so looks like my guess was wrong.

File “line.py”, line 1, in
from PiicoDev_SSD1306 import *
File “/home/pi/.local/lib/python3.7/site-packages/PiicoDev_SSD1306.py”, line 43, in
from PIL import Image
File “/home/pi/.local/lib/python3.7/site-packages/PIL/Image.py”, line 114, in
from . import _imaging as core
ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory

Would appreciate if someone could tell me what I have done wrong.

7 Likes

Hey Fractal,

I’ve just taken a look into this. I’m not familiar enough with PyPi packaging (having only just read about it right now :sweat_smile: ) to submit a fix, but from my quick glance over the CE PyPi package, this tutorial on creating PyPi packages, and the Piicodev SSD1306 firmware, it looks like you’re close to the money.

I think they might’ve forgotten to update the PyPi package to require Pillow as an extra_requires for the SSD1306. You should also note that Pillow and PIL can’t co-exist since Pillow is a direct replacement and uses the identical “PIL” library name. To install it properly according to the Pillow docs, you need to run:
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

Note the -m argument - this might be what’s caught you out in attempting to manually install Pillow. See:

Just on a hunch as well, the update to Pi OS Bullseye from Buster might’ve broken somethings, so if this doesn’t work maybe try downgrading to Buster to see if it works then.

Edit: Tagging the Core guys @Michael @Brenton @Peter

8 Likes

Thanks for the feedback, @Fractal :pray: We’ll look into this and modify the package requirements as necessary so that PiicoDev remains a 1-click install for Raspberry Pi users.

7 Likes

Hi Michael

Many thanks. The error is in line 43 of PiicoDev_SSD1306.py but would continue in lines 44 and 45 as well. It cannot find PIL and from the above it seems PIL is not the PIL library or its fork Pillow.

42 elif _SYSNAME == ‘Linux’:
43   from PIL import Image
44   from PIL import ImageDraw
45   from PIL import ImageFont

I am running it on a Raspberry Pi Zero W so using Raspberry Pi OS Lite (Buster). Just had the thought that perhaps the desktop version has a package installed which is missing from the Lite version.

6 Likes

I had another look at this and decided that in lines 43-44 of PiicoDev_SSD1306.py it is trying to import from Pillow.

elif _SYSNAME == ‘Linux’:
  from PIL import Image
  from PIL import ImageDraw
  from PIL import ImageFont

This is easily fixed by

pip3 install Pillow

The continuing errors appear to be from missing packages. After studying the Pillow documentation I found that Pillow requires the libjpeg and zlib external packages. Not sure why they did not install along with Pillow. Not without some trouble I installed libjpeg.

pip3 install pylibjpeg-libjpeg

Fixed, but now a new error.

  File “/home/pi/.local/lib/python3.7/site-packages/PIL/Image.py”, line 89, in
     from . import _imaging as core
ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory

So

sudo apt-get install libopenjp2-7-dev

Fixed, but yet another error

   File “/home/pi/.local/lib/python3.7/site-packages/PIL/Image.py”, line 89, in
     from . import _imaging as core
ImportError: libtiff.so.5: cannot open shared object file: No such file or directory

So

sudo apt install libtiff5

A tragic mistake. python3 now has the error “illegal instruction”

So

sudo apt remove libtiff5

Anyway still trying to install zlib with no zlib in pypi. In desperation I tried

pip3 install micropython-zlib

But the installation failed.

I assume that CE has sold hundreds of the PiicoDev OLED Display Modules which are all happily running. Do not understand why I am having all this trouble.

4 Likes

Hi Fractal,

I think you missed my comment. You need to use the -m flag:

3 Likes

Hi Oliver33

Sorry, I did not mention I tried your Pillow installation method

python3 -m pip install --upgrade Pillow

but found the behaviour was exactly the same as

pip3 install Pillow

I had always thought that pip3 install and python3 -m pip install did exactly the same thing but I am definitely not an expert.

I am fairly certain Pillow is installed correctly. From the error message it is being called

    from PIL import Image
  File “/home/pi/.local/lib/python3.7/site-packages/PIL/Image.py”, line 89, in
    from . import _imaging as core
ImportError: libtiff.so.5: cannot open shared object file: No such file or directory

Interesting that in the video tutorial the OLED ran with just the piicodev package installed. I am running Version 1.0.0 which is the latest.

6 Likes

Hi @Fractal

We have just released a new version which removes the dependency on PIL altogether.

Instructions here piicodev · PyPI

The new release is also on GitHub GitHub - CoreElectronics/CE-PiicoDev-SSD1306-MicroPython-Module: CE-PiicoDev-SSD1306-MicroPython-Module

Cheers,

Peter

7 Likes

Hi @Peter

Many thanks for the new version. It is great to be rid of the PIL dependency which I found problematic.

pip3 install --upgrade piicodev #Upgrade package
pip3 list #Check piicodev is Version 1.01

I have run all of the sample scripts without error.

In PiicoDev_SSD1306.text(s, x, y, c=1) I found the font (font-pet-me-128.dat) could not be changed being hard coded into the library. It is a small font and I can think of applications such as displaying a temperature where a large font or a mixed font would be useful. Perhaps in a future development you would consider mixed or scalable fonts. It is not possible to use pbm files to display say large font numbers. That could have been a quick fix.

The animation sample is an indefinite loop. Normally the code would be stopped by a ^C keyboard interupt. I found because the code is running in the library most of the time this did not work giving the message:

^CPiicoDev could not communicate with module at address 0x3C, check wiring

The only way I could stop the code running was to start a second PuTTY terminal:

sudo pkill python

The first PuTTY then displays:

Terminated

Is anyone aware of a better way of doing it?

7 Likes

Have you found a fix for this yet? thanks!

2 Likes

Hi Zac,

Welcome!

A simple way that I could think of would be hooking up a button and breaking the loop if its pressed or changing the while True to use a condition to break after x events or a for loop.

When I was testing out the code on the Pico I found I could break the loop in Thonny consitently, does interupting work for other PiicoDev modules?

4 Likes

Note the loss of keyboard interupt is mainly a problem with the animation sample which is a continuous loop. Also note it is only a problem during development and not an issue once in production. It is not a major issue and not one I was overly concerned about. As suggested a switch closure test in the loop could be used to exit the script.

The small fixed font for text however is very limiting. It is something which I would like to see improved but I am not certain if CE are working on it.

5 Likes