Home

Awesome

light_ws2812 V2.6

Light weight library to control WS2812 based LEDS and LED Strings on 8-Bit AVR and ARM microcontrollers. The new version 2 of this library supports a simplified interface and arbitrary CPU clock. V2.1 finally adds Arduino support.

See the library in action on a LPC810

New

Supported Devices

Description

This is a small Ansi-C library to control WS2811/WS2812 based RGB Leds and strings. Only the 800kHz high-speed mode is supported. This library uses a bit-banging approach with cycle optimized assembler innerloops. Some advantages of this approach compared to other solutions are:

The timing values used in the library were adjusted to work on all devices. Look here and here for details.

Usage C - Interface

Examples are provided in the Examples folder. You can build them with the supplied makefile.

Usage Arduino

Usage C++ - Interface

Usage platformio

For arduino and pure C implementations, the library supports platformio. By default, light_ws2812_Arduino will be used. If arduino is not used, i.e. the code is written pure C without arduino, define one of build_flags in platformio.ini.

FlagLibrary
LIGHT_WS2812_AVRlight_ws2812_AVR
LIGHT_APA102_AVRlight_apa102_AVR

Here is an example platformio.ini for attiny85 and nanoatmega328 without arduino.

[common]
platform = atmelavr
build_flags = -DLIGHT_APA102_AVR
lib_deps = https://github.com/cpldcpu/light_ws2812.git
upload_port = /dev/cuaU0

[env:attiny85]
board = attiny85
platform = ${common.platform}
lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags}

# with ArduinoISP programmer
upload_port = ${common.upload_port}
upload_speed = 19200
upload_protocol = stk500v1
upload_flags =
    -P$UPLOAD_PORT

[env:nanoatmega328]
board = nanoatmega328
platform = ${common.platform}
lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags}
upload_port = ${common.upload_port}

All examples under examples directory are built by platformio.

Troubleshooting

Please note that incorrect timing is rarely the source of problems. If you want to save some time, go through the items below before altering the library.

None or only a part of the string is lighting up

The LEDs are flickering and are not showing the intended color

Release History

You can find the old V1 here: https://github.com/cpldcpu/light_ws2812/tree/v1.0

Tested Combinations AVR

Device4 MHz8 MHz9.6 MHz12 MHz16 MHz20 Mhz
ATtiny 85 (Standard Core )X*XX
ATtiny 13 (Standard Core)X
ATmega 8 (Standard Core)XX
ATtiny 10 (Reduced Core)XX
ATmega 168 (Standard Core)XX
ATmega 32u4 (Standard Core)XXX

*only supported by V2.4 and earlier

Tested Combinations Arduino

Device4 MHz8 MHz9.6 MHz12 MHz16 MHz20 Mhz
Arduino UnoXX
Arduino Mega 2560X
Arduino NanoX

Tested Combinations ARM

Device12 MHz16 MHz20 MHz30 MHz32 MHz
LPC810 (Cortex M0+)XXX
STL32L052 (Cortex M0+)X
KW36Z (Cortex M0+)X

Please find updates on https://github.com/cpldcpu/light_ws281