So this is a lot of coding but since the actual topic is about the hardware that I'm playing with I figured it belongs here .
I wanted to have little lights on my desk that I could control with scripts for various reasons. Say someone tags me in IRC then I would want it to flash blue. After lurking on Google for an hour or so I stumbled upon this site https://www.blinkstick.com/. It's a small device with integrated LEDs and built-in firmware. The most simple setup is one chip connected via USB to your computer, which can then be controlled via CLI or script. I ordered one unit together with a little plastic cube that you can put the device in to get a cool flashing cube. Much fancier.
There's very good documentation on their site but I will go through what I did since I had to do a few extra steps to make it work.
Setup for Linux
And that's it. After this the below can be run without root privs.sudo pip install blinkstick
apt install python-is-python3 (probably optional)
chmod +x
Open /usr/local/bin/blinkstick in vim then do :set ff=unix and :wq
sudo blinkstick --add-udev-rule (Probably need to restart after this)
Code: Select all
from blinkstick import blinkstick
for bstick in blinkstick.find_all():
print ("Found device:")
print (" Manufacturer: " + bstick.get_manufacturer())
print (" Description: " + bstick.get_description())
print (" Serial: " + bstick.get_serial())
print (" Current Color: " + bstick.get_color(color_format="hex"))
print (" Info Block 1: " + bstick.get_info_block1())
print (" Info Block 2: " + bstick.get_info_block2())
while True:
for bstick in blinkstick.find_all():
bstick.set_random_color()
print (bstick.get_serial() + " " + bstick.get_color(color_format="hex"))
time.sleep(5)
The code can be changed to catch the exception and simply try again, which temporarily solves the problem.Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/blinkstick/blinkstick.py", line 249, in _usb_ctrl_transfer
return self.device.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, data_or_wLength)
File "/usr/lib/python3/dist-packages/usb/core.py", line 1036, in ctrl_transfer
ret = self._ctx.backend.ctrl_transfer(
File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 875, in ctrl_transfer
ret = _check(self.lib.libusb_control_transfer(
File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bl.py", line 36, in <module>
bstick.set_random_color()
File "/usr/local/lib/python3.8/dist-packages/blinkstick/blinkstick.py", line 696, in set_random_color
self.set_color(name="random")
File "/usr/local/lib/python3.8/dist-packages/blinkstick/blinkstick.py", line 410, in set_color
self._usb_ctrl_transfer(0x20, 0x9, report_id, 0, control_string)
File "/usr/local/lib/python3.8/dist-packages/blinkstick/blinkstick.py", line 255, in _usb_ctrl_transfer
return self.device.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, data_or_wLength)
File "/usr/lib/python3/dist-packages/usb/core.py", line 1036, in ctrl_transfer
ret = self._ctx.backend.ctrl_transfer(
File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 875, in ctrl_transfer
ret = _check(self.lib.libusb_control_transfer(
File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error
Code: Select all
from blinkstick import blinkstick
import time
for bstick in blinkstick.find_all():
print ("Found device:")
print (" Manufacturer: " + bstick.get_manufacturer())
print (" Description: " + bstick.get_description())
print (" Serial: " + bstick.get_serial())
print (" Current Color: " + bstick.get_color(color_format="hex"))
print (" Info Block 1: " + bstick.get_info_block1())
print (" Info Block 2: " + bstick.get_info_block2())
while True:
try:
for bstick in blinkstick.find_all():
bstick.set_random_color()
print (bstick.get_serial() + " " + bstick.get_color(color_format="hex"))
except e:
time.sleep(1)
time.sleep(5)
https://www.blinkstick.com/help/api-implementations
https://arvydas.github.io/blinkstick-python/
That's about it . Will post some more later for what I decide to use it for. The first project I want to use it with is a script that will use it together with an alarm sound to notify me when the script throws an error .