pimoroni / unicornhatmini-python

Python library for the Pimoroni Unicorn HAT Mini RGB LED Display
MIT License
45 stars 15 forks source link

Unicornhatmini library broken following the last raspberry update #4

Closed Cthuga closed 1 year ago

Cthuga commented 4 years ago

Hello,

Just updated the raspberry pi 4 to the last update this morning, since then :

File "/usr/local/lib/python3.7/dist-packages/unicornhatmini-0.0.1-py3.7.egg/unicornhatmini/init.py", line 56, in init SystemError: error return without exception set

I tried to reinstall it, but the error stays.

Could you look into it?

Gadgetoid commented 4 years ago

What are you running when you encounter this error?

Looks like line 56 is something to do with setting up SPI, in this case changing the polarity of chip select:

https://github.com/pimoroni/unicornhatmini-python/blob/39bd7e1e685c4497081279c22939f578ca30f969/library/unicornhatmini/__init__.py#L56

Could potentially be a bug with the system itself, or maybe this was just never fully supported.

Is this the latest Raspberry Pi OS, or is it the Raspberry Pi OS 64bit beta?

Cthuga commented 4 years ago

Nothing much. It happend as soon, I try to define an object from unicornhatmini import UnicornHATMini unicornhatmini = UnicornHATMini()

I'm using the latest Pi OS not the 64bit.

It was working fine this morning, I did : sudo apt update sudo apt full-upgrade sudo reboot

And after that my python program would not work anymore.

Gadgetoid commented 4 years ago

I'm not sure if this is a bug in Python SpiDev or a bug in the new Raspberry Pi 5.x kernel. I am looking into it and have reported it upstream here- https://github.com/raspberrypi/linux/issues/3745

Gadgetoid commented 4 years ago

Not sure if cshigh = False is actually necessary, or if it's the default, but omitting this line allows the library to work on 5.x. Patch:

diff --git a/library/unicornhatmini/__init__.py b/library/unicornhatmini/__init__.py
index 8cae250..d76204c 100644
--- a/library/unicornhatmini/__init__.py
+++ b/library/unicornhatmini/__init__.py
@@ -53,7 +53,7 @@ class UnicornHATMini():

         for device, pin, offset in self.left_matrix, self.right_matrix:
             device.no_cs = True
-            device.cshigh = False
+            # device.cshigh = False
             device.max_speed_hz = spi_max_speed_hz
             GPIO.setup(pin, GPIO.OUT, initial=GPIO.HIGH)
             self.xfer(device, pin, [CMD_SOFT_RESET])
Cthuga commented 4 years ago

Thanks you for your help. I made the comment as sugested, everything is back to normal.

Thanks again.