Fastled and Teensy audio library. Flickering leds when audio library used?

Status
Not open for further replies.

Gibbedy

Well-known member
Hello,
I am creating a christmas tree using (27) 12V WS2811 leds, a teensy 3.2, Octows2811 sheild, and audio sheild.

I appear to have an incompatibility with fastled and audio libraries.

I my issue is when I include audio library and create some audio objects I get leds flickering on my led strip that fastled isn't driving.

I have removed the audio sheild for testing and have the following setup:

Teensy 3.2 with Octows2811 adapter which connects to teensy with every pin except 6,7,12,14,15.
The following code is a small good example of the flickering I see.

Code:
#define MY_ISSUE  //include audio library and create a few objects

#ifdef MY_ISSUE

  #include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav           playSdWav1;     //xy=136,65
AudioAnalyzePeak         peak2;          //xy=348,219
AudioAnalyzePeak         peak1;          //xy=358,171
AudioOutputI2S           i2s1;           //xy=380,92
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 0, peak1, 0);
AudioConnection          patchCord3(playSdWav1, 1, i2s1, 1);
AudioConnection          patchCord4(playSdWav1, 1, peak2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=155,192

#endif 

#include "FastLED.h"

FASTLED_USING_NAMESPACE

#define DATA_PIN    2
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    27
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
  Serial.begin(115200);
  delay(3000); // 3 second delay for recovery

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

  // set master brightness control
  FastLED.setBrightness(BRIGHTNESS);
}

void loop()
{
  
  sinelon();
  // send the 'leds' array out to the actual LED strip
  //Serial.print("leds[0]=");
  Serial.println(leds[0]);
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND); 
}

void sinelon()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  leds[pos] += CHSV( 0, 255, 192);
}

It is the Fastled DemoReel100 stripped down to run just one effect (sinelon)
Without the audio library it runs perfect.
With audio library "#define MY_ISSUE" I see the following issue.

https://youtu.be/jxxxhzGHQQQ

Video will be up in 7 mins.


Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 1.0.8 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Using library SerialFlash at version 0.4 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire
Using library FastLED at version 3.1.5 in folder: C:\Users\FPV\Qsync\Arduino\libraries\FastLED
 
WS2811 LEDs have a self clocking waveform that is very sensitive to any disruption that delays transitions at the exact time needed. The audio library first likely candidate is the audio library interupts are persisting long enough for the pixel date to be corrupted. What happens if you physically have the audio shield in place with the relevant libraries loaded but with all the audio object commented out?

SPI LEDs are less fussy about minor perturbations in timing, and in the past at least it was possible to integrate the OctoWS library and the audio board as per one of the included FFT examples if you modded your board per the webpage. The Octo library does the wave form generation in the background in hardware so not disrupted by audio. On the other hand seeing the reports of the first pixels not working at the moment which is a problem with that route.
 
WS2811 LEDs have a self clocking waveform that is very sensitive to any disruption that delays transitions at the exact time needed. The audio library first likely candidate is the audio library interupts are persisting long enough for the pixel date to be corrupted. What happens if you physically have the audio shield in place with the relevant libraries loaded but with all the audio object commented out?

With just this left in (audio adapter connected or not ):

Code:
  #include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

No problems.

With just this line extra:
Code:
AudioOutputI2S           i2s1;           //xy=380,92

I get the occasional flicker.
The more audio objects I create the worse it gets.

Edit:
The Octo library does the wave form generation in the background in hardware so not disrupted by audio. On the other hand seeing the reports of the first pixels not working at the moment which is a problem with that route.

Fastled is able to use octo library for its magic, however when I do this audio does not work. Serial monitor shows "Start playing" is repeated. All fastled animations work however.
I can't use Octows2811 library for what I'm working on as I run out of memory (or some other bug) when I try to use 216 led string with other memory hungry hmi library.
 
Last edited:
Looks like it's the audio interrupts. Which means you can:
Add a slave CPU to do one (or more) of the functions
Halt audio interupts during light updating (which will of course break audio, and starting may get tricky)
Sort out what's clashing with Octo+Audio (should work when pins are moved to de-conflict so should be a solvable problem given enough time)
Switch to SPI LEDs
 
Thanks gremlin.
I eventually found a page of fastled documentation that says the same.

"
On the teensy 3/3.1 platforms the library allows interrupts while writing out WS2811 leds. However, the interrupt handling functions still need to be very fast, otherwise it will interfere with the writing out of led data, either corrupting your output or cutting your frames off. If you run into problems like this (N.B. this is reported to happen often with the audio library) either switch to an LED chipset that doesn't care about being interrupted (like the APA102) or put the following line at the top of your .ino file to disable interupts (before any of the #include statements):
#define FASTLED_ALLOW_INTERRUPTS 0"

So my options are to use fastled with octows2811 define which uses Paul's library for writing, however this prevents the test wav file from playing.

I assume I can get audio and octows2811 library working together, if not I'll put another small test program together and start a new tgread for that.

For now this thread is solved. Fastled and teensy audio don't mix. See fastled documentation. :)

Edit: From more reading it looks like octows2811 library and audio library will not work for what I want. No audio output, and from my testing no playsdwav.

Edit: https://www.youtube.com/watch?v=Uo704A_Bm14
For 27 leds fastled no interrupts define works ok, but not for large strips audio sounds like that tardis taking off.
 
Last edited:
Status
Not open for further replies.
Back
Top