New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more than 3 controllers breaks FastLED on an ESP32 using PlatformIO #722

Open
nsamala opened this Issue Jan 20, 2019 · 10 comments

Comments

Projects
None yet
3 participants
@nsamala
Copy link

nsamala commented Jan 20, 2019

Using the Arduino framework for the ESP32 in PlatformIO , I have issues running code with more than 3 controllers. I'm using this with an ESP-WROOM32. It works fine for 3 controllers but the moment I add a fourth or fifth (see the ledTest function) it does not render the LEDs at all.

#include <Arduino.h>
#include <FastLED.h>
#include <vector>

const int STATUS_COUNT = 1;
const int STATUS_PIN = 21;
const int STRIP_COUNT = 45;
const int STRIP_ONE_PIN = 16;
const int STRIP_TWO_PIN = 17;
const int STRIP_THREE_PIN = 18;
const int STRIP_FOUR_PIN = 19;
TaskHandle_t ledTask;

void printInfo();

// led test methods
void ledTest(void *parameter);
void showGradient(CRGB *strip, uint8_t hue, int count);
void color(CRGB *strip, int count, CRGB color);
std::vector<CRGB*> strips;

void setup() {
    Serial.begin(115200);
    printInfo();

    xTaskCreate(ledTest, "ledTest", 5000, NULL, 1, &ledTask);
}

void loop() {
    delay(10);
}

void printInfo() {
    Serial.print("ESP SDK Version: ");
    Serial.println(ESP.getSdkVersion());

    Serial.print("ESP Chip Revision: ");
    Serial.println(ESP.getChipRevision());
}

void ledTest(void *parameter) {
    Serial.println("Starting LED test");
    strips.push_back(new CRGB[STATUS_COUNT]);
    strips.push_back(new CRGB[STRIP_COUNT]);
    strips.push_back(new CRGB[STRIP_COUNT]);
    strips.push_back(new CRGB[STRIP_COUNT]);
    strips.push_back(new CRGB[STRIP_COUNT]);

    FastLED.addLeds<WS2812B, STATUS_PIN, GRB>(strips[0], STATUS_COUNT);
    FastLED.addLeds<WS2812B, STRIP_ONE_PIN, GRB>(strips[1], STRIP_COUNT);
    FastLED.addLeds<WS2812B, STRIP_TWO_PIN, GRB>(strips[2], STRIP_COUNT);
    FastLED.addLeds<WS2812B, STRIP_THREE_PIN, GRB>(strips[3], STRIP_COUNT);
    FastLED.addLeds<WS2812B, STRIP_FOUR_PIN, GRB>(strips[4], STRIP_COUNT);

    int count;
    uint8_t hue = 0;
    for (;;) {
        hue = (hue + 1) % 255;
        for (int i = 0; i < strips.size(); i++) {
            count = i == 0 ? STATUS_COUNT : STRIP_COUNT;
            showGradient(strips[i], hue, count);
        }
        FastLED.show();
        delay(10);
    }
    vTaskDelete(NULL);
}

void showGradient(CRGB *strip, uint8_t hue, int count) {
    fill_rainbow(strip, count, hue);
}

void color(CRGB *strip, int count, CRGB color) {
    for (int i = 0; i != count; i++)
        (*strip)[i] = color;
}
@focalintent

This comment has been minimized.

Copy link
Member

focalintent commented Jan 20, 2019

So - the code you have doesn't even compile - or at least it doesn't compile in the Arduino IDE (even if I fix the typo in your fill_rainbow line to fill_rainbow(strips, count, hue); - as there's no cast from std::vector<CRGB*> to CRGB* being found.

Can you try making this work under the Arduino IDE - if the 5 strips still isn't working there, I'll have @samguyer take a look at it - but platform IO isn't an officially tested/supported build environment. I don't have any multi-strip esp32 setups here right now, and won't be able to spin one up for a bit, otherwise I'd test it here.

(Mostly I want to make sure that this is also an issue in the build environment that Sam is likely to be using before I send him off chasing)

@nsamala

This comment has been minimized.

Copy link
Author

nsamala commented Jan 21, 2019

@focalintent sorry I had changed the code I had copied over in the sake of brevity and missed some things. I've gone ahead and fixed it.

When you comment out the last two FastLED.addLED lines, the strips iterate through the rainbow. Else, it freezes after setting that first status strip to red.

@focalintent

This comment has been minimized.

Copy link
Member

focalintent commented Jan 21, 2019

Does it still not work for you will you build/install it through the Arduino IDE?

@focalintent

This comment has been minimized.

Copy link
Member

focalintent commented Jan 21, 2019

Also does it work when you have the code in loop vs creating a task?

@nsamala

This comment has been minimized.

Copy link
Author

nsamala commented Jan 21, 2019

@focalintent I've tried both. It doesn't work through the Arduino IDE and it doesn't work if I move the code to loop() instead of in a separate FreeRTOS task.

@nsamala

This comment has been minimized.

Copy link
Author

nsamala commented Jan 21, 2019

@focalintent for reference, I've used the SmartLeds library here and it works for all five strips using RMT.

@focalintent

This comment has been minimized.

Copy link
Member

focalintent commented Jan 21, 2019

Thanks - I’m trying to narrow the test case for @samguyer to look at.

@samguyer

This comment has been minimized.

Copy link
Contributor

samguyer commented Jan 21, 2019

Hi! I'll give this code a test myself and let you know what I find. The RMT driver has been used by a number of people to drive a bunch of strips, though, so maybe there's something else going on.

@focalintent

This comment has been minimized.

Copy link
Member

focalintent commented Jan 21, 2019

Also, @samguyer - pull the most recent build of the library - a) to see if there's any outstanding changes between what you have in your branch and what I have here and b) I went through and annotated the methods called from the interrupt handler with IRAM_ATTR

@nsamala

This comment has been minimized.

Copy link
Author

nsamala commented Jan 31, 2019

@samguyer any luck reproducing this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment