1

Where can I find a C/C++ library to control a 16x16 ws2812b led matrix using a Raspberry Pi?

There exists a C code for Unicorn HAT HD here but the unicorn HAT HD uses four GPIO pins as data pins (pin diagram of unicorn hat HD) while the led matrix which I have has only one DIN pin. So is there a possibility of making some hardware connections so that I will be able to use that code?

2 Answers 2

2

The WS2812B has very tight timing requirements which makes it difficult to drive from the Pi. In effect the data line must be clocked very accurately. APA102 based LEDs are much easier to drive as they have separate clock and data lines.

The only library I am aware of is rpi_ws281x by Jeremy Garff.

It's interesting that the Unicorn HAT uses SPI. I didn't think that was possible because of the timing gap between SPI bytes inserted by the SPI hardware when configured by the Linux SPI driver. However I think that gap was removed recently (say 6 months ago) which may well have made standard SPI a practical solution on the Pi for driving the WS2812B.

If SPI is indeed now usable for this purpose I'd expect to see new libraries being produced to drive these chips (perhaps they have already, I haven't looked recently).

1
  • I thought I would provide an update. I followed learn.adafruit.com/neopixels-on-raspberry-pi/software and note that the rpi_ws281x library has been updated for the Pi3B+. This seems to work OK on my Pi3B+. I currently have only a single WS2812B connected via a level converter, but will connect a few more. (I intend to give my grandson a Pi, and I am sure he will like playing with the lights.)
    – Milliways
    Commented May 1, 2018 at 8:12
0

Had a look into the rpi_ws281x library and found that by changing the values of WIDTH & HEIGHT and getPixelPosition() function accordingly in this code we can make the code work for any mxn led matrix.

So we do not necessarily need SPI to drive the ws2812b led matrix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.