Custom NeoPixel LED panel with unicorn library (RPi 3)

Hi guys!

I soldered my own LED panel consisting of 4 horizontal stripes that contain 24 WS2811 LEDs each - so it’s 24x4. It’s just a test, later it will be 24x12. It’s working fine - with one restriction: I cannot feed my own content to it. I’m just lacking the coding skills. So I just tried out the unicorn library - with (limited) success! It comes with plenty of examples and of course a big community of tinkerers. The limitiation of the success lies - as you might guess - in the different layout of the panel. the unicorn library is written for 8x8 panels! So the display on my panel is A) fractured and B) not all LEDs are used.

So pleeeease, I SOOOO want my beautiful LED panel to do tons of funny stuff. Can someone take me by the hand and change some of the code to fit my panel?

I’m actually sure that I’m not the only one that would gain something from it. I mean… soldering a panel from a long LED strip, connecting three wires to the Pi, run a script - super easy. AND SUPER FUN! :)

Have a look see here, https://www.adafruit.com/product/1378
And https://forums.pimoroni.com/search?q=neopixe

Thanks, alphanumeric! Most of the posts and articles you linked to I have already read several times. I did not find a straight answer to my questions there. For me it needs to be a bit more detailed, since I’m new to python.

You shouldn’t use Unicorn HAT, but rather https://github.com/pimoroni/rpi_ws281x-python

This is the library that underpins Unicorn HAT and communicates with the LEDs.

You can see pretty much everything you’ll need to know about using it right at the top of Unicorn HAT’s library code:

And then you call ws2812.setPixelColorRGB(x, r, g, b) where x is the index of the pixel you want to set and r, g, b is the colour.

Do you have a layout diagram for your panel, showing the relationship between pixel order and X/Y position?

In order to create a setPixel that understands x, y coordinates you need to come up with some way of realising your mapping in Python. Unicorn HAT is pretty crude in this respect, just storing all the pixel indexes in a two dimensional array and looking them up like index = mapping_table[x][y]

The only thing close to what you have, that I have, is my Micro Pixel Edge for my BBC Micro Bit. It’s just one row of 10 LEDS. I programed it in Micro Python. I had a really hard time finding said info for it. I don’t think my code will help you much. I went by this, http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/neopixel.html

Thanks for the tip to use that library!
I installed https://github.com/pimoroni/rpi_ws281x-python by running:

git clone https://github.com/pimoroni/rpi_ws281x-python

What else do I have to do to use it?
The thing is, in a frenzy I installed several different libraries and I’m not sure when which one is being used.

EDIT:
Let me elaborate…
pi@raspberrypi:~ $ sudo ./rpi_ws281x/test -sgbr -x24 -y4 -g18 -c
Runs awesome! It generates a scrolling rainbow over the whole panel

After the latest
git clone https//github.com/pimoroni/rpi_ws281x-python
I got these new folders: ~/rpi_ws281x-python/library/rpi_ws281x
What should I do with them?

Sorry, I forgot to answer your question!
Yes, using a Christmas project from Andrew Oakley http://www.aoakley.com/articles/2015-11-18-raspberry-pi-christmas-led-matrix.php#program
I was able to include my layout:

# Size of your matrix
MATRIX_WIDTH=24
MATRIX_HEIGHT=4

# LED matrix layout
# A list converting LED string number to physical grid layout
# Start with top right and continue right then down
# For example, my string starts bottom right and has horizontal batons
# which loop on alternate rows.
#
# Mine ends at the top right here:     -----------\
# My last LED is number 95                        |
#                                      /----------/
#                                      |
#                                      \----------\
# The first LED is number 0                       |
# Mine starts at the bottom left here: -----------/ 

myMatrix=[95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,
          48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,
          47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,
           0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]

If you’ve installed Unicorn HAT you’ll probably already have rpi_ws281x and should be able to skip to starting to hack on the Unicorn HAT library code to make your own interface.

Yes, you’re right - it’s just the “hacking” part where I’m stuck :).
So if anyone can help me with that… tons of gold are waiting for you! MOUNTAINS!!

You could probably just paste your layout into unicornhat.py and make a couple of tweaks to disable unsupported rotations, like this: https://gist.github.com/Gadgetoid/35b2cc87f3d07823bb82cdd3e7f12e6d

If you grab that file and save as mydisplay.py you can then import mydisplay and use it as if it were a weirdly-shaped Unicorn HAT.