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
521 stars 156 forks source link

Snake layout with size other than 8*8 #173

Closed thomasw-mitutoyo-ctl closed 5 years ago

thomasw-mitutoyo-ctl commented 5 years ago

Type of Raspberry Pi

Raspberry Pi 3. Note that it's not a hardware issue. WS2812B works when size is set to 8*8

Linux Kernel version

4.14.79-v7

Background information

I have a 8*32 WS2812 board that is assembled in snake mode. You can find them on Ali Express by searching for "ws2812b 8x32".

Expected behaviour

I expected the LEDs to work with the setting

device=ws2812(width=32, height=8, mapping=UNICORN_HAT)

I use width=32 and height=8 as these are my physical dimensions and I use UNICORN_HAT because that should give me the snake layout.

Actual behaviour

There's an AssertionError in device.py in __init__() at

assert(self.cascaded == len(self.mapping))

followed by an AttributeError

'ws2812' object has no attribute '_ws'

As far as I understand, the object does not have the property, because the __init__() method did not run to the point where self._ws is initialized.

thomasw-mitutoyo-ctl commented 5 years ago

Perhaps the fixed size array UNICORN_HAT could be replaced by a generator.

I also see that I can replace the mapping parameter by something I create myself.

So I had a look at the UNICORN_HAT array and I managed to create the same array by a generator and then increased the length of that generator. However, my first try behaved snakey. Therefore, I flipped every second 8 elements in the resulting array. I was really puzzled to see what happend. The result is even worse. It's not intuitive how the mapping works.

Until now I have tried 6 different generators but I was still unable to figure out the sequence needed for my LED panel.

rm-hull commented 5 years ago

Have a look at https://github.com/rm-hull/luma.led_matrix/blob/master/examples/neopixel_crawl.py (change the cascaded=... to suit your purposes). This should give you an idea how your board is laid out

roboter-basteln commented 5 years ago

@rm-hull: I followed that example and successfully created a mapping for width=256, height=1. All LEDs do light up in the order I want to. It worked exactly like expected, that is: how I see the wires on the PCB.

However, when I use the same mapping on width=32, height=8, the LEDs light up differently.

I have modified the code to do a 2D mapping as well, but as far as I understand, I can't put tuples into the mapping, just scalar values. I still didn't figure out the formula for mapping the x-y-coordinates to scalar values. I've tried the combinations x*width+y, x*height+y, y*width+x and y*height+x.

rm-hull commented 5 years ago

Can you record and post a video of the neopixel crawl running on your 32x8 matrix please?

Also, can you share the mapping code you have tried please?

thijstriemstra commented 5 years ago

ping @thomasw-mitutoyo-ctl