Yet another WS2812 driver, uses the BusrtSPI library. Less features than the PixelArray library but I felt like making my own version.

Dependencies:   BurstSPI

Dependents:   WS2812Text cylon

An alternative WS2811/2812 (NeoPixel) driver using the BusrtSPI library.

Credit for the inspiration goes to Jacob Bramley for his pixelArray library that can be found here: http://developer.mbed.org/users/JacobBramley/code/PixelArray/

This version was written mainly to help me understand what was going on rather than to overcome any shortcomings in the other library and as such it lacks some features (800kHz only, no callback on each pixel etc...)

Connect the SPI output to the LED data input, other SPI pins are unused.

Note: The voltage thresholds between the LEDs and mbed devices are on paper incompatible. The datasheet for the WS2812 indicated that running at 5V it requires 4V on Din to count it as a high (the threshold is 0.8*the supply voltage). Most mbeds are lucky to output much over 3.1V. In reality things normally work OK but it depends on the mBed and batch to batch variations in the LEDs, I've seen some combinations that start to fail at an LED supply voltage of 4.4V or more. If something odd is going on try dropping the LED power supply voltage, they run fine down to 4V.

Files at this revision

API Documentation at this revision

Comitter:
AndyA
Date:
Wed Nov 23 09:41:48 2016 +0000
Parent:
4:8997e12da7c7
Commit message:
Update to fix issues with 16bit brightness support.

Changed in this revision

BurstSPI.lib Show annotated file Show diff for this revision Revisions of this file
wsDrive.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8997e12da7c7 -r 6aa3e7de65f9 BurstSPI.lib
--- a/BurstSPI.lib	Tue Nov 22 15:14:42 2016 +0000
+++ b/BurstSPI.lib	Wed Nov 23 09:41:48 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Sissors/code/BurstSPI/#6ed1d9f1ef37
+http://mbed.org/users/Sissors/code/BurstSPI/#bc069279eb37
diff -r 8997e12da7c7 -r 6aa3e7de65f9 wsDrive.cpp
--- a/wsDrive.cpp	Tue Nov 22 15:14:42 2016 +0000
+++ b/wsDrive.cpp	Wed Nov 23 09:41:48 2016 +0000
@@ -68,9 +68,9 @@
 
 void wsDrive::sendPixel(pixelInfo16 *pixToSend)
 {
-    sendByte((unsigned char)pixToSend->G);
-    sendByte((unsigned char)pixToSend->R);
-    sendByte((unsigned char)pixToSend->B);
+    sendByte(pixToSend->G<255?(unsigned char)pixToSend->G:255);
+    sendByte(pixToSend->R<255?(unsigned char)pixToSend->R:255);
+    sendByte(pixToSend->B<255?(unsigned char)pixToSend->B:255);
 }