The RGB python code is a bit slow at the time of this writing, but a few tweaks can dramatically speed it up.
First edit ledstrip.py to use the hardware SPI, note the argument use_py_spi = True.
My ledstrip.py was located at /home/pi/RPi-LPD8806/raspledstrip/ledstrip.py
First edit ledstrip.py to use the hardware SPI, note the argument use_py_spi = True.
My ledstrip.py was located at /home/pi/RPi-LPD8806/raspledstrip/ledstrip.py
def __init__(self, leds, use_py_spi = True, dev="/dev/spidev0.0", driver="LPD8806"):
Now inside LPD8806.py, we're going to change the SPI speed to 16MHz.
if self.use_py_spi: import spidev self.spi = spidev.SpiDev() self.spi.open(0,0) self.spi.max_speed_hz = 16000000 print 'py-spidev MHz: %d' % (self.spi.max_speed_hz / 1000000.0 )
That print statement is there just to make sure everything gets set correctly.
One final change to the LPD8806.py file is in the update() function. Every call to self.spi.xfer2() seems to have a 160ms delay at the end, so we're simply going to change the update function so that it calls the spi.xfer2() fewer times.
One final change to the LPD8806.py file is in the update() function. Every call to self.spi.xfer2() seems to have a 160ms delay at the end, so we're simply going to change the update function so that it calls the spi.xfer2() fewer times.
def update(self, buffer): temp_buffer = [] if self.use_py_spi: for x in range(self.leds): temp_buffer = temp_buffer + [i for i in buffer[x]] #self.spi.xfer2([i for i in buffer[x]]) self.spi.xfer2(temp_buffer) self.spi.xfer2([0x00,0x00,0x00]) #zero fill the last to prevent stray colors at the end self.spi.xfer2([0x00]) #once more with feeling - this helps :) time2 = time.time()
If you re-run the example.py python file, you should see a substantial increase in speed.
Page last edited January 12, 2014
Text editor powered by tinymce.