Hello, I am having trouble getting the FirstLight sketch to work with FastLED 3.1.8,

Hello, I am having trouble getting the FirstLight sketch to work with FastLED 3.1.8, a Teensy 3.6, and an APA102 strip. I am using Arduino IDE 1.8.2 and Teensyduino 1.41. I’m not getting any compile errors, but instead of the led strip showing the FirstLight sketch, instead I just get random colors that slowly twinkle at the end of the strip.

I have successfully gotten Adafruit’s strandtest sketch to work, so I know it’s not a problem with my wiring or the LED’s. My modified FirstLight code is below (I didn’t modify any part of the loop function). Does anyone have any idea what I may be doing wrong? Thanks.

#include <FastLED.h>
#define NUM_LEDS 30
#define DATA_PIN 34
#define CLOCK_PIN 33
CRGB leds[NUM_LEDS];

void setup() {
delay(2000);
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
}

void loop() {
// Move a single white led
for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds
leds[whiteLed] = CRGB::White;

  // Show the leds (only one of which is set to white, from above)
  FastLED.show();

  // Wait a little bit
  delay(100);

  // Turn our current led back to black for the next loop around
  leds[whiteLed] = CRGB::Black;

}
}

Try initializing your array to Black. With APA102’s, especially, I have seen problems where the leds get a noise signal, and, if the power is on, they display.

The clock and data lines may be reversed, the labeling is incorrect on some strips. Try swapping the pin numbers round either in your code or in your wiring but not both.

If that doesn’t work try slowing the data rate, some setups/wiring/strips can’t handle 12MHz (which is the default rate for APA102s).

FastLED.addLeds<LED_TYPE, DATA_PIN, CLK_PIN, COLOR_ORDER, DATA_RATE_MHZ(1)>(leds, 0, NUM_LEDS).setCorrection(TypicalLEDStrip);

Get it working at 1MHz and then increase the speed to the fastest rate that is stable.

@Paul_Guthrie Thanks for the suggestion, but it turns out it’s related to the clock speed, see below. I’ll keep this in mind for the future though.

@Jeremy_Spencer It works at 1 MHZ! But not at 2 MHZ or faster. I’m not using a 3.3v to 5v logic level shifter for the data or clock, would this be causing the problem at higher clock speeds? I didn’t realize this might be necessary until now (I thought I had read somewhere that this is unnecessary for short LED strips and forgot about it). If that is the problem, what’s interesting is that I previously had no problems running FastLED on the same strip using an Adafruit Feather 32u4 without specifying a low clock speed, but maybe that board defaults/maxes out at a 1 MHZ refresh rate?

Glad you got it working :slight_smile:

The Adafruit library drives APA102s at 1MHz, did you use that library with the feather?

You shouldn’t need a level shifter with APA102s…

No, I also used fastled on the feather. I never specified a clock speed though, so I don’t know what it would default to for that board.

And hmm, well so far not using a logic level shifter is the only thing I can think of that would prevent me from running at a higher clock speed. I’ve got one on order, so I’ll report back! Thanks for your help.