Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 4 + Audio Adapter + FastLED = Problems

  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    18

    Teensy 4 + Audio Adapter + FastLED = Problems

    Hi all,

    Here's a video of what I have working on a Teensy 3.6, and now I am attempting to switch in a Teensy 4. This is a model for a much larger project, so I am very excited the T4 came out at just the right time!

    This project right now only consists of performing FFT with the audio adapter, and driving LEDs (WS2815) based on the FFT data.

    On the T3.2 and T3.6, I needed to use the OCTOWS2811 library to make both the FFT and LEDs work simultaneously. However, this library does not work on the T4 / is not needed? Anywho, I'm back to my early day problems where I can do either FFT or drive LEDs, but not both at the same time. Does anybody know why these 2 things interfere with each other and how to fix it?

    Also, I've found that only on a T4, a delay of 1 or higher ( "delay(1)" ) is required to get FastLED to work. Super simple sketches that have no audio component, like this one that just moves a light back and fourth, require a delay. Anybody know why? Here's my code for this:
    Code:
    #include <FastLED.h>
    #define NUM_LEDS_PER_STRIP 979
    #define NUM_STRIPS 1
    #define NUM_LEDS 979
    
    CRGB leds[NUM_LEDS_PER_STRIP * NUM_STRIPS];
    
    void setup() {
      FastLED.addLeds<NUM_STRIPS, WS2813, 10, GRB>(leds, NUM_LEDS_PER_STRIP);
      LEDS.setBrightness(80);
    }
    
    void loop() { 
      FastLED.clear();  // clears LEDs
      int x = beatsin16(1, 0, NUM_LEDS);  // makes "x" go back and fourth between 0 and NUM_LEDS
      leds[x] = CHSV(100, 255, 255); // Sets LED x to green
      FastLED.show();  // Pushes to LED strip
      delay(1);  // With this line commented out, nothing will show on the LED strip
    }

    Here's code that successfully prints the FFT data but does not make my LEDs light up (EXCEPT FOR LEDs 0 - ~60. When the variable "x" is between 0 - ~60, the "x" LED lights up.):
    Code:
    #include <FastLED.h>
    #define NUM_LEDS_PER_STRIP 979
    #define NUM_STRIPS 1
    #define NUM_LEDS 979
    CRGB leds[NUM_LEDS_PER_STRIP * NUM_STRIPS];
    
    #include <Audio.h>
    // GUItool: begin automatically generated code
    AudioInputI2S i2s1; //xy=219.1999969482422,183
    AudioMixer4 mixer1; //xy=403.1999969482422,203.1999969482422
    AudioAnalyzeFFT1024 fft1024; //xy=547.1999969482422,239
    AudioConnection patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection patchCord3(mixer1, fft1024);
    AudioControlSGTL5000 audioShield; //xy=446.1999969482422,317
    // GUItool: end automatically generated code
    const int myInput = AUDIO_INPUT_LINEIN;
    
    void setup() { 
      Serial.begin(9600);
      
      FastLED.addLeds<NUM_STRIPS, WS2813, 10, GRB>(leds, NUM_LEDS_PER_STRIP);
      LEDS.setBrightness(80);
    
    // AUDIO STUFF
      AudioMemory(12);
      audioShield.enable();
      audioShield.inputSelect(myInput);
    // configure the mixer to equally add left & right
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.5);
    }
    
    void loop() { 
      printSpectrum();
    
      FastLED.clear();
      int x = beatsin16(1, 0, NUM_LEDS);
      leds[x] = CHSV(100, 255, 255);
      FastLED.show();
      delay(1);
    }
    
    void printSpectrum() {
      if (fft1024.available()) {
        printNumber(fft1024.read(0) * 1000);
        printNumber(fft1024.read(1) * 1000);
        printNumber(fft1024.read(2, 3) * 1000);
        printNumber(fft1024.read(4, 6) * 1000);
        printNumber(fft1024.read(7, 10) * 1000);
        printNumber(fft1024.read(11, 15) * 1000);
        printNumber(fft1024.read(16, 22) * 1000);
        printNumber(fft1024.read(23, 32) * 1000);
        printNumber(fft1024.read(33, 46) * 1000);
        printNumber(fft1024.read(47, 66) * 1000);
        printNumber(fft1024.read(67, 93) * 1000);
        printNumber(fft1024.read(94, 131) * 1000);
        printNumber(fft1024.read(132, 184) * 1000);
        printNumber(fft1024.read(185, 257) * 1000);
        printNumber(fft1024.read(258, 359) * 1000);
        printNumber(fft1024.read(360, 511) * 1000);
        Serial.println();
      }
    }
    
    void printNumber(float n) {
      if (n >= 0.004) {
        Serial.print(n, 3);
        Serial.print(" ");
      }
      else {
        Serial.print("   -  "); // don't print "0.00"
      }
    }
    I've isolated the problem to this code, that sets up the audio system. When this is commented out, the LEDs work. When it's not commented out, the LEDs don't work.
    Code:
    // GUItool: begin automatically generated code
    AudioInputI2S i2s1; //xy=219.1999969482422,183
    AudioMixer4 mixer1; //xy=403.1999969482422,203.1999969482422
    AudioAnalyzeFFT1024 fft1024; //xy=547.1999969482422,239
    AudioConnection patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection patchCord3(mixer1, fft1024);
    AudioControlSGTL5000 audioShield; //xy=446.1999969482422,317
    // GUItool: end automatically generated code
    Any help is very much appreciated!

  2. #2
    Junior Member
    Join Date
    Aug 2016
    Posts
    18
    Regarding the first chunk of code and the required delay, the reason for this has been found! At the recommendation of someone on Reddit, I tried delayMicroseconds() and found that 265 microseconds was the lowest I could go.

    "There's a slight delay in the data (listed as 300ns in the datasheet) when it is passed from one "pixel" to another that may have a cumulative effect. 979 LEDs * 300ns ~= 294ms which is darn close to your working delay"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •