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

Thread: Help with distorted audio output from shield

  1. #1
    Junior Member
    Join Date
    May 2022
    Posts
    7

    Help with distorted audio output from shield

    I am running a pretty basic audio input with FFT analysis setup. I have passthrough audio too. It works fine but now that I am adding in the fastLED library, the passthrough is totally distorted (just screeching sounds). Is there an overlapping output or something?

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <FastLED.h>
    
    //fastLED stuff
    #define NUM_LEDS  1130
    #define DATA_PIN 7    
    #define CLOCK_PIN 14
    #define BRIGHTNESS  200
    #define FRAMES_PER_SECOND 60
    
    CRGB leds[NUM_LEDS];
    bool gReverseDirection = false;
    
    //AUDIO SHIELD STUFF
    const int myInput = AUDIO_INPUT_LINEIN;
    //const int myInput = AUDIO_INPUT_MIC;
    
    // Create the Audio components.  These should be created in the
    // order data flows, inputs/sources -> processing -> outputs
    //
    AudioInputI2S          audioInput;         // audio shield: mic or line-in
    AudioSynthWaveformSine sinewave;
    AudioAnalyzeFFT1024    myFFT;
    AudioOutputI2S         audioOutput;        // audio shield: headphones & line-out
    AudioMixer4            mixer1;
    // Connect either the live input or synthesized sine wave
    //AudioConnection patchCord1(sinewave, 0, myFFT, 0);
    AudioConnection patchCord1(audioInput, 0, audioOutput, 0);  //one for left and one for right, allows stereo passthrough
    AudioConnection patchCord2(audioInput, 1, audioOutput, 1);  //
    AudioConnection patchCord3(audioInput, 0, mixer1, 0);  //need to mix L and R for the FFT analysis (non-stereo)
    AudioConnection patchCord4(audioInput, 1, mixer1, 1);
    AudioConnection patchCord5(mixer1, myFFT);  //this feeds the mixed L and R into the FFT analyzer
    
    AudioControlSGTL5000 audioShield;
    
    void setup() {
      //fastLED stuff
      delay(3000); // sanity delay
      FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR, DATA_RATE_MHZ(4)>(leds, NUM_LEDS);  //the BGR sets the order of the LEDs, it corrects the red-blue reverse
       FastLED.setBrightness( BRIGHTNESS );
      //AUDIO SHIELD STUFF
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(12);
    
      // Enable the audio shield and set the output volume.
      audioShield.enable();
      audioShield.inputSelect(myInput);
      audioShield.volume(0.5);
    
      // Configure the window algorithm to use - test others!
      myFFT.windowFunction(AudioWindowHanning1024);
      //myFFT.windowFunction(NULL);
    
      // Create a synthetic sine wave, for testing
      // To use this, edit the connections above
      sinewave.amplitude(0.8);
      sinewave.frequency(1034.007);
       
    }
    
    void loop() {
      float n;
      int i;
    
      if (myFFT.available()) {
        // each time new FFT data is available
        // print it all to the Arduino Serial Monitor
        Serial.print("FFT: ");
        for (i=0; i<40; i++) {
          n = myFFT.read(i);
          if (n >= 0.01) {
            Serial.print(n);
            Serial.print(" ");
          } else {
            Serial.print("  -  "); // don't print "0.00"
          }
        }
        Serial.println();
      }
    
      leds[0].setHSV( 220, 187, (myFFT.read(1))*1000);
        leds[1].setHSV( 0, 187, (myFFT.read(2))*1000);
          leds[2].setHSV( 32, 187, (myFFT.read(3))*1000);
            leds[3].setHSV( 64, 187, (myFFT.read(4))*1000);
              leds[4].setHSV( 96, 187, (myFFT.read(5))*1000);
                leds[5].setHSV( 128, 187, (myFFT.read(6))*1000);
                  leds[6].setHSV( 160, 187, (myFFT.read(0))*1000);
        FastLED.show();
    }

  2. #2
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    386
    Quote Originally Posted by mkomkom View Post
    I am running a pretty basic audio input with FFT analysis setup. I have passthrough audio too. It works fine but now that I am adding in the fastLED library, the passthrough is totally distorted (just screeching sounds). Is there an overlapping output or something?

    Code:
    //fastLED stuff
    #define DATA_PIN 7    
    #define CLOCK_PIN 14
    You didn't say which Teensy (T3x or T4x) and/or which Audio Shield (Rev C or Rev D) that you are using. Check this <link> for info on which pins your Audio Shield is using (very likely an overlap on pin 7 if you're using a T4x).

    Mark J Culross
    KD5RXT

  3. #3
    Junior Member
    Join Date
    May 2022
    Posts
    7
    Sorry, should have mentioned I am using a Teensy 4.1 and the Rev D board.

    Yes, it looks like pin 7 is used for the audio output. I might not need the audio passthrough. I wonder if I simply delete the I2S2 output the audio shield will not access pin 7 at all?

    I'll also try using a different pin for LEDs. Everyone seems to use 7 and 14 for APA102 strands with the OctoShield, but I don't know why...

  4. #4
    Junior Member
    Join Date
    May 2022
    Posts
    7
    Found this little doozy in the Examples-->OctoWS2811--->Teeny4PinList

    Code:
    This example shows how to
      use only 4 pins, which are the 4 pins of the Octo28 shield which do
      not conflict with the Audio shield.
    
      Required Connections
      --------------------
        pin 2:  LED Strip #1
        pin 14: LED strip #2
        pin 6:  LED strip #5
        pin 5:  LED strip #8
    i wish that had been on the product page! Here is the info compiled from a few pages:

    pin 2: LED Strip #1 [Orange wire- Top Jack]
    pin 14: LED strip #2 [Blue wire - Top Jack]
    pin 6: LED strip #5 [Orange wire - Bottom Jack]
    pin 5: LED strip #8 [Brown wire - Bottom Jack]

    That's everything you need to hook up APA102 strips with the OctoWS2811 Adaptor and the Audio Shield together. Of course you only need 2 of the pins. I went with 2 and 14. So far so good!

Posting Permissions

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