Skip to content

Drivers

Tom Ritchford edited this page May 13, 2017 · 9 revisions

Drivers are what make BiblioPixel so flexible. All the work of generating pixel data can be completely abstracted away from the hardware while the drivers handle actually doing something with that data, no matter what that may be.

Currently, the included drivers are:

  • SimPixel: A driver that outputs to a WebGL page. For development and standalone applications.
  • Dummy: Outputs to nothing. For testing.
  • LPD8806: Direct SPI LDP8806 control.
  • WS2801: Direct SPI WS2801 control.
  • APA102: Direct SPI APA102 control.
  • Network: For interfacing with hardware connected to another device on the network.
  • Serial: For interfacing with serial controllers, like the AllPixel.
  • ImageSequence: Outputs each frame to an image.
  • Hue: Control of Philips Hue lights.
  • PiWS281X: Raspberry Pi-only driver for PiWS281X hardware.

These are all very useful, but what makes the driver system even more useful is the ability to write your own. This is made easy by the DriverBase base-class, for example:

from bibliopixel.drivers.driver_base import *

class DriverTest(DriverBase):
    def __init__(self, num, gamma = None):
        super(DriverTest, self).__init__(num, gamma)
        #do any other initialization here

    #Push new data
    def update(self, data):
	#handle channel order and gamma correction
        self._fixData(data)
        #output to hardware/UI/etc.
        print(data)

The above is all that is needed for a working driver, aside from the actual implementation of interfacing with your hardware, UI, etc. For more complicated setups, see DriverBase for available properties and methods that can be overridden.

DriverSPIBase is also provided for creating drivers using direct SPI port access on devices like the Raspberry Pi and Beagle Bone Black. For example, the WS2801 driver:

from bibliopixel.drivers.spi_driver_base import *

class WS2801(DriverSPIBase):
    def __init__(self, num, c_order = ChannelOrder.RGB, use_py_spi = True, dev="/dev/spidev0.0", SPISpeed = 1, gamma = None):
        if SPISpeed > 1 or SPISpeed <= 0:
            raise ValueError("WS2801 requires an SPI speed no greater than 1MHz or SPI speed was set <= 0")
        super(WS2801, self).__init__(num, c_order = c_order, use_py_spi = use_py_spi, dev = dev, SPISpeed = SPISpeed, gamma)

The WS2801 chipset has a very simple protocol so no changes to the update() method are needed. All the hard work of SPI setup and communication is handled by DriverSPIBase. If a more complicated data format is needed, modify the data buffer in __init__() or override update() and modify self._buf before calling self._sendData(), which is normally called automatically in the default update() implementation.

Clone this wiki locally