FAB_LED Is a Fast Arduino Bitbanging library for addressable LEDs, like WS2812B.
To install the library, unzip the source files into your Arduino “libraries” directory, like any other library. Rename the directory FAB_LED. Restart your arduino IDE. You’re ready to test it.
Load an example, plug your WS2812B LEDs onto pin D6 of your board (pin “~6” on Arduino Uno), power it, compile and load the program. The led strip should cycle different patterns. If you don’t use pin D6 then just change the declaration in the program.
- Jun 19,2016: Refactoring the library to make it more compact and maintainable. Simplifying the a API to draw() and send() from send_pixels().
- May 2016: support for palettes, pixel remapping, parallel port updates (up to 6 ports on 16mhz avr) beginning support for apa102 and arm.
- Apr 1, 2016: updated repository. Added APA104, WS2812 support, fixed Mac compile bugs, slowed aggressive timing to handle APA104.
Mar 29, 2016: Library should adapt to CPU frequency, added 1K pixels demo. Forgot to update GIT repository!
- Mar 23, 2016: The beta is available, with one code example.
- Feb 29, 2016: I’ve finally debugged my WS2812B library to the point where it all works on a 16MHz Arduino UNO. Now why would anyone care for a me too library?
The FAB_LED library has a few benefits attached to it versus other libraries (AdaFruit NeoPixel or FastLED libraries):
- The low level bit-banging code is written in gcc C, without any inline assembly. This means it should support any CPU frequency, not just the frequencies that I have hardcoded.
- The LED class supports multiple pixel formats, which provide great flexibility to choose between pixel manipulation convenience and pixel memory size. A pixel can use from 1 bit of memory to 32 bits, using different schemes:
- 3 uint8_t per pixel (24 bits)
- One uint32_t word per pixel (32 bits)
- 1, 2, 4 or 8 bits per pixel mapped to a color palette of 2, 4, 16 or 256 colors
- One uint16_t word per pixel (16 bits, 5 bits per pixel), with a choice of 3 levels of brightness
- Separate pixel clear method and a 256-gray levels method allow you to clear or set a LED strip of any size without using up any memory.
- The methods can be called back to back to duplicate patterns on infinitely long LED strips, tested on a 16MHz Arduino Uno. Timings for the palette method work but are very tight.
- Alternatively, you can define multiple arrays to draw frames of an animation, and just change which array is drawn at every clock tick. There is no need to re-draw the frames, unlike other LED libraries.
- Using the class requires nothing more than knowing which port your LED strip is attached to. A physical port on Arduino is 2 elements, the port letter A to F, and the port pin, from 0 to 7.
At this point FAB_LED is not vaporware anymore. It is fully working.
The following example uses the palette routine, using 2 bits per pixels.
- It uses a color palette taking only 12 bytes of RAM to hold the 4 color values.
- It defines a 16-pixel pattern which fits in another 4 bytes of RAM.
- The 16-pixels pattern is sent 11 times in a tight loop, to light up the whole 170-LED strip.
The animation is done by manipulating the palette colors after the tight sendPixel loop:
- We rotate one of the four colors (blue-green pulse).
- We blink on/off the red color.
All this uses a total of 16 bytes for the data arrays, and a one page user code loop to animate. The code page is shown as screen capture.
The bottom loop does the display directly, there is no need for a show() routine since it paints the pixels on the fly as soon as sendPixel() is called.
Here’s a video of this code running:
I am adding slowly 2D support. This is my first rendering. I had to put a cloth to diffuse the LEDs to take the photo. It’s an 8×8 pixel board:
Ooh and posting my video I see someone posted how to pipeline data from a USB port directly… I’ll have to look into that, to maybe stream from USB or a SD card! They can handle thousands of LEDs.