a node.js library to control a SPI led driver (p.e adafruit leddriver) with your Raspberry Pi
This is a node.js library to control a SPI led driver.
I wrote this to control my Adafruit 24-Channel 12-bit PWM LED Driver using the TLC5947 with my Raspberry Pi. This should also work with different SPI devices or host systems but my examples referr to this configuration. It could also be used for other PWM modules like motor controls etc.
npm install leddriver
var LEDDRIVER = require"leddriver";var driver = 24 12;
number of channelsyour leddriver has
bits per channelof your leddriver
/dev/spidev0.0as defined in node-simplespi )
number of channels- 1)
This example sets the value of channel 5 to 500. The maximum allowed value depends on the
bits per channel of your device. Since I am using a 12bit SPI device it has 3 hexadecimal digits per channel ("000" to "FFF"). In decimal this is a value between 0 and 4095.
number of channels- 1)
This example sets the value of channel 5 to 0.2 * maximum value. In my 12bit example this has exactly the same result like the first example (0.2 * 4095 = 819) but it is far easier to use like this.
This updates your led driver by sending the values.
var LEDDRIVER = require"leddriver";var driver = 24 12;driverpset0 1;driverpset1 0;driverpset2 1;driversend;setTimeoutdriverpset0 0.5;driverpset1 0.5;driverpset2 0.5;driversend;5000;
When running this example the LEDs connected to channel 0 and 2 should be fully turned on while channel 1 is off. After 5 seconds all the LEDs go to half brightness.
The library also includes a helper for setting RGB-LEDs to a color defined in csslike hex style:
driversetRGB"#e010ff" 0 1 2;
When driving with MOSFETS like discussed in the adafruit Forums you should invert (1=0, 0=1) your output. You can turn on inversion of setRGB:
thx @ jnovack
Connect your Pi like this to the LED driver:
|Raspberry Pi||led driver|
|5V or 3.3V (or external)||input V+|
/OE on the LED driver to
GND or to a GPIO of your choice (you can quickly turn off all LEDs by using a GPIO).
The SPI interface requires root access on the Raspberry Pi. Run your app with
For more details on getting SPI to run see node-simplespi!
I am not responsible for any damages to your hardware. Use this at your own risk.