Teensy + Audio Library + Smart Matrix Library = not working

Status
Not open for further replies.

Starscream

New member
Hi guys,

I'm trying to establish a spectrum analyzer on a 16x32 RGB Led Matrix with a Teensy 3.1. I can successfuly use the matrix with the Smart Matrix Library i have got from here:

https://github.com/pixelmatix/SmartMatrix

I also can run the FFT example program from the Teensy Audio Library. The FFT data is shown well on the serial Monitor.

The issue i have is, that the Teensy seems to stop working as soon as i combine both librarys in a single sketch.


Here is my Code, it is almost exactly the Example Code from the Audio Library with the smart matrix lib added. As soon as i uncomment "matrix.begin();" i don't get any data from the Teensy it seems not to run at all, with "matrix.begin();" commented out everything works fine. I tried V1 and V2 from the Smart Matrix Lib. My Teensyduino Version is 1.20. I tried multiple Analog inputs, i'm using the Sparkfun Electet Mic Breakout.

Please let me know any guideance you might have.


Code:
// FFT Test
//
// Compute a 1024 point Fast Fourier Transform (spectrum analysis)
// on audio connected to the Left Line-In pin.  By changing code,
// a synthetic sine wave can be input instead.
//
// The first 40 (of 512) frequency analysis bins are printed to
// the Arduino Serial Monitor.  Viewing the raw data can help you
// understand how the FFT works and what results to expect when
// using the data to control LEDs, motors, or other fun things!
//
// This example code is in the public domain.

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

#include "SmartMatrix_16x32.h"
SmartMatrix matrix;

//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
//


AudioAnalyzeFFT1024    myFFT;
AudioInputAnalog        audioInput(A2); 
AudioConnection patchCord1(audioInput, 0, myFFT, 0);



void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);
  // Configure the window algorithm to use
  myFFT.windowFunction(AudioWindowHanning1024);
  //myFFT.windowFunction(NULL);
  
  //matrix.begin();

}

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();
  }
  
}
 
The smartmatrix shield seems to use nearly all the Teensy 3.1 pins, including the pins that are needed for the audio adapter.
TeensyManualWiring.jpg


The smartmatrix code is doing interrupt-driven DMA to the display. Its possible that the timers it is using are also needed by the audio adapter?
 
Hi,

Yes that could be. Unfortunately i don't have enough knowledge of the Audio library.

I could try to do FFT with the arm.math (CMSIS DSP) library but didn't found a good example where it is shown how to access the FFT data.
 
Hi,

Yes that could be. Unfortunately i don't have enough knowledge of the Audio library.

I could try to do FFT with the arm.math (CMSIS DSP) library but didn't found a good example where it is shown how to access the FFT data.

I've worked with the CMSIS DSP library a bit after discovering it in this guide: https://learn.adafruit.com/fft-fun-with-fourier-transforms . Tony Dicola's implementation is extremely versatile, but it can be simplified to save some time. Unfortunately it does not have the deep performance optimizations that the Audio library does. When you sift through the example, it's helpful to know that the NUMBER_OF_NEOPIXELS also means how many FFT windowing bins are created.

There are 3 or 4 CMSIS commands in void loop(), but essentially the data is returned in an array, CMSIS also offers sum, mean, and other useful functions to analyze the array. Don't forget FFT[0] is your tDC/total signal power!

In my project, I need fast response with low accuracy and settled on FFT_64 at 5000Hz which runs about 69Hz.
 
Status
Not open for further replies.
Back
Top