Update: Now it works with the Audio library:
Teensy 3.0 is compatible, except if you try to use the Audio library ADC input (AudioInputAnalog), because there's only one ADC module so you can't use it for two things.
Teensy 3.1 is compatible. If you want to use AudioInputAnalog and the ADC you have to use the ADC_1 module, the Audio library uses ADC_0. Any calls to functions that use ADC_0 will most likely crash the program. Note: make sure that you're using pins that ADC_1 can read (see pictures above)! Otherwise the library will try to use ADC_0 and it won't work!!
Pedvide, this works fantastic! I numbers I get from my log scale light sensor are much more stable. Your library is certainly advanced but the more I read, I realized it is incredibly well documented! Thank you!
I found this image helpful for those trying to figure out which pins are on ADC0, ADC1, or both!
I have a jumper to cut and solder to change my mic pin, but this edit gets my two earlier prototypes running with ADC+Audio libraries!
Also, I went ahead and cleaned up the example code below. It's based on PRJC's FFT example but configured for taking audio from a mic without the Audio Board and taking an analog reading from ADC1 which currently isn't used by InputAudioAnalog. New Users: currently AnalogReference(INTERNAL) is currently hard coded into the library, depending on you wiring/mic you may need to edit the library. See: https://github.com/PaulStoffregen/Audio/issues/89
Important note from Paul on the topic:
I had originally intended to include an adc1.analogReference() function, like the DAC object has. Somehow, this never happened. It'll come in some future version. Pull requests are welcome.... (hint, hint)
However, changing the reference to 3.3V will reduce the signal amplitude by 3. For hardware where the signal is already very low, you might be better off using the recommended circuit. Those 2 extra capacitors and 4 resistors will buy your 3X the signal gain.
Code:
// FFT Test for Analog Mic
//
// Use PRJC's Audio library to compute audio spectrum analysis
// from an analog mic input on ADC0 while taking an analog read
// sample from a pin on ADC1 using Pedvide's ADC library.
// Download the latest copy at:
// https://github.com/pedvide/ADC
//
// 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>
// CREATE THE ADC OBJECT FIRST, BEFORE ALL AUDIO STUFF!!
ADC *adc = new ADC(); // adc object
const int readPin = 30; // ADC1, Choose a pin the can be accessed by the ADC *NOT* being used to stream audio.
// Currently this must be a pin on ADC1, but has been suggested as a fix for the audio library.
// 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 analogAudioIn(15); //Pin 15, mic pin, currently must be on ADC0
AudioSynthWaveformSine sinewave;
AudioAnalyzeFFT1024 myFFT;
// Connect either the live input or synthesized sine wave
AudioConnection patchCord1(analogAudioIn, 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);
// 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);
adc->setAveraging(8, ADC_1); // set number of averages
adc->setResolution(12, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the sampling speed
}
int value = 0;
void loop() {
float n;
int i;
value = adc->analogRead(readPin, ADC_1); // read a new value, will return ADC_ERROR_VALUE if the comparison is false.
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("Pin: ");
Serial.print(readPin);
Serial.print(" = ");
Serial.print(value*3.3/adc->getMaxValue(ADC_1), DEC); //assuming 3.3v reference voltage
Serial.print("v FFT: ");
for (i=0; i<40; i++) {
n = myFFT.read(i);
if (n >= 0.008) {
Serial.print(n);
Serial.print(" ");
}
else {
Serial.print(" - "); // don't print "0.00"
}
}
Serial.print("\n");
}
}
I've learned a lot from this issue! Thanks to everyone who helped!