Adafruit Matrix Hat Support for BiblioPixel

Adafruit Matrix Hat

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):
        self._matrix.SetBuffer(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!

Multi-Driver Demo with BiblioPixel

Last time on the Maniacal Labs Blog… we told you about the awesome new multiple driver support added to BiblioPixel in the latest version. Well, check out the video below to see the proof!




All the code from the video is below. More details are on the BiblioPixel Wiki. And be sure to visit the Maniacal Labs Forum to discuss usage or ask questions. Happy making!

#Load driver for your hardware, visualizer just for example
import time
import bibliopixel.log as log
log.setLogLevel(log.DEBUG)

useSerial = False

if useSerial:
    from bibliopixel.drivers.serial_driver import *
    #Use DeviceIDManager.py to set or view your device IDs
    driverA = DriverSerial(LEDTYPE.NEOPIXEL, 8*8, deviceID = 0)
    driverB = DriverSerial(LEDTYPE.NEOPIXEL, 8*8, deviceID = 1)
    driverC = DriverSerial(LEDTYPE.NEOPIXEL, 16*8, deviceID = 2)
else:
    from bibliopixel.drivers.visualizer import *
    #When using multiple visualizers you must specify distinct ports
    driverA = DriverVisualizer(width=8, height=8, port=1610, pixelSize = 30, stayTop=True)
    driverB = DriverVisualizer(width=8, height=8, port=1611, pixelSize = 30, stayTop=True)
    driverC = DriverVisualizer(width=16, height=8, port=1612, pixelSize = 30, stayTop=True)


#load the LEDMatrix class
from bibliopixel.led import *
import bibliopixel.colors as colors

#change rotation and vert_flip as needed by your display
build = MultiMapBuilder()
build.addRow(mapGen(8,8, serpentine=(not useSerial)), mapGen(8,8, serpentine=(not useSerial)))
build.addRow(mapGen(16,8, serpentine=(not useSerial)))
#in the AllPixel version of the demo we used WS2812 matrices that were not serpentine, but the visualizer 
#If using multiple different displays, use whatever it is for that display

#create LEDMatrix and load in generated map
#threaded updates are fastest when using multiple drivers
led = LEDMatrix(driver = [driverA, driverB, driverC], threadedUpdate = True, width = 16, height = 16, coordMap=build.map)

try:
    from matrix_animations import *

    anim = Bloom(led, dir=True)
    anim.run(amt=6, fps = 30)

except KeyboardInterrupt:
    pass

led.all_off()
led.update()
#since updates are threaded, give them time to finish before exiting the app
time.sleep(2)

Exciting Updates!

It’s been a little over a month since the Kickstarter for our AllPixel finished and things are progressing nicely. We’ve certainly learned a lot about communicating with an overseas manufacturer and designing a product for mass production. Nothing a few tiny tweaks couldn’t fix. Our goal has always been to deliver the best possible product. The final boards should be going into production within the next week or two!

During the campaign, we set a stretch goal of providing multiple driver support to BiblioPixel. Sadly, we didn’t actually meet that goal. But we couldn’t just let it go… version 1.1.x of BiblioPixel is now available with full support for multiple drivers! Now, you can run a display with as many AllPixels as your computer can handle the data for! No longer is your display limited to the 700 pixel limit of the AllPixel… wire in another and BiblioPixel will magically make both act as one! For more details, check out the BiblioPixel Wiki.

In the effort to provide multiple driver support, we also added threaded display updates. This allows all the updates to the display to happen on background threads (one per driver). The details are all a bit technical, but what this means is higher animation frame-rates, especially when using multiple drivers. For example, if you have four AllPixels connected, they will all update the display at the same time… while the next frame is being generated! With these two new features, we hope to really make BiblioPixel even more of an animation power house.

As a little side bonus, we also added a new driver to BiblioPixel that allows control of the Philips Hue LED lights. They aren’t nearly as fast as the usual LED lights your used to using with BiblioPixel as they are meant for home lighting, but this will allow super easy control of Hue lights directly from BiblioPixel.

That’s all for now! Stay tuned.

Requiem for Maker Faire NC

MFNC

Last night, we got some really disappointing news; Maker Faire North Carolina will not be happening this year :(

Last year’s faire was an exceptional experience and the AllPixel may not have happened without it. Having been planning for and looking forward to exhibiting at the 2015 faire since the moment the 2014 one ended, this was horribly crushing to hear. But as they explain on their website, it was not an easy decision, but simply became more than the organizers could handle in their spare time.

We sincerely hope that the Maker community can rally together and make it a possibility to bring a Maker Faire back to Raleigh. There will be a giant void in our year without it.

-Adam