Pi Zero 2 + UnicornHat = (Hardware revision is not supported) Segmentation fault

Thought I’d try the new Zero 2 with a bit of Unicornhat magic.

Sadly, it’s not working:

File "/usr/local/lib/python2.7/dist-packages/rpi_ws281x/rpi_ws281x.py", line 131, in begin
    raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -3 (Hardware revision is not supported)
Segmentation fault

Tried these.

pi@raspberrypi:~ $ sudo pip install --upgrade rpi_ws281x
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already up-to-date: rpi_ws281x in /usr/local/lib/python2.7/dist-packages (4.3.0)
pi@raspberrypi:~ $ sudo pip3 install --upgrade rpi_ws281x
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already up-to-date: rpi_ws281x in /usr/local/lib/python3.7/dist-packages (4.3.0)

Any ideas, please?

Have a look at line 131 of
File “/usr/local/lib/python2.7/dist-packages/rpi_ws281x/rpi_ws281x.py”
I’d guessing its checking to see what hardware is in use. And the Zero 2 W hasn’t been added yet.

Does it work if you use python3 instead of python?

I don’t have one in front of me to try, but I think it might be Unicorn HAT that needs you to run the examples with sudo…

Yes, as far as I know the original unicorn hat requires sudo.
I don’t have one either, I have a mini and HD.

Tried with python/python3
Tried with and without sudo, although it does require sudo, try without for the sake of…

Always the same segmentation error.

And here’s line 123 to 131 of “/usr/local/lib/python2.7/dist-packages/rpi_ws281x/rpi_ws281x.py”
Nowhere (in the entire file) does it mention ‘hardware’ ‘hard ware’ ‘zero’ or ‘pi’

   def begin(self):
        """Initialize library, must be called once before other functions are
        called.
        """

        resp = ws.ws2811_init(self._leds)
        if resp != 0:
            str_resp = ws.ws2811_get_return_t_str(resp)
            raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))

Did a little googling, found this Doesn't support Pi Zero 2 · Issue #475 · jgarff/rpi_ws281x · GitHub
which takes you to this rpi-ws281x · PyPI
Error now reads

RuntimeError: ws2811_init failed with code -5 (mmap() failed)
Segmentation fault

Found my Unicorn HAT, woop!

Just tried the one line installer on a fresh Raspberry Pi OS install (installing things on the Zero 2 is so fast, wow!) and the examples seem to work ok - I’m running them with

sudo python3 rainbow.py

Might be worth flashing a new RPi OS image and starting from scratch, in case the old version of rpi_ws281x is still lurking around somewhere?

1 Like

Reimaged the OS
Installed the Unicornhat files with the one line installer.

BOOM!

pi@raspberrypi:~ $ cd /home/pi/Pimoroni/unicornhat/examples
pi@raspberrypi:~/Pimoroni/unicornhat/examples $ sudo python3 rainbow.py
Rainbow

Displays a beautiful rainbow across your HAT/pHAT :D

If you're using a Unicorn HAT and only half the screen lights up, 
edit this example and  change 'unicorn.AUTO' to 'unicorn.HAT' below.

Reticulating splines
Enabled unicorn poop module!
Pooping rainbows...

What I haven’t done yet, is to run any updates on the OS.
It’ll be interesting to see what happens when I do…

1 Like

Same issue with Pi5 if anyone’s found a solution.

pi@raspberrypi:~ $ cd /home/pi/Pimoroni/unicornhat/examples
pi@raspberrypi:~/Pimoroni/unicornhat/examples $ sudo python3 rainbow.py
Traceback (most recent call last):
  File "/home/pi/Pimoroni/unicornhat/examples/rainbow.py", line 6, in <module>
    import unicornhat as unicorn
  File "/usr/local/lib/python3.11/dist-packages/unicornhat.py", line 35, in <module>
    ws2812.begin()
  File "/usr/local/lib/python3.11/dist-packages/rpi_ws281x/rpi_ws281x.py", line 143, in begin
    raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -3 (Hardware revision is not supported)
Segmentation fault