DriverSerial - adammhaile/ae45LhX89i GitHub Wiki

class bibliopixel.drivers.serial_driver.DriverSerial

DriverSerial allows for the control of the AllPixel or any other serial device that implements the same protocol.

__init__(type, num, dev="", c_order = ChannelOrder.RGB, SPISpeed = 16, gamma = None, restart_timeout = 3)

  • type - Type of LEDs being controlled by the serial hardware. See LED Types for more info.
  • num - Number of pixels to be controlled.
  • dev - The name of the COM port to be used. If using the AllPixel this can be left blank and the port name will be automatically detected.
  • c_order - Optional: Channel order used by the attached display. Can be any of the six options in the ChannelOrder class. See Channel Order for more details.
  • SPISpeed - Optional. The SPI speed, in MHz, to use when communicating with SPI-based strips. Valid range; 1-24.
  • gamma - 256 value gamma correction list. The list MUST contain 256 8-bit integer values. Predefined corrections lists can be found in bibliopixel.gamma
  • restart_timeout - Number of seconds to wait after reconfiguration and restarting the device before trying to reconnect. Some systems take longer to re-enumerate the device and, if so, increase this value. However, if a reconfigure is needed and reconnect fails it does not mean the reconfigure failed. Increasing this value is not necessarily needed, but just restarting the script instead.

setMasterBrightness(brightness)

  • brightness - 8-bit (0-255) brightness value.

When using DriverSerial, calling setMasterBrightness will attempt to pass along the brightness request to the hardware, if supported. If it is supported in the receiving hardware it will return True, otherwise False.

LED Types

The "type" parameter of the init method from above should be an integer value, representing chipsets supported by the serial hardware. The list below is specifically for the AllPixel but if other chipsets values are needed, any integer value can be passed instead of using the LEDTYPE enumeration. The intent is that the serial device may support multiple chipsets and this value allows configuring which chipset is used at run-time. A type value of 0 can be used if the device only supports one chipset.

class LEDTYPE:
    GENERIC = 0 #Use if the serial device only supports one chipset
    LPD8806 = 1
    WS2801  = 2
    #These are all the same
    WS2811 = 3
    WS2812 = 3
    WS2812B = 3
    NEOPIXEL = 3
    #400khz variant of above
    WS2811_400 = 4

    TM1809 = 5
    TM1804 = 5
    TM1803 = 6
    UCS1903 = 7
    SM16716 = 8

Protocol

Each packet sent to the serial device follows the same format:

command length (n) data
0 to 255 high byte low byte n bytes of message data

Command values currently use the following values, as defined in the CMDTYPE enumeration:

class CMDTYPE:
    SETUP_DATA = 1 #config data (LED type, SPI speed, num LEDs)
    PIXEL_DATA = 2 #raw pixel data will be sent as [R1,G1,B1,R2,G2,B2,...]
    BRIGHTNESS = 3 #data will be single 0-255 brightness value, length must be 0x00,0x01

After each command is sent, the receiver returns a single byte return code, as defined by the RETURN_CODES enumeration:

class RETURN_CODES:
    SUCCESS = 255 #All is well
    REBOOT = 42 #Device reboot needed after configuration
    ERROR = 0 #Generic error
    ERROR_SIZE = 1 #Data receieved does not match given command length
    ERROR_UNSUPPORTED = 2 #Unsupported command
    ERROR_PIXEL_COUNT = 3 #Too many pixels for device

Note: ERROR_PIXEL_COUNT is returned after connecting and configuring a device, waiting for the reboot, and connecting again. The pixel memory allocation is dynamic and happens at reboot. In order to not require a hard coded pixel limit (a value which can change with custom versions of the firmware) the limit is detected on boot. If the requested count is beyond the limit, ERROR_PIXEL_COUNT will be returned upon connect and the device will revert to the default configuration.

⚠️ **GitHub.com Fallback** ⚠️