Hey everybody,
i started some nice “knightrider” python script on a raspi with a BlinkStick Strip.
counter = 0
direction = 1
while True:
for bstick in blicks:
bstick.set_color(channel=0, index=counter, name="black")
time.sleep(0.003) #<----- You need to add this to wait for black color to be sent to the LEDs
counter = counter+direction
if counter == 7:
direction = -1
if counter == 0:
direction = 1
for bstick in blicks:
bstick.set_color(channel=0, index=counter, name="green")
time.sleep(0.2)
But after 1 min it crashed.
pi@raspberrypi:~/boot $ sudo python Blinkstick.py Knightrider
Traceback (most recent call last):
File "Blinkstick.py", line 59, in <module>
bstick.set_color(channel=0, index=counter, name="black")
File "/usr/local/lib/python2.7/dist-packages/blinkstick/blinkstick.py", line 341, in set_color
self._usb_ctrl_transfer(0x20, 0x9, report_id, 0, control_string)
File "/usr/local/lib/python2.7/dist-packages/blinkstick/blinkstick.py", line 244, in _usb_ctrl_transfer
return self.device.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, data_or_wLength)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 711, in ctrl_transfer
self.__get_timeout(timeout)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 836, in ctrl_transfer
timeout))
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py", line 571, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
Could you please do a lsusb -v -d 20a0:41e5 and post the result here? Do it once before the crash and once after the crash please. Is it always excactly 1 minute?
btw, i´ve allowed myself to change your code a bit
import time
from blinkstick import blinkstick
blicks = blinkstick.find_all()
counter = 0
direction = 1
while True:
for bstick in blicks:
bstick.set_color(channel=0, index=counter, name="black")
time.sleep(0.020) #<----- You need to add this to wait for black color to be sent to the LEDs
counter = counter+direction
if counter == 7:
direction = -1
if counter == 0:
direction = 1
for bstick in blicks:
bstick.set_color(channel=0, index=counter, name="red")
time.sleep(0.08)
It runs a bit smoother and has the KnightRider Red now!
Edit 02.08.2016: Correction of the delay after the set_color from 0.003 to 0.020
Ah man, should have seen that. @b_cyranka: You always need a 20ms delay between every signals sending to your Blinkstick(s).
For your last code you´ve send: Do that delay also in your loop getting every Blinkstick. If you have only one Blinkstick connected you could do a
I would recommend the first option, but if the second option works then you should be ok. The delay is required only when you set the colors of the LEDs, because BlinkStick needs to send them and can’t communicate while it’s sending data to the LEDs.
I am still getting that error even with a 200 ms delay. In fact, it is pretty absurd - this doesn’t work even with a 200 ms delay (it does work with 300 ms):
val = 0
for i in range(100):
val = val + 1
for stick in sticks:
for led in range(0, 8):
stick.set_color(0, led, val, val, val)
time.sleep(0.200)
but this works (even with only 20 ms):
val = 100
for i in range(100):
for stick in sticks:
for led in range(0, 8):
stick.set_color(0, led, val, val, val)
time.sleep(0.020)