2024 Linux Instructions (node-hid 3.0.0, async TypeScript)
This project hasn't been updated in five years and didn't work on my Ubuntu 23.10. I was getting some python-related build errors when running npm install. Maybe because Ubuntu uses Python 3 by default, and the old node-hid package versions depend on Python 2.7 for building.
Luckily, this project only has one dependency, https://www.npmjs.com/package/node-hid, and the source-code on here is fairly straight-forward. I was able to start using my Blinkstick Pro again like so:
import { HIDAsync as Device, devicesAsync } from "node-hid"; // [email protected]
const run = async () => {
const devices = await devicesAsync();
const bsDeviceInfo = devices.find(({ product }) => product === "BlinkStick");
if (!bsDeviceInfo) throw new Error("No BlinkStick found");
if (!bsDeviceInfo.path) throw new Error("BlinkStick does not have path");
const bs = await Device.open(bsDeviceInfo.path);
// Set LED at index 0 to red
const red = [255, 0, 0];
const index = 0;
await bs.sendFeatureReport(Buffer.from([5, 0, index, ...red]));
await bs.close();
};
run();
Hope that helps people here to get started!
Some notes from me:
-
node-hidis well typed, so it's easy to explore. - Colors are represented as RGB values with type
[number, number, number], wherenumberis from 0-255 - You mainly interact with the BlinkStick through
sendFeatureReport- A FeatureReport is just a Buffer/Array of numbers
- The first element seems to be some kind of "command" parameter.
5is for setting a LED's color. - The rest is args for the command
- The first arg is called
channelin this repo, but I couldn't figure out what it's for - The second arg is the index of the LED you want to change
- The last three args are an RGB array for the color
- The first arg is called
-
node-hidalso has a synchronous API if you prefer - I only have the BlinkStick Pro so idk if this works for the other products
- Don't be discouraged to look at @arvydas's code in this repo, it should teach you how to do other things
Many thanks for this! It was a big help for me.
Your code works just fine for BlinkStick Nano as well, with the only difference that you have to check for product "BlinkStick Nano". Or maybe better, use startsWith("BlinkStick").
On my BlinkStick Nano, the RGB value has to be at least 3 for a LED to actually light up.
I only have the BlinkStick Pro so idk if this works for the other products
The OG BlinkStick (and, I think, any other single-LED models) doesn’t seem to understand the 5 command, hence this code:
https://github.com/arvydas/blinkstick-node/blob/f9ba968d5eabe6c50123426d5a3174f36e5abf4c/blinkstick.js#L391-L395
If all you need to do is send a single color, the mod to the above code is easy and I think this should work for any model:
- await bs.sendFeatureReport(Buffer.from([5, 0, index, ...red]));
+ await bs.sendFeatureReport(Buffer.from([1, ...red]));
Also, I needed to add this to /etc/udev/rules.d/85-blinkstick.rules to make it work without needing root:
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="20a0", ATTRS{idProduct}=="41e5", MODE:="0666", GROUP="plugdev"
(Mostly copied from blinkstick --add-udev-rule, except that defines it for SUBSYSTEM=="usb". Don’t ask me what the difference is, though.)
@westwood846 @antti5 You may be interested in my fork that uses node-hid@3 by default, and comes with Typescript support.