RPi-GPIO-Odroid & Python pillow

On HardKernel’s Odroid wiki, this page

RPi.GPIO for ODROID
https://wiki.odroid.com/odroid-c2/application_note/gpio/rpi.gpio

points to a github repository for an RPi.GPIO library that’s been adapted for the Odroid boards:

awesometic/RPi.GPIO-Odroid
https://github.com/awesometic/RPi.GPIO-Odroid

Is it possible to build and install this at all within CoreELEC or is it only possible if I’m running under, say, armbian or Ubuntu? I saw mention on the LibreELEC forums of an rpi-tools addon that appeared to be part of the LE addon repository. Is anything like that available in CoreELEC?

I ask since I’d like to then install the Python packages luma.core and luma.lcd for driving a SPI-connected LCD panel.

Thanks!
Matt

Hmm… perhaps the Entware route will get me just enough development environment to get things working.

What is Entware and How to Install/Uninstall it?

So close…

 opkg update
 opkg install git
 opkg install git-http
 
 opkg install gcc
 opkg install busybox ldd make gawk sed
 opkg install patch diffutils coreutils-install

Install all python3 packages per:
http://www.giuseppeparrello.it/en/net_router_install_python_interpreter.php

UPDATE: Actually, I think opkg install python3 python3-dev python3-pip may be sufficient, rather than everything listed on that site.

 git clone https://github.com/awesometic/RPi.GPIO-Odroid.git
 cd RPi.GPIO-Odroid/
 python3 setup.py build             <--- success!!
 python3 setup.py install

pip3 install --upgrade pillow       <--- this was my mistake; see below

pip3 install luma.oled

git clone https://github.com/rm-hull/luma.examples
cd luma.examples/examples

Trying python3 welcome.py --interface spi, though, gets an error from PIL:

Traceback (most recent call last):
  File "welcome.py", line 14, in <module>
    from luma.core.virtual import viewport, snapshot, range_overlap
  File "/opt/lib/python3.8/site-packages/luma/core/virtual.py", line 8, in <module>
    from PIL import Image, ImageDraw, ImageFont
  File "/opt/lib/python3.8/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/opt/lib/python3.8/site-packages/PIL/__init__.py)

In welcome.py change

from PIL import ImageFont

to

from PIL import _imaging
from PIL import ImageFont

Found this in https://stackoverflow.com/questions/25340698/importerror-cannot-import-name-imaging

I’ll give that a try, @vpeter, once I get python3 back to a working state. :slight_smile:

I went down the route of uninstalling things to try to get a fresh slate, and now things are such that pip3 won’t work (complains of missing urllib, which seems bad)!

Unfortunately, @vpeter, that doesn’t seem to help. Rather than editing source anywhere, I just gave both of the following a try after invoking /opt/bin/python3:

>>> from PIL import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name '_imaging' from 'PIL' (/opt/lib/python3.8/site-packages/PIL/__init__.py)

and, in a separate run:

>>> from PIL import ImageFont
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/lib/python3.8/site-packages/PIL/ImageFont.py", line 33, in <module>
    from . import Image
  File "/opt/lib/python3.8/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/opt/lib/python3.8/site-packages/PIL/__init__.py)

For both, the import in question that actually fails is from PIL/Image.py itself, in the try/except block below. The exception that is supposed to get caught is indeed ImportError, but I don’t think any of the conditions listed match. This form of import is the “modern” version per the third warning box on this page:

Pillow >> Docs >> Installation

I’m wondering if pillow was built correctly for Entware…

Cheers,
Matt


from PIL/Image.py

try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.
    from . import _imaging as core

    if __version__ != getattr(core, "PILLOW_VERSION", None):
        raise ImportError(
            "The _imaging extension was built for another version of Pillow or PIL:\n"
            "Core version: %s\n"
            "Pillow version: %s" % (getattr(core, "PILLOW_VERSION", None), __version__)
        )

except ImportError as v:
    core = deferred_error(ImportError("The _imaging C module is not installed."))
    # Explanations for ways that we know we might have an import error
    if str(v).startswith("Module use of python"):
        # The _imaging C module is present, but not compiled for
        # the right version (windows only).  Print a warning, if
        # possible.
        warnings.warn(
            "The _imaging extension was built for another version of Python.",
            RuntimeWarning,
        )
    elif str(v).startswith("The _imaging extension"):
        warnings.warn(str(v), RuntimeWarning)
    # Fail here anyway. Don't let people run with a mostly broken Pillow.
    # see docs/porting.rst
    raise

Some progress! Browsing through the list of entware packages

https://bin.entware.net/aarch64-k3.10/

I saw there was a python3-pillow. So,

pip3 uninstall pillow
opkg install python3-pillow

and the demo.py invocation now gets me:

Version: luma.oled 3.6.0 (luma.core 1.17.1)
Display: ssd1306
Interface: spi
Dimensions: 128 x 64
------------------------------------------------------------
usage: demo.py [-h] [--config CONFIG] [--display DISPLAY] [--width WIDTH] [--height HEIGHT] ...

demo.py: error: GPIO access not available

Seems like I might almost be there! Soon as I figure out how to get the GPIO access it needs. (I’m already root, so it must be some woe besides permissions.)

demo.py: error: GPIO access not available

That last woe was due to the actual Raspberry Pi version of RPi.GPIO getting installed in one of the earlier steps. Getting that thoroughly deleted and then re-building and re-installing the RPi.GPIO-Odroid code results in this, a working OLED display connected to the C4 running CoreELEC:

spi_OLED_with_CoreELEC

Many thanks to @anon88919003 and the CE developers for making entware available under CoreELEC! I really didn’t want to give up on the platform-specific Kodi improvements the CE team makes, but I want to make progress with this display / front-panel project as well. I was prepared to give armbian or Odroid’s build of Ubuntu a try, but wasn’t looking forward to the state of Kodi in those OSes.

I did get this display working last night in Ubuntu on the C4, but I’m really exited to still be able to use CoreELEC. Now I just need to migrate the LCD panel over from the RPi.

Cheers,
Matt

1 Like

About | FAQ | Terms of Service | Privacy Policy | Legal Notice