Donnerstag, 2. April 2015

Yet Another WS2812 library

I'm currently working with the WS2812 LEDs. They are awesome because they're so simple to hook up and interface with.
Probably the most popular Arduino library for programming these LEDs is FastLED. It features a ton of useful functions and super optimized routines. And you cannot only use LEDs with the WS2811 controller, also SPI based controllers. However, I failed getting it to work with a 8 MHz AVR.  It seemed like the timing was way off.

Edit: It is the ATmega 1284P that will cause problems with FastLED. Apparently the bit-banging-routines are only working on 328, 32u4 and 2560. This is due to the larger memory the 1284P can access, which needs 3 address bytes instead of 2 with the 328. Therefore, jump-instructions take one tick longer. At 8 MHz that is 0,125 µs which is 10% of the period of one bit at 800 kHz (the clock frequency of the WS2812). That's why the actual clock frequency of the AVR needs to be 10% higher than defined in the F_CPU macro. According to this, the developers of FastLED are aware of this issue, but are not going to fix it.

Over at the Arduino forums, someone recommended using a light weight WS2812 library instead. I tried this one and it worked like a charm. Unfortunately, it is so "light" that it doesn't even support a global brightness parameter. Also, the way the HSV to RGB conversion is a bit user-unfriendly by using an indirection with another RGB-struct.

So I changed the whole library by Tim aka cpldcpu, Matthias Riegler, Windell H. Oskay and Freezy a bit up. I added direct RGB and HSV access to each pixel, the optimized HSV to RGB function from FastLED and a global brightness method, which is defeatable by commenting out a single line (to make it lighter for ATtiny). It isn't beautiful, but it works and some of you might be interested in it, so I shared it.
https://github.com/emgoz/WS2812
- Marv

Keine Kommentare:

Kommentar veröffentlichen