### Install BlinkStick Python Packages Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Control-Remotely Installs necessary packages for the BlinkStick Python example. This includes the 'websocket-client' library for WebSocket communication. ```bash pip install websocket-client ``` -------------------------------- ### Install MQTT and BlinkStick Python Packages Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-MQTT Installs the necessary Python packages, mosquitto for MQTT communication and blinkstick for controlling the BlinkStick device. These are required for both the listener and sender scripts. ```bash sudo pip install mosquitto blinkstick ``` -------------------------------- ### Install psutil Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Display-CPU-usage This command installs the psutil library, which is required to access system and process utilities, including CPU information. ```bash pip install psutil ``` -------------------------------- ### Install BlinkStick Python Package (Windows) Source: https://github.com/arvydas/blinkstick-python/blob/master/README.rst Installs the blinkstick Python package on Windows using the command line. Assumes Python is installed and added to the system PATH. ```bash C:\Python27\Scripts\pip.exe install blinkstick ``` -------------------------------- ### Verify BlinkStick Installation Source: https://github.com/arvydas/blinkstick-python/wiki/NotImplementedError-is_kernel_driver_active-on-some-Linux-systems Executes the BlinkStick command-line tool to display information about connected BlinkStick devices. This command is used to verify that the installation and configuration were successful. ```bash sudo blinkstick --info ``` -------------------------------- ### Install PyUSB (Downgrade) and BlinkStick Python Source: https://github.com/arvydas/blinkstick-python/wiki/NotImplementedError-is_kernel_driver_active-on-some-Linux-systems Installs or downgrades the PyUSB library to version 1.0.0b1 and then installs the BlinkStick Python package. This is a common solution for compatibility issues on Linux. ```bash sudo pip install pyusb==1.0.0b1 sudo pip install blinkstick ``` -------------------------------- ### Uninstall PyUSB and Install Specific Version Source: https://github.com/arvydas/blinkstick-python/wiki/NotImplementedError-is_kernel_driver_active-on-some-Linux-systems Uninstalls the current PyUSB version and then installs version 1.0.0b1. This is a troubleshooting step for existing installations experiencing PyUSB-related errors. ```bash sudo pip uninstall -y pyusb sudo pip install pyusb==1.0.0b1 ``` -------------------------------- ### BlinkStick CLI - Basic Control (Bash) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Provides examples of using the BlinkStick command-line interface for basic operations like displaying device information, setting colors by name or hex value, and turning the device off. ```bash # Display device information blinkstick --info # Set color using color name blinkstick --set-color red blinkstick blue # Set color using hex value blinkstick --set-color "#FF5500" blinkstick FF5500 # Random color blinkstick random # Turn off blinkstick off ``` -------------------------------- ### Listen for BlinkStick Color Commands via MQTT (Python) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-MQTT A Python script that acts as an MQTT client. It connects to a local MQTT broker, subscribes to the 'blinkstick/color' topic, and sets the BlinkStick's color based on the hex color code received in the messages. It requires the mosquitto and blinkstick Python libraries. ```python #!/usr/bin/env python from blinkstick import blinkstick import sys import mosquitto def on_connect(mosq, obj, rc): print("rc: "+str(rc)) def on_message(mosq, obj, msg): sticks[0].set_color(hex="#"+str(msg.payload)) print(msg.topic+" "+str(msg.payload)) def on_publish(mosq, obj, mid): print("mid: "+str(mid)) def on_subscribe(mosq, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def on_log(mosq, obj, level, string): print(string) def main(): global sticks print "BlinkStick MQTT script" print "" sticks = blinkstick.find_all() if len(sticks) == 0: print "BlinkStick not found..." return 64 mqttc = mosquitto.Mosquitto() mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe mqttc.connect("localhost", 1883, 60) mqttc.subscribe("blinkstick/color", 0) rc = 0 while rc == 0: rc = mqttc.loop() return 0 if __name__ == "__main__": sys.exit(main()) ``` -------------------------------- ### Morph Between Colors Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Transitions the BlinkStick's color smoothly between different specified colors. Each `--morph` command initiates a transition to the specified color. ```bash blinkstick --morph red blinkstick --morph green blinkstick --morph blue ``` -------------------------------- ### Untitled No description -------------------------------- ### BlinkStick: Notify New Gmail Emails with Python Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Check-Gmail This Python script fetches your Gmail Atom feed to check for new emails. It uses `urllib` for authentication and `feedparser` to interpret the feed. If new emails are found, the BlinkStick device is set to blink red. Ensure you have the `blinkstick` and `feedparser` libraries installed. Replace 'username' and 'password' with your actual Gmail credentials. ```python import urllib import feedparser from blinkstick import blinkstick username = "username" password = 'password' #No need to edit anything below this line _URL = "https://mail.google.com/gmail/feed/atom" bstick = blinkstick.find_first() #This overriden class will automatically supply username and password for atom URL class my_opener (urllib.FancyURLopener): # Override def get_user_passwd(self, host, realm, clear_cache=0): return (username, password) def auth(): '''The method to do HTTPBasicAuthentication''' opener = my_opener() f = opener.open(_URL) feed = f.read() return feed def readmail(feed): '''Parse the Atom feed and print a summary''' atom = feedparser.parse(feed) print "" print atom.feed.title print "You have %s new mails" % len(atom.entries) if bstick is not None and len(atom.entries) > 0: bstick.blink(name="red") if __name__ == "__main__": f = auth() # Do auth and then get the feed readmail(f) # Let the feed be chewed by feedparser ``` -------------------------------- ### Install BlinkStick Python Package Source: https://github.com/arvydas/blinkstick-python/wiki/locale.Error:-unsupported-locale-setting-when-installing-BlinkStick-Package This command installs the BlinkStick Python library using pip. Ensure your locale settings are correctly configured to avoid installation errors. ```bash sudo pip install blinkstick ``` -------------------------------- ### Send BlinkStick Color Command via MQTT (Command Line) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-MQTT An alternative method to send a color command using the mosquitto_pub command-line tool. This command publishes the hex color code '00ff00' to the 'blinkstick/colour' topic on a local MQTT broker, effectively changing the BlinkStick's color. ```bash mosquitto_pub -h localhost -t blinkstick/colour -m 00ff00 ``` -------------------------------- ### BlinkStick WebSocket Control in Python Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Control-Remotely A Python script that establishes a WebSocket connection to BlinkStick.com to receive color commands. It parses incoming messages, converts HTML color codes to RGB, and sets the BlinkStick's color. Requires the 'blinkstick' and 'websocket-client' libraries. ```python import websocket import json import sys from blinkstick import blinkstick access_code = "change this to AccessCode from BlinkStick.com" bstick = blinkstick.find_first() if bstick is None: sys.exit("BlinkStick not found...") def HTMLColorToRGB(colorstring): """ convert #RRGGBB to an (R, G, B) tuple """ colorstring = colorstring.strip() if colorstring[0] == '#': colorstring = colorstring[1:] if len(colorstring) != 6: raise ValueError("input #%s is not in #RRGGBB format" % colorstring) r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:] r, g, b = [int(n, 16) for n in (r, g, b)] return (r, g, b) def on_message(ws, message): global client_id global access_code global bstick #Uncomment this for debugging purposes #print message m = json.loads(message) if m[0]['channel'] == '/meta/connect': ws.send(json.dumps( {'channel': '/meta/connect', 'clientId': client_id, 'connectionType': 'websocket'})) return elif m[0]['channel'] == '/meta/handshake': client_id = m[0]['clientId'] print ("Acquired clientId: " + client_id) ws.send(json.dumps( {'channel': '/meta/subscribe', 'clientId': client_id, 'subscription': '/devices/' + access_code})) return elif m[0]['channel'] == '/devices/' + access_code: if 'color' in m[0]["data"]: print ("Received color: " + m[0]["data"]["color"]) (r, g, b) = HTMLColorToRGB(m[0]["data"]["color"]) for x in range(0, 8): bstick.set_color(channel=0, index=x, red=r, green=g, blue=b) elif 'status' in m[0]["data"] and m[0]["data"]['status'] == "off": print ("Turn off") bstick.turn_off() elif m[0]['channel'] == '/meta/subscribe': if m[0]['successful']: print ("Subscribed to device. Waiting for color message...") else: print ("Subscription to the device failed. Please check the access_code value in the file.") #Reconnect again and wait for further messages ws.send(json.dumps( {'channel': '/meta/connect', 'clientId': client_id, 'connectionType': 'websocket'})) def on_error(ws, error): print (error) def on_close(ws): print ("### closed ###") def on_open(ws): ws.send(json.dumps( {'channel': '/meta/handshake', 'version': '1.0', 'supportedConnectionTypes': ['long-polling', 'websocket']})) if __name__ == "__main__": # Set this to True for debugging purposes websocket.enableTrace(False) ws = websocket.WebSocketApp("ws://live.blinkstick.com:9292/faye", on_message=on_message, on_error=on_error, on_close=on_close) ws.on_open = on_open ws.run_forever() ``` -------------------------------- ### Access BlinkStick Device Information (Python) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-information-about-BlinkStick This snippet demonstrates how to find all connected BlinkStick devices and print their manufacturer, description, serial number, current color, and two info blocks. It utilizes the blinkstick library. ```python 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() ``` ```python 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()) ``` -------------------------------- ### Removed BlinkStick CLI: BlinkStick.com Connection Command Source: https://github.com/arvydas/blinkstick-python/wiki/Module-Simplification This command was used to connect to BlinkStick.com using an access code via the command-line tool. This functionality has been removed starting with version 1.1. Users are advised to consult tutorials for remote control setups. ```bash blinkstick --connect=ACCESS_CODE ``` -------------------------------- ### Resolve Locale Error During Installation Source: https://github.com/arvydas/blinkstick-python/wiki/locale.Error:-unsupported-locale-setting-when-installing-BlinkStick-Package This command exports the LC_ALL environment variable to 'C', which resolves the 'unsupported locale setting' error during the installation of Python packages. ```bash export LC_ALL=C ``` -------------------------------- ### Send BlinkStick Color Command via MQTT (Python) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-MQTT A simple Python script that connects to a local MQTT broker and publishes a hex color code ('00ff00' for green) to the 'blinkstick/color' topic. This will trigger the listener script to change the BlinkStick's color. It requires the mosquitto Python library. ```python #!/usr/bin/env python import mosquitto mqttc = mosquitto.Mosquitto() mqttc.connect("localhost", 1883, 60) mqttc.publish("blinkstick/color", "00ff00") ``` -------------------------------- ### Set Color by Hex Code using BlinkStick CLI Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Sets a specific color on the BlinkStick using its hexadecimal color code. The hex code should be provided directly after the 'blinkstick' command. ```bash blinkstick 11ab45 ``` -------------------------------- ### Set Random Color using BlinkStick CLI Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Sets a random color for all connected BlinkSticks. This command requires no arguments and directly applies a random color. ```bash blinkstick random ``` -------------------------------- ### Set Color by Name for Specific BlinkStick Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Sets a specific color (e.g., 'blue') for a BlinkStick identified by its serial number. This allows targeting a particular device. ```bash blinkstick --serial BS000001-1.0 blue ``` -------------------------------- ### Set BlinkStick Pro Mode Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Sets the operational mode for a BlinkStick Pro device. Mode 2 typically corresponds to the WS2812 LED mode, required for individual pixel control. ```bash blinkstick --set-mode 2 ``` -------------------------------- ### Add BlinkStick Udev Rule (Linux) Source: https://github.com/arvydas/blinkstick-python/blob/master/README.rst Adds a udev rule to grant user permissions for accessing BlinkStick devices on Linux without requiring root privileges. This is a one-time setup command. ```bash sudo blinkstick --add-udev-rule ``` -------------------------------- ### Get BlinkStick Manufacturer and Description Source: https://context7.com/arvydas/blinkstick-python/llms.txt Retrieves the manufacturer name and product description of the connected BlinkStick device. This information helps in identifying the specific model and its origin. ```python from blinkstick import blinkstick stick = blinkstick.find_first() manufacturer = stick.get_manufacturer() description = stick.get_description() print(f"Manufacturer: {manufacturer}") print(f"Description: {description}") print(f"Full device info: {manufacturer} {description}") ``` -------------------------------- ### Control BlinkStick Pro LEDs with Python Source: https://github.com/arvydas/blinkstick-python/wiki/BlinkStick-Pro:-Run-single-pixel-on-all-LEDs-connected-to-a-channel This Python script utilizes the blinkstick library to control an 8-LED BlinkStick Pro. It randomly selects colors and animates them across the LEDs, fading them on and off. It handles device connection and disconnection gracefully. ```python import time import math import colorsys from random import randint from blinkstick import blinkstick class Main(blinkstick.BlinkStickPro): def run(self): self.send_data_all() red = randint(0, 255) green = randint(0, 255) blue = randint(0, 255) x = 0 sign = 1 try: while True: self.bstick.set_color(0, x, red, green, blue) time.sleep(0.02) self.bstick.set_color(0, x, 0, 0, 0) time.sleep(0.004) x += sign if x == self.r_led_count - 1: sign = -1 red = randint(0, 255) green = randint(0, 255) blue = randint(0, 255) elif x == 0: sign = 1 except KeyboardInterrupt: self.off() return # Change the number of LEDs for r_led_count main = Main(r_led_count=8, max_rgb_value=128) if main.connect(): main.run() else: print "No BlinkSticks found" ``` -------------------------------- ### Python Clock Visualization for BlinkStick Pro Source: https://github.com/arvydas/blinkstick-python/wiki/BlinkStick-Pro:-Display-analogue-clock-on-16-LED-ring This Python script uses the blinkstick-python library to display the current time on a BlinkStick Pro, mapping hours, minutes, and seconds to different LED positions and colors. It requires an Adafruit NeoPixel ring. The script continuously updates the display every 0.1 seconds until interrupted. ```python from datetime import datetime import time import math import colorsys from blinkstick import blinkstick class Main(blinkstick.BlinkStickPro): def run(self): self.off() try: while (True): self.clear() t = datetime.now() hour = t.time().hour minute = t.time().minute second = t.time().second hour_pos = 15 - int((hour / 24.0) * 16) minute_pos = 15 - int((minute / 60.0) * 16) second_pos = 15 - int((second / 60.0) * 16) self.set_color_or(hour_pos, 255, 0, 0) self.set_color_or(minute_pos, 0, 255, 0) self.set_color_or(second_pos, 0, 0, 255) self.send_data_all() time.sleep(0.1) except KeyboardInterrupt: self.off() return def set_color_or(self, x, r, g, b): cr, cg, cb = self.get_color(0, x) self.set_color(0, x, int(r) | int(cr), int(g) | int(cg), int(b) | int(cb)) main = Main(r_led_count=16) if main.connect(): main.run() else: print "No BlinkSticks found" print "exit" ``` -------------------------------- ### Untitled No description -------------------------------- ### Set BlinkStick Color via Command Line Source: https://github.com/arvydas/blinkstick-python/blob/master/README.rst A command-line utility to control BlinkStick devices, demonstrated here by setting a pulse effect to red. This tool is installed alongside the Python package. ```bash blinkstick --pulse red ``` -------------------------------- ### Display CPU Usage with BlinkStick (Python) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Display-CPU-usage This Python script continuously monitors CPU usage using psutil and sets the BlinkStick LED color accordingly. Green indicates low CPU usage (0%), amber signifies moderate usage (50%), and red represents high usage (100%). The script requires a BlinkStick device to be connected. ```python from blinkstick import blinkstick import psutil bstick = blinkstick.find_first() if bstick is None: print ("No BlinkSticks found...") else: print ("Displaying CPU usage (Green = 0%, Amber = 50%, Red = 100%)") print ("Press Ctrl+C to exit") #go into a forever loop while True: cpu = psutil.cpu_percent(interval=1) intensity = int(255 * cpu / 100) bstick.set_color(red=intensity, green=255 - intensity, blue=0) ``` -------------------------------- ### Get Current BlinkStick LED Color (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt This code retrieves the current color of a BlinkStick LED using the get_color() method. It shows how to get the color as an RGB tuple or a hexadecimal string, and also how to read the color of a specific LED on BlinkStick Pro devices. ```python from blinkstick import blinkstick stick = blinkstick.find_first() # Set a color first stick.set_color(name="skyblue") # Get color as RGB tuple r, g, b = stick.get_color() print(f"Current color RGB: ({r}, {g}, {b})") # Get color as hex string hex_color = stick.get_color(color_format='hex') print(f"Current color HEX: {hex_color}") # Get color of specific LED on BlinkStick Pro r, g, b = stick.get_color(index=3) print(f"LED 3 color: RGB({r}, {g}, {b})") ``` -------------------------------- ### Blink Color Multiple Times Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Blinks a specified color a certain number of times. The `--repeats` option controls the number of blinks, and the color is provided as an argument. ```bash blinkstick --repeats 2 --blink red ``` -------------------------------- ### Pulse Color Multiple Times Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Pulses a specified color a certain number of times. Similar to blinking, the `--repeats` option controls the duration or number of pulses. ```bash blinkstick --repeats 2 --pulse green ``` -------------------------------- ### Find BlinkStick Device by Serial Number (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt This example shows how to locate a specific BlinkStick device using its unique serial number with the find_by_serial() function. It then attempts to set the color of the found device. ```python from blinkstick import blinkstick # Connect to a specific BlinkStick by serial number serial = "BS012345-1.0" stick = blinkstick.find_by_serial(serial=serial) if stick: print(f"Found device: {stick.get_manufacturer()} - {stick.get_description()}") stick.set_color(name="purple") else: print(f"Device with serial {serial} not found") ``` -------------------------------- ### Control Individual Pixels on BlinkStick Pro Source: https://github.com/arvydas/blinkstick-python/wiki/Command-line-tool-usage-examples Sets the color of an individual LED connected to a BlinkStick Pro. This requires the device to be in WS2812 mode. The `--channel`, `--index`, and color arguments specify the target LED and its color. ```bash blinkstick --channel 0 --index 5 red ``` -------------------------------- ### BlinkStick Internet Connectivity Check (Python) Source: https://github.com/arvydas/blinkstick-python/wiki/Example:-Display-Internet-connectivity-status This Python script utilizes the BlinkStick library and the socket module to check for internet connectivity. It defines a function `internet_connected` that attempts to connect to Google's DNS server (8.8.8.8) on port 53. If successful, it returns True, indicating the internet is up. The main loop continuously checks this status and controls the BlinkStick's LED color (green for connected, pulsing red for disconnected). It requires the `blinkstick` library to be installed. ```python import socket import time from blinkstick import blinkstick """ This functions checks connection to Google DNS server If DNS server is reachable on port 53, then it means that the internet is up and running """ def internet_connected(host="8.8.8.8", port=53): """ Host: 8.8.8.8 (google-public-dns-a.google.com) OpenPort: 53/tcp Service: domain (DNS/TCP) """ try: socket.setdefaulttimeout(1) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except Exception as ex: pass return False # Find first BlinkStick led = blinkstick.find_first() # Can't do anything if BlinkStick is not connected if led is None: print "BlinkStick not found...\r\nExiting..." else: try: # Store value of last state in this variable connected = False while (True): if internet_connected(): # If previously internet was disconnected, then print message # and set BlinkStick to green if not connected: print "Internet is up!" connected = True led.set_color(name="green") # Wait for 1 second before checking for internet connectivity time.sleep(1) else: # If previously internet connected, then print message if connected: print "Internet is down..." connected = False # BlinkStick pulse API call lasts for 1 second so this acts # as delay before next check for internet is performed led.pulse(name="red") except KeyboardInterrupt: print "Exiting... Bye!" led.turn_off() ``` -------------------------------- ### Removed BlinkStick CLI: CPU Usage Command Source: https://github.com/arvydas/blinkstick-python/wiki/Module-Simplification This command was previously used to display CPU usage via the BlinkStick command-line tool. It has been removed starting with version 1.1. Users should refer to external tutorials for alternative methods. ```bash blinkstick --cpu-usage ``` -------------------------------- ### Get BlinkStick Device Serial Number Source: https://context7.com/arvydas/blinkstick-python/llms.txt Retrieves the unique serial number of the connected BlinkStick device. The serial number is returned in the format BSnnnnnn-X.Y and can be parsed to extract device ID and software version. ```python from blinkstick import blinkstick stick = blinkstick.find_first() serial = stick.get_serial() print(f"Device Serial: {serial}") # Extract version information parts = serial.split('-') if len(parts) == 2: device_id = parts[0] version = parts[1] print(f"Device ID: {device_id}") print(f"Software Version: {version}") ``` -------------------------------- ### Get BlinkStick Device Variant Type Source: https://context7.com/arvydas/blinkstick-python/llms.txt Obtains the device type of the BlinkStick, either as an integer constant (e.g., BLINKSTICK_PRO) or a human-readable string. This information can be used to determine device capabilities and apply specific configurations. ```python from blinkstick import blinkstick stick = blinkstick.find_first() # Get variant as integer constant variant = stick.get_variant() print(f"Variant code: {variant}") # Get variant as readable string variant_name = stick.get_variant_string() print(f"Device type: {variant_name}") # Check device capabilities based on variant if variant == blinkstick.BlinkStick.BLINKSTICK_PRO: print("This device supports multiple channels and addressable LEDs") stick.set_mode(2) # Enable WS2812 mode elif variant == blinkstick.BlinkStick.BLINKSTICK: print("This is a standard BlinkStick with single LED") ``` -------------------------------- ### Create Blink Effect on BlinkStick LED (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt This code creates a blinking effect on a BlinkStick LED using the blink() method. It shows how to specify color (RGB, hex, name), number of repetitions, and delay between blinks. It also includes an example for blinking a specific LED on BlinkStick Pro. ```python from blinkstick import blinkstick stick = blinkstick.find_first() # Blink red 5 times with 500ms delaystick.blink(red=255, green=0, blue=0, repeats=5, delay=500) # Blink using color name with custom timingstick.blink(name="blue", repeats=10, delay=250) # Blink specific LED on BlinkStick Prostick.blink(channel=0, index=3, hex="#00FF00", repeats=3, delay=1000) ``` -------------------------------- ### BlinkStick CLI - Device Mode and Info Blocks (Bash) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Illustrates setting the device mode on BlinkStick Pro and updating the info blocks via the command line. Also includes instructions for adding udev rules on Linux. ```bash # Set device mode (BlinkStick Pro) blinkstick --set-mode 2 # Set info blocks blinkstick --set-infoblock1 "Living Room" blinkstick --set-infoblock2 "Entertainment Center" # Add udev rule for Linux (run as root) sudo blinkstick --add-udev-rule ``` -------------------------------- ### Control Addressable LEDs with BlinkStickPro (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Shows how to initialize and control addressable LED strips connected to a BlinkStick Pro. It covers setting individual LED colors in a buffer and sending the data to the device. Requires the BlinkStickPro class. ```python from blinkstick import blinkstick # Initialize for 8 LEDs on R channel, 8 on G channel pro = blinkstick.BlinkStickPro(r_led_count=8, g_led_count=8, b_led_count=0) # Connect to device if pro.connect(): # Set individual LED colors in buffer pro.set_color(channel=0, index=0, r=255, g=0, b=0) pro.set_color(channel=0, index=1, r=255, g=128, b=0) pro.set_color(channel=0, index=2, r=255, g=255, b=0) # Send buffer to channel 0 (R pin) pro.send_data(0) # Or send to all channels at once pro.send_data_all() # Turn off all LEDs pro.off() ``` -------------------------------- ### BlinkStick CLI - Animations (Bash) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Demonstrates how to use the BlinkStick CLI to create animations such as blinking, pulsing, and morphing effects. Includes parameters for repeats, delay, and duration. ```bash # Blink red 10 times with 250ms delay blinkstick --blink --set-color red --repeats 10 --delay 250 # Pulse green smoothly 3 times over 2 seconds each blinkstick --pulse --set-color green --repeats 3 --duration 2000 # Morph to blue over 1.5 seconds blinkstick --morph --set-color blue --duration 1500 ``` -------------------------------- ### Set and Read Device Info Blocks (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Demonstrates how to set and read information stored in the first two info blocks of a BlinkStick device using Python. This is useful for identifying devices or storing metadata. ```python # Set device name in info block 1 stick.set_info_block1("Office Desk") # Set location or other info in info block 2 stick.set_info_block2("Room 42") # Read back the information name = stick.get_info_block1() location = stick.get_info_block2() print(f"Device name: {name}") print(f"Location: {location}") ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Control LED Matrices with BlinkStickProMatrix (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Illustrates how to control LED matrices connected to a BlinkStick Pro using coordinate-based methods. Includes drawing shapes, numbers, and shifting the matrix. Requires the BlinkStickProMatrix class. ```python from blinkstick import blinkstick # Initialize 8x8 matrix on R channel, 8x8 on G channel matrix = blinkstick.BlinkStickProMatrix(r_columns=8, r_rows=8, g_columns=8, g_rows=8) if matrix.connect(): # Draw using x, y coordinates matrix.set_color(x=0, y=0, r=255, g=0, b=0) matrix.set_color(x=15, y=7, r=0, g=255, b=0) # Draw a line matrix.line(x1=0, y1=0, x2=7, y2=7, r=255, g=255, b=0) # Draw a rectangle matrix.rectangle(x1=2, y1=2, x2=5, y2=5, r=0, g=255, b=255) # Render a number matrix.number(x=10, y=1, n=5, r=255, g=0, b=0) # Send to device matrix.send_data_all() # Shift entire matrix left matrix.shift_left(remove=False) matrix.send_data_all() ``` -------------------------------- ### BlinkStick CLI - Specific Device and Settings (Bash) Source: https://context7.com/arvydas/blinkstick-python/llms.txt Shows how to control a specific BlinkStick device using its serial number, set brightness, control individual LEDs on BlinkStick Pro, and apply inverse mode. ```bash # Control specific device by serial blinkstick --serial BS012345-1.0 --set-color purple # Set brightness to 50% blinkstick --brightness 50 --set-color white # Control specific LED on BlinkStick Pro blinkstick --channel 0 --index 5 --set-color cyan # Set inverse mode blinkstick --inverse --set-color red ``` -------------------------------- ### Device Discovery API Source: https://context7.com/arvydas/blinkstick-python/llms.txt Functions to find and connect to BlinkStick devices connected to the system. ```APIDOC ## find_first() ### Description Returns the first BlinkStick device found connected to the system, or None if no devices are available. ### Method `find_first()` ### Endpoint N/A (Python library function) ### Parameters None ### Request Example ```python from blinkstick import blinkstick stick = blinkstick.find_first() if stick is None: print("No BlinkStick devices found") else: print(f"Connected to: {stick.get_serial()}") stick.set_color(red=255, green=0, blue=0) ``` ### Response #### Success Response - **stick** (object) - A BlinkStick device object if found, otherwise None. #### Response Example ```json // If found: // BlinkStick device object // If not found: null ``` ``` ```APIDOC ## find_all() ### Description Returns a list of all BlinkStick devices connected to the system. ### Method `find_all()` ### Endpoint N/A (Python library function) ### Parameters None ### Request Example ```python from blinkstick import blinkstick sticks = blinkstick.find_all() print(f"Found {len(sticks)} BlinkStick device(s)") colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] for i, stick in enumerate(sticks): color = colors[i % len(colors)] stick.set_color(red=color[0], green=color[1], blue=color[2]) print(f"Device {i+1}: {stick.get_serial()} - Color set to RGB{color}") ``` ### Response #### Success Response - **sticks** (list) - A list of BlinkStick device objects. #### Response Example ```json [ // BlinkStick device object 1, // BlinkStick device object 2, ... ] ``` ``` ```APIDOC ## find_by_serial(serial: str) ### Description Locates a specific BlinkStick device using its unique serial number. ### Method `find_by_serial(serial: str)` ### Endpoint N/A (Python library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from blinkstick import blinkstick serial = "BS012345-1.0" stick = blinkstick.find_by_serial(serial=serial) if stick: print(f"Found device: {stick.get_manufacturer()} - {stick.get_description()}") stick.set_color(name="purple") else: print(f"Device with serial {serial} not found") ``` ### Response #### Success Response - **stick** (object) - A BlinkStick device object if found, otherwise None. #### Response Example ```json // If found: // BlinkStick device object // If not found: null ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Find and Connect to First BlinkStick Device (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt This snippet demonstrates how to find and connect to the first available BlinkStick device using the blinkstick.find_first() function. It checks if a device was found and then sets its color to red. ```python from blinkstick import blinkstick # Find and connect to the first BlinkStick device stick = blinkstick.find_first() if stick is None: print("No BlinkStick devices found") else: print(f"Connected to: {stick.get_serial()}") # Set color to red stick.set_color(red=255, green=0, blue=0) ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Manual BlinkStick Udev Rule Addition (Linux) Source: https://github.com/arvydas/blinkstick-python/blob/master/README.rst Manually adds a udev rule for BlinkStick devices on Linux by echoing the rule configuration to the appropriate system file. This achieves the same outcome as the --add-udev-rule command. ```bash echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"20a0\", ATTR{idProduct}==\"41e5\", MODE:=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick.rules ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Find All Connected BlinkStick Devices (Python) Source: https://context7.com/arvydas/blinkstick-python/llms.txt This code finds all connected BlinkStick devices using blinkstick.find_all() and iterates through them to set different colors. It handles cases where multiple devices are connected and cycles through a predefined list of colors. ```python from blinkstick import blinkstick # Find all connected BlinkStick devices sticks = blinkstick.find_all() print(f"Found {len(sticks)} BlinkStick device(s)") # Set different colors on each device colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] for i, stick in enumerate(sticks): color = colors[i % len(colors)] stick.set_color(red=color[0], green=color[1], blue=color[2]) print(f"Device {i+1}: {stick.get_serial()} - Color set to RGB{color}") ```