Controlling multiple LED strands. Neopixel? octoWS2811?


#1

I want to control seven LED (2812b) strands via the D0 - D6 pins to display text and moving patterns. I played with the Neopixel library but it doesn’t seem to have any built-in functions for matrix/array control.

Previously, I was using the octoWS2811 library with Teensy and have some code written for it that works great. Unfortunately, I haven’t found a port for Spark yet. I tried to load octoWS2811 by importing Arduino.h, octoWS2811.h and .cpp. I’m now getting “Arduino.h:27:26: fatal error: avr/pgmspace.h: No such file or directory #include <avr/pgmspace.h>” I fear this process of including built-in Arduino libraries will continue indefinitely.

Has anyone written an octoWS2811 port? Would someone like to? OR would someone like to explain what the process is to port a library so that I can try to do it? Is there an easier / better / faster way to display text and patterns on multiple LED strands with existing libraries or minor modifications?


#2

1.) You can daisy chain them and only use 1 pin to control all of them.

2.) There is already the Neopixel library used to control WS2812b that you should be able to find in the Web IDE

3.) The library examples can be found here: https://github.com/spark/uber-library-example


#3

I’d like to piggy back on this topic, not with a new question, but with an answer.

Like the original poster, I have struggled to find a way to address multiple NeoPixel strings. My puzzlement was deepened by the fact that when the declaration of multiple strings - like…

static Adafruit_NeoPixel leds1(20, S1_PIXEL_PIN,WS2812);
static Adafruit_NeoPixel leds2(10, S2_PIXEL_PIN, WS2812);
static Adafruit_NeoPixel leds3(10, S3_PIXEL_PIN, WS2812);

/*
is followed by code something like...
*/

void setup() {
leds1.begin();
leds1.show();
}

void loop() {
    turnThemOn(leds1);
    delay(1000);
    leds1.clear();
    leds1.show();
}

void turnThemOn(Adafruit_NeoPixel themLeds) {
    for (int lp=0 ;lp < themLeds.numPixels(); lp++) {
        themLeds.setPixelColor(lp,64,64,0); // Go yellow-ish
    }
    themLeds.show();
}

it does kind of work… the leds go on to yellow-ish as expected, but then nothing else happens. the clear() back in the main loop never happens and the cycle does not repeat as expected.

I had mentally discounted the possibility that the cause might be to do with the LED string reference, cos - well it works once - how can it be wrong? …and so I wasted a few hours looking elsewhere for my problem. WRONG!

Turns out that, although the method above works that initial time, it trashes the NEOPIXEL data object on the way out…and it never works again until a reset. To be honest, my knowledge of the various possible methods of passing parameters to functions is sketchy, so I can’t explain this issue in detail - perhaps someone more steeped in that can help me out there?

But anyway, having eliminated all other avenues I came back to wondering if that method was wrong. I googled and googled and google and…anyway you get the idea! Eventually having framed the right question (always the trick, right?), I found the answer within the Adafruit support site.

Below is how the code should (roughly) look to work properly. You pass an address pointer (&) to your string and within the function de-reference code that works on the neopixel string “->” When you do that, all is sweetness. Hope this helps someone else not waste time on this problem. Oddly, this particular “how to” is not even mentioned in the usually reliable Uber-guide to NeoPixels from Adafruit. I have emailed this article to them in case they want to include something.

DECLARATIONS OF NEOPIXEL STRINGS REMAIN UNCHANGED…

void setup() {
    leds1.begin();
    leds1.show();
}

void loop() {
    turnThemOn(&leds1);
    delay(1000);
    leds1.clear();
    leds1.show();
}

void turnThemOn(Adafruit_NeoPixel *themLeds) {
    for (int lp=0; lp< themLeds->numPixels();lp++) {
        themLeds->setPixelColor(lp,64,64,0); // Go yellow-ish
    }
}

Best regards
Alan T

#4
void loop() {
    turnThemOn(&leds1);
    delay(1000);
    leds1.clear();
    leds1.show();
}

void turnThemOn(Adafruit_NeoPixel *themLeds) {
    for (int lp=0; lp&lt; themLeds->numPixels();lp++) {
        themLeds->setPixelColor(lp,64,64,0); // Go yellow-ish
    }
}

cuz it is C++ you should be able to simply pass by reference and avoid all that -> dereferencing stuff…

void loop() {
    turnThemOn(leds1);
    delay(1000);
    leds1.clear();
    leds1.show();
}

void turnThemOn(Adafruit_NeoPixel& themLeds) {
    for (int lp=0; lp < themLeds.numPixels(); lp++) {
        themLeds.setPixelColor(lp,64,64,0); // Go yellow-ish
    }
}

#5

Any particular reason not to use one of the Particle ported NeoPixel libraries?

Or are you? Since I can’t see the include statement in your code.


#6

Ah! Okay - I’ll try that later. Many thanks.

Best regards
Alan T


#7

@ScruffR - yes, I am using the standard 0.0.13 Neopixel library. I was just boiling down the code to make it as short as possible. Sorry for any confusion.

Best regards
Alan T


#8

I’ve been struggling with the same challenge and come to the same answer. I have this code …

Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void displayLowest(Adafruit_NeoPixel* pStrip) {

    // lowest
    pStrip->setPixelColor(0, 20,20,0);
    pStrip->setPixelColor(1, 30,30,0);
    pStrip->setPixelColor(2, 20,20,0);
    pStrip->setPixelColor(3, 0,0,0);
    pStrip->setPixelColor(4, 0,0,0);
    pStrip->setPixelColor(5, 0,0,0);
    pStrip->setPixelColor(6, 0,0,0);
    pStrip->setPixelColor(7, 0,0,0);
    pStrip->setPixelColor(8, 0,0,0);

    pStrip->show();
}


But I get this compile error
"cannot convert ‘Adafruit_NeoPixel’ to ‘Adafruit_NeoPixel*’ for argument ‘1’ to ‘void displayLowest(Adafruit_NeoPixel*)’’"

any ideas why?


#9

Have you followed the README?

You would define strip0 like this:

Adafruit_NeoPixel strip0(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

I just tried it and it compiles.


#10

To provide some background
If you want to use pStrip->setPixelColor(0, 20,20,0); you’d need to create the object like this

Adafruit_NeoPixel *strip0 = new Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

(new instantiates the object and returns an object pointer)

If you create it as you did above, you’d need to call like this

pStrip.setPixelColor(0, 20,20,0);

(this is an object reference which isn’t used in conjunction with the “deref operator” ->)