Hi,
At the moment I am trying to get an analog mic to connect to a Teensy 3.5. I'd like to use pin A16 or A17 because these are free on the PCB where the teensy is plugged in to.
For the mic I use a MAX9812 amp in between which so most of the sound will be on a voltage level between 0 and 1.2v.
The code I am using is working an a Teensy 3.2 on pin A3 but also not in pin A17.
So the main question is, is it possible to attach a mic to A16 or A17 to perform fft?
This is the code I'm using:
Who can help me figuring out if this is possible or what I am doing wrong
At the moment I am trying to get an analog mic to connect to a Teensy 3.5. I'd like to use pin A16 or A17 because these are free on the PCB where the teensy is plugged in to.
For the mic I use a MAX9812 amp in between which so most of the sound will be on a voltage level between 0 and 1.2v.
The code I am using is working an a Teensy 3.2 on pin A3 but also not in pin A17.
So the main question is, is it possible to attach a mic to A16 or A17 to perform fft?
This is the code I'm using:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#define MIC_ANALOG A17
#define MIC_GAIN 10 // multiplier for the specific mic
// GUItool: begin automatically generated code
// Actions
AudioAnalyzePeak peak1; //xy=495,162
AudioAnalyzeFFT256 fft256_1; //xy=496,230
AudioAnalyzeRMS rms1; //xy=505,109
// Analog mic
AudioInputAnalog adc1(MIC_ANALOG); //default for adc1 is A2 3.3v
AudioConnection patchCord1(adc1, fft256_1);
AudioConnection patchCord2(adc1, rms1);
AudioConnection patchCord3(adc1, peak1);
// An array to hold the 16 frequency bands
long output_interval = 2000;
float fft_level[16];
int loopcounter =0;
float rms =0;
float peak = 0;
long mill_counter;
// frequency bin spreading
int fft_bin[17] = {2,3,4,6,8,10,13,16,20,24,29,34,40,47,54,62,70};
const String sensDivider = ", ";
//*********************************************************************************** SETUP
void setup()
{
// Audio connections require memory to work.
AudioMemory(12);
// Configure the window algorithm to use
fft256_1.windowFunction(AudioWindowHanning256);
fft256_1.averageTogether(255);
}
//*********************************************************************************** FFT256
void read_fft256()
{
if (fft256_1.available())
{
// each time new FFT data is available, fft_bin it into 16 channels
// Note- response doesn't seem flat so each is normalized <experimenting!
// Note- these calculations go very fast!!
// Band are 172Hz wide
fft_level[0] += fft256_1.read(fft_bin[0],fft_bin[1]-1) * 1 * MIC_GAIN;
fft_level[1] += fft256_1.read(fft_bin[1],fft_bin[2]-1) * 1 * MIC_GAIN;
fft_level[2] += fft256_1.read(fft_bin[2],fft_bin[3]-1) * 1 * MIC_GAIN;
fft_level[3] += fft256_1.read(fft_bin[3],fft_bin[4]-1) * 1 * MIC_GAIN;
fft_level[4] += fft256_1.read(fft_bin[4],fft_bin[5]-1) * 1 * MIC_GAIN;
fft_level[5] += fft256_1.read(fft_bin[5],fft_bin[6]-1) * 1 * MIC_GAIN;
fft_level[6] += fft256_1.read(fft_bin[6],fft_bin[7]-1) * 1 * MIC_GAIN;
fft_level[7] += fft256_1.read(fft_bin[7],fft_bin[8]-1) * 1 * MIC_GAIN;
fft_level[8] += fft256_1.read(fft_bin[8],fft_bin[9]-1) * 1 * MIC_GAIN;
fft_level[9] += fft256_1.read(fft_bin[9],fft_bin[10]-1) * 1 * MIC_GAIN;
fft_level[10] += fft256_1.read(fft_bin[10],fft_bin[11]-1) * 1 * MIC_GAIN;
fft_level[11] += fft256_1.read(fft_bin[11],fft_bin[12]-1) * 1 * MIC_GAIN;
fft_level[12] += fft256_1.read(fft_bin[12],fft_bin[13]-1) * 1 * MIC_GAIN;
fft_level[13] += fft256_1.read(fft_bin[13],fft_bin[14]-1) * 1 * MIC_GAIN;
fft_level[14] += fft256_1.read(fft_bin[14],fft_bin[15]-1) * 1 * MIC_GAIN;
fft_level[15] += fft256_1.read(fft_bin[15],fft_bin[16]-1) * 1 * MIC_GAIN;
loopcounter += 1;
}
// else
// {
// Serial.println("FFT not available");
// }
}
//*********************************************************************************** Counter
bool output_audio()
{
if (millis() > mill_counter + output_interval)
{
Serial.print("fft_0="); Serial.print(fft_level[0]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_1="); Serial.print(fft_level[1]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_2="); Serial.print(fft_level[2]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_3="); Serial.print(fft_level[3]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_4="); Serial.print(fft_level[4]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_5="); Serial.print(fft_level[5]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_6="); Serial.print(fft_level[6]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_7="); Serial.print(fft_level[7]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_8="); Serial.print(fft_level[8]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_9="); Serial.print(fft_level[9]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_10="); Serial.print(fft_level[10]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_11="); Serial.print(fft_level[11]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_12="); Serial.print(fft_level[12]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_13="); Serial.print(fft_level[13]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_14="); Serial.print(fft_level[14]/loopcounter); Serial.print(sensDivider);
Serial.print("fft_15="); Serial.print(fft_level[15]/loopcounter); Serial.print(sensDivider);
Serial.print("RMS="); Serial.print(rms/loopcounter); Serial.print(sensDivider);
Serial.print("Peak="); Serial.print (peak1.readPeakToPeak()); Serial.print(sensDivider);
Serial.print("Loopcounter=");Serial.println(loopcounter);
for (size_t i = 0; i < 16; i++)
{
fft_level[i]=0;
}
mill_counter=millis();
loopcounter=0;
rms =0;
return true;
}
}
//*********************************************************************************** RMS
void read_rms()
{
if (rms1.available())
{
rms += rms1.read();
}
}
//*********************************************************************************** LOOP
void loop()
{
read_fft256();
read_rms();
output_audio();
}
Who can help me figuring out if this is possible or what I am doing wrong