playFlashRaw and FastLED incompatible?

Status
Not open for further replies.

Break Stuff

Active member
I'm using Teensy 3.2, Teensyduino 1.36, Arduino 1.8.1, PJRC Propshield, APA102 leds, and FastLed 3.1.3

I can find no combination of settings that allow playFlashRaw and FastLED to work at the same time.
as soon as "FastLED.addLeds<>" is called playFlashRaw will not work. Comment it out and playFlashRaw works just fine.

Code with file:
Code:
/******************************* LEDS */
#include <FastLED.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];

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

AudioPlaySerialflashRaw  playFlashRaw1;  
AudioMixer4              mixer1;         
AudioOutputAnalog        dac1;          
AudioConnection          patchCord1(playFlashRaw1, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, dac1);

void setup() {
  /************************************************************ LEDS */
  delay(1000);    
    
   FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS); // Comment this out and the sounds work
 
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);  

  /*********************************************************** Audio */
  AudioMemory(20);
  pinMode(5, OUTPUT);
  mixer1.gain(0, 0.8);
  digitalWrite(5, HIGH);
  if ( !SerialFlash.begin(6) ) Serial.println("spi failure"); else Serial.println("spi success");
}


void loop() {
  /********************************************************************************** LEDS */
  for(int n = 0; n < NUM_LEDS; n++) {
    leds[n] = CRGB::White;
   //   SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));    //these 4 lines do not help
   //   digitalWrite(7, HIGH);  
    FastLED.show();
   //   digitalWrite(7, LOW);
   //   SPI.endTransaction(); 
    delay(8);
    leds[n] = CRGB::Black;  
  }
  /******************************************************************************* Audio */
   Serial.println("start play attempt");
   playFlashRaw1.play("rainstickMONO.raw");         
   delay(5);
   while ( playFlashRaw1.isPlaying() );
   Serial.println("end play attempt");
}
 

Attachments

  • rainstickMONO.zip
    228.2 KB · Views: 114
If you are using/forcing Software SPI or alternate hardware SPI pins then yes. Otherwise you can declare it as above with no problems.

From https://github.com/FastLED/FastLED/wiki/Basic-usage
For four wire chipsets you have a couple of options. If you are using the hardware SPI pins for the device that you're building for, then you don't even have to specify the pins:

void setup() {
FastLED.addLeds<APA102>(leds, NUM_LEDS);
}
If you are specifying your own pins, you have to specify a clock and a data pin:

void setup() {
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS);
}
 
Anyone got any ideas on a work around?
Well, since FastLED doesn't use SPI lib, maybe try SPI begin/end. This sketch plays the RAW file fine in the loop(), but I don't have LED strip, so i don't really know if LEDs would be working.. worth a try, i guess
Code:
/******************************* LEDS */
#include <FastLED.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];

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

AudioPlaySerialflashRaw  playFlashRaw1;  
AudioMixer4              mixer1;         
AudioOutputAnalog        dac1;          
AudioConnection          patchCord1(playFlashRaw1, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, dac1);

void setup() {
  /************************************************************ LEDS */
    
   FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS); // Comment this out and the sounds work
 
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);  

  /*********************************************************** Audio */
  AudioMemory(20);
  pinMode(5, OUTPUT);
  mixer1.gain(0, 0.8);
  digitalWrite(5, HIGH);
  if ( !SerialFlash.begin(6) ) Serial.println("spi failure"); else Serial.println("spi success");
}


void loop() {
  SPI.end();
  SPI.begin();
  /********************************************************************************** LEDS */
  for(int n = 0; n < NUM_LEDS; n++) {
    leds[n] = CRGB::White;
  //    SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));    //these 4 lines do not help
      digitalWrite(7, HIGH);  
    FastLED.show();
      digitalWrite(7, LOW);
   //   SPI.endTransaction(); 
    delay(8);
    leds[n] = CRGB::Black;  
  }
  SPI.end();
  /******************************************************************************* Audio */
  SPI.begin();
   Serial.println("start play attempt");
   playFlashRaw1.play("TOPGUN.RAW");         
   delay(5);
   while ( playFlashRaw1.isPlaying() );
   Serial.println("end play attempt");
}

with analyzer i do see activity on pins 11 and 13 when pin 7 goes HIGH
 
Last edited:
SPI.begin();
Will make the audio work but then the leds no longer work.

calling FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS);
in the loop makes the leds work again but it seems like a terrible idea. And shuts off the audio off as soon as it's called.

but with this someone can play audio and then lights if they want, just not at the same time.

Code:
/******************************* LEDS */
#include <FastLED.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];

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

AudioPlaySerialflashRaw  playFlashRaw1;  
AudioMixer4              mixer1;         
AudioOutputAnalog        dac1;          
AudioConnection          patchCord1(playFlashRaw1, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, dac1);

void setup() {
  /************************************************************ LEDS */
    
   FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS); // Comment this out and the sounds work
 
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);  

  /*********************************************************** Audio */
  AudioMemory(20);
  pinMode(5, OUTPUT);
  mixer1.gain(0, 0.8);
  digitalWrite(5, HIGH);
  if ( !SerialFlash.begin(6) ) Serial.println("spi failure"); else Serial.println("spi success");
}


void loop() {
  SPI.end();
  /********************************************************************************** LEDS */

   FastLED.addLeds<APA102, BGR>(leds, NUM_LEDS);  // Calling addLeds here makes both work, ish
  for(int n = 0; n < NUM_LEDS; n++) {
    leds[n] = CRGB::White;
      digitalWrite(7, HIGH);  
    FastLED.show();
      digitalWrite(7, LOW);
    delay(8);
    leds[n] = CRGB::Black;  
  }
  /******************************************************************************* Audio */
  SPI.begin();
   Serial.println("start play attempt");
   playFlashRaw1.play("TOPGUN.RAW");         
   delay(5);
   while ( playFlashRaw1.isPlaying() );
   Serial.println("end play attempt");
}
 
I updated my sketch in post #5 bout the same time as you were posting your new sketch. The audio is going to cut off each time through the loop once the isPlaying while loop finishes, yes? if you don't wait on isPlaying, then i could see that flipping the SPI with begin/end could kill the playback in loop(). But i'm working without LED strip, so probably useless advice.
 
Apparently calling FastLED.addLeds repeatedly will not consume more memory. So if someone can use this for now great.
 
Status
Not open for further replies.
Back
Top