Python Pipe Error


#1

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

Is this a code problem or some libUsb deep …


#2

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 :wink:

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! :smile:

Edit 02.08.2016: Correction of the delay after the set_color from 0.003 to 0.020


#3

It crashs not always after 1 min. The time is vary. Somethime it crashs fast sometimes it crash after 20 min.

After reboot:

pi@raspberrypi ~ $ lsusb -v -d 20a0:41e5
Bus 001 Device 005: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

Bus 001 Device 006: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

When it runs:

pi@raspberrypi ~ $ lsusb -v -d 20a0:41e5
Bus 001 Device 005: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

Bus 001 Device 006: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

After a crash:

pi@raspberrypi ~/Shervin/scratch/Controller $ lsusb -v -d 20a0:41e5
Bus 001 Device 099: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

Bus 001 Device 097: ID 20a0:41e5 Clay Logic
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x20a0 Clay Logic
  idProduct          0x41e5
  bcdDevice            2.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               40mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      96
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             100

And no worries about the changes. :sunglasses:


#4

When I run this code:

import time
from blinkstick import blinkstick

blicks = blinkstick.find_all()

while True:
		for bstick in bsticks:
			print bstick.get_serial()

It crashs in the first min.
Maybe i send to many commands?


#5

In the example changed by @p0ke please change this line:

time.sleep(0.003) #<----- You need to add this to wait for black color to be sent to the LEDs

to

time.sleep(0.020) #<----- You need to add this to wait for black color to be sent to the LEDs

And let me know if this fixes your issue.


#6

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

blinkstick.find_first()

instead

blinkstick.find_all()

#7

I need 20ms delay after I send a command to the blink stick?
For my project i need two sticks…

question:
20ms for each stick?

for bstick in blicks:
	bstick.set_color(channel=0, index=counter, name="red")
	time.sleep(0.020) 

or
20ms after I send the two commands to the blink sticks.

for bstick in blicks:
	bstick.set_color(channel=0, index=counter, name="red")

time.sleep(0.020)

#8

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.


#10

Thx for your help. :grin:


#11

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)

(can’t seem to get indentation right)


#12

Tested it, works as expected. Can´t see any error even with 20 ms.


#13

And now I can’t replicate the issue either. I have rebooted the machine, I wonder if the USB subsystem was in a funky state.