rm-hull / luma.led_matrix

Python module to drive LED Matrices & 7-segment displays (MAX7219) and RGB NeoPixels (WS2812 / APA102)
https://luma-led-matrix.readthedocs.io
MIT License
523 stars 157 forks source link

AttributeError: module 'PIL.Image' has no attribute 'new' #259

Closed unitythemaker closed 3 years ago

unitythemaker commented 3 years ago

Type of Raspberry Pi

Raspberry Pi Zero WH

Linux Kernel version

Linux raspberrypi 5.10.17+ #1414 Fri Apr 30 13:16:27 BST 2021 armv6l GNU/Linux

Expected behaviour

I'm expecting Python to run the code without errors. I inspected 10s of issues but didn't find any solution. Before getting that error I was getting something like: No module named luma.led.matrix found or same for luma.core.

Actual behaviour

pi@raspberrypi:~/luma.led_matrix $ sudo python3 -m pip install luma.core luma.led_matrix
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting luma.core
  Using cached https://www.piwheels.org/simple/luma-core/luma.core-2.3.1-py2.py3-none-any.whl (71 kB)
Collecting luma.led_matrix
  Using cached https://www.piwheels.org/simple/luma-led-matrix/luma.led_matrix-1.5.0-py2.py3-none-any.whl (19 kB)
Requirement already satisfied: cbor2 in /usr/local/lib/python3.7/dist-packages (from luma.core) (5.4.2)
Requirement already satisfied: pillow>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from luma.core) (8.4.0)
Requirement already satisfied: spidev in /usr/lib/python3/dist-packages (from luma.core) (3.4)
Requirement already satisfied: RPI.GPIO in /usr/lib/python3/dist-packages (from luma.core) (0.7.0)
Requirement already satisfied: pyftdi in /usr/local/lib/python3.7/dist-packages (from luma.core) (0.53.3)
Requirement already satisfied: smbus2 in /usr/local/lib/python3.7/dist-packages (from luma.core) (0.4.1)
Requirement already satisfied: deprecated in /usr/local/lib/python3.7/dist-packages (from luma.core) (1.2.13)
Installing collected packages: luma.core, luma.led-matrix
Successfully installed luma.core-2.3.1 luma.led-matrix-1.5.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
pi@raspberrypi:~/luma.led_matrix $ sudo python3 examples/matrix_demo.py
Traceback (most recent call last):
  File "examples/matrix_demo.py", line 122, in <module>
    demo(args.cascaded, args.block_orientation, args.rotate, args.reverse_order)
  File "examples/matrix_demo.py", line 22, in demo
    rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
  File "/usr/local/lib/python3.7/dist-packages/luma/led_matrix/device.py", line 89, in __init__
    self.clear()
  File "/usr/local/lib/python3.7/dist-packages/luma/core/mixin.py", line 46, in clear
    self.display(Image.new(self.mode, self.size))
AttributeError: module 'PIL.Image' has no attribute 'new'
unitythemaker commented 3 years ago

I think this problem is not luma specific. It's more like about Pillow. I'll try to research about it.

Edit: luma.oled doesn't work too I tested it now. AttributeError: module 'PIL.ImageFont' has no attribute 'ImageFont'

unitythemaker commented 3 years ago

I ran the library on my RPi 3B without errors. The problem is related to Pi Zero. Can you make it run on Pi Zero? TY anyways.

thijstriemstra commented 3 years ago

Hmm, I doubt that. What python version are you using? Same version on both RPi 3B and Pi Zero? What operating system (version)?

unitythemaker commented 3 years ago

Common

Raspbian Lite (the versions are same because installed w/ RPi Imager and the image was cached and didn't redownload therefore the OS' are same.)

pi@raspberrypi:~ $ python3 --version
Python 3.7.3

Installed pip via sudo apt install python3-pip.
Ran apt upgrade before installing & trying these.

RPi3B

pi@raspberrypi:~ $ pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.63-v7+ #1459 SMP Wed Oct 6 16:41:10 BST 2021 armv7l GNU/Linux
# Notice the armv7l may it can help

RPi Zero WH

pi@raspberrypi:~ $ pip3 --version
pip 21.3.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.63+ #1459 Wed Oct 6 16:40:27 BST 2021 armv6l GNU/Linux
# Notice the armv6l may it can help
thijstriemstra commented 3 years ago

some ideas:

unitythemaker commented 3 years ago

The matrix doesn't change it's initial shape and the code doesn't give any error also shows logs like

Created device
MAX7219 LED Matrix Demo
Click to view image ![image](https://user-images.githubusercontent.com/83316880/140623591-765dc855-7ea3-4cc9-81d8-d0ab51ab1f12.png)

However I can see the brightness of leds are changing slightly. I saw some issues about it like #102.

Also I've newly noticed that the boards in the images are not same with mine. Mine have a MAX7219CNG integrated. I don't know if that will make any change about that problem but it worked with RPi3B first. Now it doesn't even if I re-install the OS and try the same things on RPi3B.

(I'm running the code examples/matrix_demo.py)

Edit: Tried connecting matrix to SPI1 by looking at #169 & #204 and still no change.

# changed this line & changed wiring
    serial = spi(port=0, device=1, gpio=noop())
unitythemaker commented 3 years ago

I've tried running this matrix with Arduino UNO and still no change. It seems like the problem is way more different. TYSM for helping me!

unitythemaker commented 3 years ago

I found the problem. The integrated was connected incorrectly.

nse-2461396820112576173-83252 nse-9058724158996543697-83253 nse-7768186634596230443-83254

thijstriemstra commented 3 years ago

I found the problem.

nice!

The integrated was connected incorrectly.

Can you be a little more specific? Maybe it helps others googling similar problems.

unitythemaker commented 3 years ago

Oh, ok. As you can see in the images: The integrated is attached onto a black header. However in the PCB, it shows it's correct direction but it is soldered in the wrong direction. Therefore you attach the integrated by looking at the header's side that has a semicircle. Which is actually the wrong direction according to PCB.