Possible workaround for FastLED w/Audio shield issue

Status
Not open for further replies.

Jay Converse

Active member
Like many of us, I struggled for many hours with this, I thought my code was wonky.

I had downloaded some nice animation from GitHub, and the project ran great on it's own. But when I added it to my favorite project that includes my PJRC Audio shield code, it wouldn't behave. Even though my FastLed object was initialized to 224 LEDs, it would never display past the 45th one. I spent a tedious hour tracing with Serial.println, looking for 44, 45, 46, and calculations that would make them. At the same time, my Adafruit Neopixel strip and Neopixel matrix objects in my project were all working fine with 224 LEDs.

I started to tediously rework the animation code, then I found a simple work around. It appears that all FastLED code is running fine, it's only .show() that's busted. So, I changed:

FastLED.show();

to

for(int i = 0; i< NUM_LEDS;i++){
strip.setPixelColor(i, strip.Color(FastLeds.r, FastLeds.g, FastLeds.b));
}
strip.show();

and now I have my pretty animations.
 
This would be great to figure out some of the mysteries of mixing the Audio library (no shield) and FastLED.
Your replacement code include objects that I can't identify:
strip; and
FastLeds[]
Where are they defined?

Is this using only FastLED libs and Audio libs, or is AdaFruit's NeoPixel added (or replacing FastLED?)

Could you post a complete listing of a short program that demonstrates the problem and solution?
 
LOL, a short program. Thanks to all the RAM a Teensy gives me, my favorite project is pushing 5000 lines. My project started with AdaFruit libraries, so I didn't think adding FastLED libraries would interfere. Hell, it compiles, it's a runtime problem!

My grid is asymmetrical (long story), but my x-to-y remapping functions work great with the Neopixel matrix library, so I don't think the asymmetry is the problem

Here are the includes and primary objects:

#define NUM_LEDS 224
#define NUM_COLUMNS 16
#define NUM_ROWS 17

#include "FastLED.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include "TubaGrid16x17.h" // My remap functions
#include "Sprites.h" // My bitmaps
#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeSans9pt7b.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN_LEDOUT, NEO_GRB + NEO_KHZ800);
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(NUM_COLUMNS, NUM_ROWS, PIN_LEDOUT, 0, NEO_GRB + NEO_KHZ800);
CRGB FastLeds[ NUM_COLUMNS * NUM_ROWS ];

In Setup() I've got:

FastLED.addLeds<WS2812B, PIN_LEDOUT, GRB>(FastLeds, NUM_LEDS+1);


It's really strange. All the FastLED math on my FastLeds object works fine, the pixels are in the positions that I expect, but they just won't .Show(). I've seen some other posts that it might be a clock/timing issue, but I'm not smart enough to debug something like that. Hell, I'm an accounting programmer, I don't even own an oscilloscope, all I have is a cheap multimeter.
 
Hi Jay. When looking at the code you posted you have:

...
#define NUM_LEDS 224
#define NUM_COLUMNS 16
#define NUM_ROWS 17
...
CRGB FastLeds[ NUM_COLUMNS * NUM_ROWS ];
...
FastLED.addLeds<WS2812B, PIN_LEDOUT, GRB>(FastLeds, NUM_LEDS+1);

So you've defined NUM_LEDS = 224
and then for the CRGB FastLeds array you're making that 16x17 = 272
and then in the addLeds line you're specifying NUM_LEDS+1 = 225

Three different numbers here. I would sort of expect these discrepancies to cause problems or behavior you might not expect. Double check on that to see if it's perhaps causing any of your FastLED issues.
-marc
 
Thanks for the comment! When I was debugging, I went over those values many times, pulling my hair out. The Fastled code I borrowed has "phantom" pixels that use a remapping function, so x times y is a matrix larger than the displayed output. But if this was a problem, why does copying the FastLed array into the Adafruit array give me the expected results? As I noted above, the FastLed code works fine in its own project, it only goes wonky when I paste it into my big project.

But, I'm not all that stressed about this, thanks to the clock speed of the Teensy, adding the array copy has no noticeable affect. After the holidays I'll revisit my code early one weekend morning...
 
I was just looking at macetech's RGBShades code that uses mapping (not sure if you based your code of that or not) and he defines NUM_LEDS as the matrix W x H. And then this same value is put in the CRGB array (lines 42,43 here: https://github.com/macetech/RGBShades/blob/master/XYmap.h ) which is sort of what I was expecting to see.

I do see where he adds +1 in the addLeds line (line 96 here: https://github.com/macetech/RGBShades/blob/master/RGBShades.ino ), but that is added to a variable last visible pixel, not NUM_LEDS. Maybe that's your difference to investigate?

Backup your code and just don't break your great fun before the holidays! And yeay for the great speed of the Teensy! Nice to be able to do extra stuff and still keep your display rate up just fine. :)
-marc
 
Status
Not open for further replies.
Back
Top