cpldcpu / light_ws2812

Light weight library to control WS2811/WS2812 based LEDS and LED Strings for 8-Bit AVR microcontrollers.
GNU General Public License v3.0
939 stars 204 forks source link

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.

Flag Library
LIGHT_WS2812_AVR light_ws2812_AVR
LIGHT_APA102_AVR light_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

Device 4 MHz 8 MHz 9.6 MHz 12 MHz 16 MHz 20 Mhz
ATtiny 85 (Standard Core ) X* X X
ATtiny 13 (Standard Core) X
ATmega 8 (Standard Core) X X
ATtiny 10 (Reduced Core) X X
ATmega 168 (Standard Core) X X
ATmega 32u4 (Standard Core) X X X

*only supported by V2.4 and earlier

Tested Combinations Arduino

Device 4 MHz 8 MHz 9.6 MHz 12 MHz 16 MHz 20 Mhz
Arduino Uno X X
Arduino Mega 2560 X
Arduino Nano X

Tested Combinations ARM

Device 12 MHz 16 MHz 20 MHz 30 MHz 32 MHz
LPC810 (Cortex M0+) X X X
STL32L052 (Cortex M0+) X
KW36Z (Cortex M0+) X

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