npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ws281x-spi

v1.3.0

Published

Allows controlling WS281x LEDs over SPI on SBCs like Pine64

Downloads

5

Readme

WS281x-spi

Allows controlling WS281x LEDs over SPI pin on single board computers like Pine64 or Raspberry Pi.


Installation

npm i ws281x-spi

Usage

The node proccess needs to run as root to be able to access to SPI.

Example code on Pine64:

const Strip = require("ws2812-spi");

// 8 LEDs, Bus index 1, Device index 0
const strip = new Strip(8, 1, 0);

// Set all LEDs to red color
strip.data.fill(0xff0000);

// Send the change to the LEDs
strip.render();

// After 1 second, turn off the strip and exit
setTimeout(_ => strip.destroy(), 1000);

API

new WS281xSPI() - Constructor

Parameters:

  • nPixels (Integer) - Number of LEDs you have (default: 256)
  • bus (Integer) - Index of the bus to use (1 on Pine64, 0 on RPi) (default: 0)
  • device (Integer) - Index of the device on the bus to use (default: 0)
  • grb (Boolean) - True if your LEDs use GRB (default), or false if RGB

.data - Parameter defining the color of each individual pixel

Must be either:

  • Uint32Array of values that form 0xRRGGBB in hexadecimal form. (eg. 0xff0000 is red)
  • Array with values that the library color can understand. (Basically any CSS representation of color and more) (eg. "#ff0000", "red", {r: 255, g: 0, b: 0}, [255, 0, 0] or "hsl(0deg, 100%, 50%)", see the library's documentation for reference)

.render() - Send the current data to the LED strip

You can optionally pass a object similar to .data defined above that will replace the values in current .data before rendering.
Parameters:

  • data Uint32Array or Array - Optional data to replace current data with. (explained above)

.destroy() - Close the SPI communication and optionally turn off the LEDs

After the method is called, the instance is no longer usable. SPI communication is closed and reference to .data is dropped.
It's a good idea to call this method before exitting the node process. Parameters:

  • black Boolean - True if the LEDs should be turned off (set black color) before destroing, false will keep the LEDs as they are

Support

If you successfully run this on a setup not listed here, feel free to share with me in issues, as well as your achievements with and thoughts about this library.

The following has been tested to be functional:

SBCs

LEDs

  • WS2812b

Troubleshooting

Error: EMSGSIZE, Message too long

If you get this message, it means you have too many LEDs.
Messages are limited my SPI's bufsize, which is 4096 by default (approx. 32 LEDs).


License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See https://www.gnu.org/licenses/.

Author

Adam "Zhincore" Žingor - zhincore.eu