Adafruit Matrix Hat Support for BiblioPixel

So, last week, Adafruit launched this little beauty. Having just acquired a handful of Pi B+ and A+ boards and already having a 32×32 matrix that I’d been meaning to use, this was a complete insta-buy™. And, of course, I had to make it work with BiblioPixel! Well, it showed up last night and the coding commenced!

Fortunately, Adafruit already had a library ready to go with a handy python wrapper, since the main code is all C. Unfortunately, the python wrapper was really basic and only provided setting individual pixels. I tried this method first, but 1024 pixels all set one at a time in python was just not nearly fast enough. So…

I next had to figure out how to modify the C python extension… something I’ve never done. As good a time as any to learn! After a bit of documentation reading, I was able to knock out a new function, SetBuffer(), that takes the BiblioPixel data buffer and dumps it to the display’s framebuffer. Internally it’s still using SetPixel, but it’s doing so at the C level and therefore much faster. All this and the BiblioPixel driver is insanely simple, not counting comments only 6 lines:

from rgbmatrix import Adafruit_RGBmatrix
from bibliopixel.drivers.driver_base import *

class DriverAdaMatrix(DriverBase):

    # rows: height of the matrix, same as led-matrix example
    # chain: number of LEDMatrix panels, same as led-matrix example
    def __init__(self, rows = 32, chain = 1):
        super(DriverAdaMatrix, self).__init__(rows*32*chain)
        self._matrix = Adafruit_RGBmatrix(rows, chain)

    #Push new data to strand
    def update(self, data):

Since this driver is so dependent upon the Adafruit library, the Pi, and compiling C code on the Pi, I opted to not include it directly in the main BiblioPixel source. But, through the wonders of open source, it’s already merged into and is available directly in their library!

Enjoy and happy making!


  1. Bibliopixel support for the adafruit led matrixes, great news! could you post an example of how to call it from the Pi’s terminal line. For instance sudo python, there are some commented out lines that look like they could be enabled but no luck. Invalid syntax error.

    1. Make sure BiblioPixel is installed (pip install BiblioPixel) and then copy that commented out code into a new file and run it from there. It was just an example. I’ll add an “if __main__” section to it soon so you can just run that file as is.

  2. Adafruit named that file “”, however using “from ada-matrix import DriverAdaMatrix” results in a ‘syntax error’.
    Renaming the file to and include it with “from adamatrix import DriverAdaMatrix” works.

Leave a Reply