Python PIL library for ILI9341

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jcdammeyer
 
Posts: 26
Joined: Mon Mar 24, 2014 11:49 am

Python PIL library for ILI9341

Post by jcdammeyer »

I've created an SD card with 5.10 Debian Buster. With SAMBA it's been easy enough to recreate all the user folders used on the older 4.14 Debian Buster pulling them from my PC folders. But when I try to run this simple Python program it's run into problems finding the PIL library

This worked:
debian@beaglebone:~$ sudo apt install build-essential python-dev python-setuptools python-pip python-smbus -y
After it failed a number of times with this:
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='www.piwheels.org', port=443): Read timed out. (read timeout=15)",)': /simple/adafruit-bbio/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', error(0, 'Error'))': /simple/adafruit-bbio/
Where and how do I get the PIL library?

Code: Select all

# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
# Header text removed since it contained banned words.
#
from PIL import Image

import Adafruit_ILI9341 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI


# Raspberry Pi configuration.
#DC = 18
#RST = 23
#SPI_PORT = 0
#SPI_DEVICE = 0

# BeagleBone Black configuration.
DC = 'P9_15'
RST = 'P9_12'
SPI_PORT = 1
SPI_DEVICE = 0

# Create TFT LCD display class.
disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))

# Initialize display.
disp.begin()

# Load an image.
FileName = 'ORING_YVR_SMALL.jpg'
print('Loading image...'+FileName)
image = Image.open(FileName)

# Resize the image and rotate it so it's 240x320 pixels.
image = image.rotate(90).resize((240, 320))

# Draw the image on the display hardware.
print('Drawing image')
disp.display(image)
Attachments
ORING_YVR_SMALL.jpg
ORING_YVR_SMALL.jpg (69.89 KiB) Viewed 1580 times

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Python PIL library for ILI9341

Post by adafruit_support_carter »

Which ILI9341 based display are you using? Please link to product page.

jcdammeyer
 
Posts: 26
Joined: Mon Mar 24, 2014 11:49 am

Re: Python PIL library for ILI9341

Post by jcdammeyer »

Why does that even matter? I did go through my last few years of orders. There are two Beaglebone Black along with HDMI displays. But your question doesn't make sense.
I picked the smallest sample program I had to show the PIL library.
How do I get that??

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Python PIL library for ILI9341

Post by adafruit_support_carter »

If your only issue is with installing PIL/Pillow, you can try here:
https://pypi.org/project/Pillow/

If there is a problem with the hardware, then we need more information on what specific hardware is being used.

jcdammeyer
 
Posts: 26
Joined: Mon Mar 24, 2014 11:49 am

Re: Python PIL library for ILI9341

Post by jcdammeyer »

Thank you for your prompt support. I had not tried that link. However it turns out not to work with this version of Debian on the Beagle.
If I insert the other micrSD card:
debian@ebb:~$ uname -a
Linux ebb 4.19.94-ti-r68 #1buster SMP PREEMPT Thu Sep 16 15:32:31 UTC 2021 armv7l GNU/Linux

debian@ebb:~/Python/Adafruit_Python_ILI9341/examples$ python image_orings.py
Loading image...ORING_YVR_SMALL.jpg
Drawing image
debian@ebb:~/Python/Adafruit_Python_ILI9341/examples$
,
It doesn't matter if the hardware is connected or not.

For the newer version of Debian it failed with the newer versions of pillow.
Instead:
debian@beaglebone:~$ pip install Pillow==1.0
...
Successfully installed Pillow-1.0
Then was told I didn't have the Adafruit library so

Code: Select all

ImportError: No module named Adafruit_ILI9341
debian@beaglebone:~/Python/Adafruit_Python_ILI9341/examples$ pip install Adafruit_ILI9341
...
Successfully installed Adafruit-GPIO-1.0.3 Adafruit-ILI9341-1.5.1 adafruit-pureio-1.0.1 spidev-3.5
Finally another try and this time this error.
debian@beaglebone:~/Python/Adafruit_Python_ILI9341/examples$ python image_orings.py
Loading image...ORING_YVR_SMALL.jpg
Traceback (most recent call last):
File "image_orings.py", line 52, in <module>
image = image.rotate(90).resize((240, 320))
File "/home/debian/.local/lib/python2.7/site-packages/PIL/PIL/Image.py", line 1359, in rotate
self.load()
File "/home/debian/.local/lib/python2.7/site-packages/PIL/PIL/ImageFile.py", line 189, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/home/debian/.local/lib/python2.7/site-packages/PIL/PIL/Image.py", line 385, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
And once again I'm lost.
Where do I find the jpeg decoder?

Back in 2019 when I last worked with this on the 4.19 Debian BBB converting the Pi code to the Beagle I didn't have any problems. So obviously many things have changed.
Thanks
John

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Python PIL library for ILI9341

Post by adafruit_support_carter »

If you are having issues installing PIL/Pillow on a specific Linux distribution, you'll need to contact the PIL/Pillow project maintainers.

While the Adafruit library relies on having Pillow installed, it does nothing special in terms of installation. It looks like you can recreate the issue by simply trying to run the Pillow open() command on a JPEG file. It looks like there are missing dependencies. But why those dependencies did not get installed when Pillow was originally installed would be an issue for the Pillow maintainers to look at.

jcdammeyer
 
Posts: 26
Joined: Mon Mar 24, 2014 11:49 am

Re: Python PIL library for ILI9341

Post by jcdammeyer »

Thank you.
The last time I installed this I just followed the instructions from one of the pages which is why I had the ADAfruit libraries. I don't remember having problems. But then it was a few years ago.
Thanks for your help.
I'll first check with the Beaglebone support with respect to their new kernel and why trying to install pillow fails. There is some ambiguity as to whether even it installs the the jpeg module or whether on the older Debian 4.14 was automatically added. Migrating to 4.19 didn't change that it was there. But now 5.10 there is an issue.
I will report back with the results.

jcdammeyer
 
Posts: 26
Joined: Mon Mar 24, 2014 11:49 am

Re: Python PIL library for ILI9341

Post by jcdammeyer »

I took a new sd and did the following:
debian@jcd:~/Python/Adafruit_Python_ILI9341/examples$ python image_orings.py
Traceback (most recent call last):
File "image_orings.py", line 21, in <module>
from PIL import Image
ImportError: No module named PIL
debian@jcd:~/Python/Adafruit_Python_ILI9341/examples$

debian@jcd:~$ sudo pip3 install adafruit-circuitpython-rgb-display

debian@jcd:~$ python3 -m pip install --upgrade pip

debian@jcd:~$ sudo apt install libjpeg62-turbo-dev

debian@jcd:~$ python3 -m pip install --upgrade Pillow
Successfully built Pillow
Installing collected packages: Pillow
Successfully installed Pillow-9.1.0

debian@jcd:~$ python3 -m pip install Adafruit-GPIO
Finally ended up here:
d
ebian@jcd:~/Python/Adafruit_Python_ILI9341/examples$ python3 image_orings.py
Traceback (most recent call last):
File "image_orings.py", line 46, in <module>
disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))
TypeError: __init__() got multiple values for argument 'spi'
The structure of SPI bus, Outputs for DC and RESET have all changed so now the sample program needs a complete rewrite.

Further research on the Adafruit forums suggests that as of last year support for BeagleBone is essentially discontinued. A search for the boards that are supported with CPython etc. doesn't turn up the Beagle.

So with regret I'll abandon the Adafruit approach of Python or CPython or Python2 or Python3 (whatever flavour is popular this week) and return to Lazarus and Free Pascal or C. In that IDE all the code from 4 years ago can still compile on the newest Debian 5.10 and communications via SPI and I2C both work.

We can consider this issue closed.
John

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”