With my teensy3.1 and existing PCB for my interactive sound/light project I am attempting to implement the fantastic Audio library FFT analysis. My T3.1 takes input from an Adafruit mic, an analog light sensor, and also analog Read from a voltage divider. The current audio library 1.02 does not support the use of analogRead() as it crashes AudioInputAnalog. I put in a request on github, and haven't found a solution else where. I've considered the ADC library however just adding #include <ADC.h> breaks Audio Input Analog. Pedvide, any thoughts?
In my next hardware iteration I could consider I2C solutions to solve the current incompatibility, but I'm wondering if there is a simple software solution to get this running now. I'm only looking for 1 sample of each, every time the FFT is complete, they don't have to be averaged and are not time sensitive.
1) What is the cause of the core conflict? - My guess is something to do with interrupts and analogRead() waits for the conversion, which may be getting interrupted.
2) How difficult or possible would it be to implement a work around?
Interesting aside: touchRead works! I have five touch pins, { 0, 1, 16, 17, 33 } and I was able to read all of them while the FFT was running.
In my next hardware iteration I could consider I2C solutions to solve the current incompatibility, but I'm wondering if there is a simple software solution to get this running now. I'm only looking for 1 sample of each, every time the FFT is complete, they don't have to be averaged and are not time sensitive.
1) What is the cause of the core conflict? - My guess is something to do with interrupts and analogRead() waits for the conversion, which may be getting interrupted.
2) How difficult or possible would it be to implement a work around?
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 <ADC.h>
//ADC *adc = new ADC(); // adc object
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
// Using adafruit mic-amp, edit library to turn-off internal voltage reference in
// inputAnalog.cpp
AudioInputAnalog adc1(15);
AudioSynthWaveformSine sinewave;
AudioAnalyzeFFT1024 myFFT;
// Connect either the live input or synthesized sine wave
AudioConnection patchCord1(adc1, 0, myFFT, 0);
//AudioConnection patchCord1(sinewave, 0, myFFT, 0);
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);
pinMode(15, INPUT);
pinMode(14, INPUT);
// Configure the window algorithm to use
//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("T: "); //Testing touchRead
//Serial.print(touchRead(0));
Serial.print("\t FFT: ");
for (i=0; i<40; i++) {
n = myFFT.read(i);
if (n >= 0.005) {
Serial.print(n);
Serial.print(" ");
} else {
Serial.print(" - "); // don't print "0.00"
}
}
Serial.println();
}
}
Interesting aside: touchRead works! I have five touch pins, { 0, 1, 16, 17, 33 } and I was able to read all of them while the FFT was running.
Last edited: