Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue running LEDPOV script with Neopixel
#1
Hi,

I'm having some trouble running the LEDPOV example script from the POVStick project using a strip of Neopixels (144 LED/m), AllPixel and Raspberry Pi.
(I've successfully run AllPixelStripTest.py and changed the RGB channel order accordingly)

The only changes I've made to the example script are with the driver, number of LEDs, and channel order.
Code:
from bibliopixel.led import *
import bibliopixel.image as img
from bibliopixel.drivers.serial_driver import *
import bibliopixel.gamma as gamma

#Takes a matrix and displays it as individual columns over time
class LEDPOV(LEDMatrix):

   def __init__(self, driver, povHeight, width, rotation = MatrixRotation.ROTATE_0, vert_flip = False):
       self.numLEDs = povHeight * width

       super(LEDPOV, self).__init__(driver, width, povHeight, None, rotation, vert_flip, False)
   
   #This is the magic. Overriding the normal update() method
   #It will automatically break up the frame into columns spread over frameTime (ms)    
   def update(self, frameTime = None):
       if frameTime:
           self._frameTotalTime = frameTime

       sleep = None
       if self._frameTotalTime:
           sleep = (self._frameTotalTime - self._frameGenTime) / self.width

       width = self.width
       for h in range(width):
           start = time.time() * 1000.0

           buf = [item for sublist in [self.buffer[(width*i*3)+(h*3):(width*i*3)+(h*3)+(3)] for i in range(self.height)] for item in sublist]
           self.driver.update(buf)
           sendTime = (time.time() * 1000.0) - start
           if sleep:
               time.sleep(max(0, (sleep - sendTime) / 1000.0))

#convert 6 character hex colors to RGB tuple
def hex2rgb(hex):
   """Helper for converting RGB and RGBA hex values to Color"""
   hex = hex.strip('#')
   if len(hex) == 6:
       split = (hex[0:2],hex[2:4],hex[4:6])
   else:
       raise ValueError('Must pass in either a 6 character hex value!')

   r, g, b = [int(x, 16) for x in split]

   return (r, g, b)

argv = sys.argv
argc = len(argv)

file = ""
bright = 100
col_time = 50
bgcolor = (0,0,0)

#load in command line args
if argc > 1:
   file = argv[1]
else:
   print "Must specifiy an input file!"
   sys.exit(2)

#get brightness value
if argc > 2:
   bright = int(x=argv[2])

#col_time is time to display each vertical line for, in ms
if argc > 3:
   col_time = int(argv[3])

#bgcolor is the color that will be used on transparent pixels
if argc > 4:
   bgcolor = hex2rgb(argv[4])

#open the file so it is not loaded each time through
i = img.Image.open(file)

img_width = i.size[0]
totalFrameTime = img_width * col_time

print "Image Display Time: {0:.1f}s".format(totalFrameTime/1000.0)

driver = DriverSerial(LEDTYPE.NEOPIXEL, num = 144, c_order=ChannelOrder.GRB, gamma=gamma.NEOPIXEL)

#automatically configure matrix width to image width.
#change povHeight to match your setup
led = LEDPOV(driver, povHeight = 144, width = img_width, rotation=MatrixRotation.ROTATE_0, vert_flip=True)
led.setMasterBrightness(bright)

img.showImage(led, imageObj = i, bgcolor=bgcolor)

try:
   while True:
       led.update(frameTime=totalFrameTime)
except KeyboardInterrupt:
   led.all_off()
   led.update()

Here's the error I'm getting:

pi@raspberrypi ~ $ python POVStick-example.py TSX-144.jpg 64 100
Image Display Time: 21.6s
INFO - serial_driver - Using COM Port: /dev/ttyACM0, Device ID: 0, Device Ver: 0
Traceback (most recent call last):
  File "POVStick-example.py", line 93, in <module>
    led.update(frameTime=totalFrameTime)
  File "POVStick-example.py", line 29, in update
    self.driver.update(buf)
AttributeError: 'list' object has no attribute 'update'


Any suggestions?
#2
Ahh... uh oh. BiblioPixel 2.x broke LEDPOV.

So... for one, LEDPOV is now built into BiblioPixel.... but it looks like it's broken in there too.

You need to change this line:
self.driver.update(buf)

To:
self.driver[0].update(buf)

I've fixed it in the master branch of the BiblioPixel github repo (https://github.com/ManiacalLabs/BiblioPixel) but not in the version you can install from pip. So I would just modify your script for now... at least until I can can test and release a new version officially.
#3
Thumbs Up 
Yep, that did the trick. [Image: thumbsup.png] Thanks so much!
#4
FYI, fixed in latest release.
#5
Awesome. Thanks for letting me know!


Forum Jump:


Users browsing this thread: 1 Guest(s)