NeoPixel (WS2812-based) digital RGB LED strip are very popular as they are affordable and easy to use. These are driven from only one wire, which is very convenient. Unfortunately for C.H.I.P users, as there is no clock line, it requires more or less precise timing requirements. It is very easy to drive them using microcontrollers, but difficult using a full-fledged operating system.
It doesn't look that bad in the Pi land but there is no driver on the C.H.I.P yet. While it may be attainable using DMA, our best bet to drive a LED strip from a C.H.I.P is to use a 2-wire interface alternative: the DotStar APA102. These are available in various formats, including micro 2020 SMD. They can be controlled from a standard SPI interface using SCLK for clock and MOSI for data.
There is a pure Python library to control it from a Raspberry Pi. With a few tweaks, we can will make it work on the C.H.I.P. On C.H.I.P, SPI support is not enabled by default, but spi module is now part of the standard kernel so you don't have to compile your own.
APA102 driver installation
--- a/apa102.py +++ b/apa102.py @@ -62,8 +62,8 @@ class APA102: self.ledstart = (globalBrightness & 0b00011111) | 0b11100000 # Don't validate, just slash of extra bits self.leds = [self.ledstart,0,0,0] * self.numLEDs # Pixel buffer self.spi = spidev.SpiDev() # Init the SPI device - self.spi.open(0, 1) # Open SPI port 0, slave device (CS) 1 - self.spi.max_speed_hz=8000000 # Up the speed a bit, so that the LEDs are painted faster + self.spi.open(32766, 0) # Open SPI port 0, slave device (CS) 1 + self.spi.max_speed_hz=500000 + self.spi.mode = 3 # CPOL=1|CPHA=1
The C.H.I.P has a slower SPI than the Raspberry Pi with the default max speed being 500 Khz. In practice, I found the SPI to be stable up to 2.5 Mhz on by board. 500 Khz is also fast enough to drive long strips and small panels @ 30FPS+. Roughly FPS=SPI_SPEED/((32*N_LEDS)+32+(N_LEDS/2))
Wiring and testing
Wire your strip. Be cautious: the strip is 5V powered and input high should be at least 0.7*VDD which is 3.5V while the C.H.I.P has 3.3V GPIOs. Lower the the strip voltage a bit (e.g. using a diode) or use a level shifter.
Run the sample lightshow using
python3 runColorCycle.py. You might want to edit the number of LEDs in the
runColorCycle.py source file.