Reset square using python

While testing my programs it seems I have to remove the blinkstick a lot
from usb port to make it work normal again.

I dont know if it is the python library that is the cause or something else.

Is there a way to reset the square from my python script?

Example of failing execution:
when I leave program below running for more than 10 minutes
4 leds stay purple and only the other 4 keep morphing.

from blinkstick import blinkstick
import time

led = blinkstick.find_first()

led.turn_off()

duration = 10000
led.set_mode(3) # sets all leds at once
time.sleep(1)
try:
    while True:
        led.morph(steps=100, name="red", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="blue", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="green", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="yellow", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="purple", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="orange", duration=duration)
        time.sleep(0.01)
        led.morph(steps=100, name="pink", duration=duration)
        time.sleep(0.01)
except KeyboardInterrupt:
    pass

Hey ddjazz,

regarding your problem I have no idea at the moment. Sometimes HID devices generally needs to be replugged.

But I recommend not to set the mode everytime you start your program. The mode is stored into the EEPROM of the attiny so there is no need to write the mode everytime. Another reason is, that an EEPROM has a write limit. OK, it is about 10000 writes but if you play around a lot or even set the mode on every signal, you could reach that limit and then the last mode will be burned to the memory forever :slight_smile:

Hmmm… I think if Arvy can catch this in his APIs. Means: Before do the set_mode check if this mode is already set and then dont set again…

I agree about the set_mode() function.

However this has nothing to do with the problem i am experiencing.

With the code above i sometimes get connection errrors , sometimes a list index out of range,
and if it runs a few minutes 4 leds stay on the same colors , while other 4 are morphing.

The only fix is to remove the blinkstick from the usb port and connect it again.
highly annoying and almost unusable. Sometimes i have to reinsert it 3 or more times to get rid
of the 4 led problem.

Could support take a look at this please?

System used:
windows 7
python 2.7.9
blinkstick python modules

Tried it again the program quit after 1 minute with following error:

Traceback (most recent call last):
  File "blinkmorph.py", line 21, in <module>
    led.morph(steps=100, name="green", duration=duration)
  File "C:\Python27\lib\site-packages\blinkstick\blinkstick.py", line 713, in mo
rph
    r_start, g_start, b_start = _remap_rgb_value_reverse(self._get_color_rgb(ind
ex), self.max_rgb_value)
  File "C:\Python27\lib\site-packages\blinkstick\blinkstick.py", line 376, in _g
et_color_rgb
    return [device_bytes[1], device_bytes[2], device_bytes[3]]
  File "C:\Python27\lib\UserList.py", line 31, in __getitem__
    def __getitem__(self, i): return self.data[i]
IndexError: list index out of range

Just want to give you the certainty: You are not alone! Normally I don´t do much with python but this evening I had a bit time to test. I´ve got excactly the errors you describe. After a while it gives me the error message “list index out of range”.

Hmmm… It seems to have to do with the windows power management. It only seems to happen if I´m afk for a while… maybe windows reduced or switched of the power somehow.

Please try to switch of the “computer can turn off this device to save power” for your BlinkStick in the power management of the device manager in windows. I will also give this a try…

This doesnt happen when morphing in mode 2 on my square , i dont think it is power management problem.

Hey ddjazz,

I´m still testing. The script is running since an hour without a problem while I´m working on my PC. It must be a problem with the environment and not with the device itself. As I can see it fails to get the color from the device. That means the device is not reachable for a little moment.
I keep on testing and hopefully I find something more that can help you.

I also experienced lost communications in mode 2.
The only fix is to remove the stick and place it again.

I also changed the powermanagement for usb but didnt not improve anything.

Traceback (most recent call last):
  File "blink3.py", line 16, in <module>
    bstick.set_color(0, a, red, green, blue)
  File "C:\Python27\lib\site-packages\blinkstick\blinkstick.py", line 341, in se
t_color
    self._usb_ctrl_transfer(0x20, 0x9, report_id, 0, control_string)
  File "C:\Python27\lib\site-packages\blinkstick\blinkstick.py", line 232, in _u
sb_ctrl_transfer
    raise BlinkStickException("Could not communicate with BlinkStick {0} - it ma
y have been removed".format(self.bs_serial))
blinkstick.blinkstick.BlinkStickException: Could not communicate with BlinkStick
  - it may have been removed

Right, it happens independent from the mode. Sometimes it runs for hours, sometimes the error appears after a few minutes… I have no idea at the moment.

I’ll have to stop experimenting , it’s just unuseable.
I must have abused my usb port already too long
removing and reseating everytime.

I find it odd that noone from support responded to this thread
I cannot recommend blinkstick at the moment and i can not buy
other products until this issue is resolved.

dissappointed at the moment.

Can you tell me the serial number of the device? I need to check the batch and when it was made.

I have square BS001481-3.0 and BS002794-3.0
Both have the problems I described.

Thanks for letting me know. We have slightly updated board design that should solve your problem. Please drop me an email to info at blinkstick dot com with your order number and I’ll post you replacements.