Using the Adafruit "Electret Microphone Amplifier - MAX4466 with Adjustable Gain", powered by 5V, output to A0 input on a Nano. Running the following code from OpenMusicLabs...
/*
fht_adc_serial.pde
guest openmusiclabs.com 7.7.14
example sketch for testing the fht library.
it takes in data on ADC0 (Analog0) and processes them
with the fht. the data is sent out over the serial
port at 115.2kb.
*/
#define LOG_OUT 1 // use the log output function
#define FHT_N 128 // set to 128 point fht (gives 64 freq bins)
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#include <FHT.h> // include the library
unsigned long StartTime = 0;
unsigned long EndTime = 0;
void setup() {
// set prescaler to 32 for a sample rate of 38.4kHz (BW = 19.2kHz)
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
sbi(ADCSRA,ADPS0);
/*
Prescale ADPS2,1,0 Clock MHz) Sampling rate (KHz)
2 0 0 1 8 615
4 0 1 0 4 307
8 0 1 1 2 153
16 1 0 0 1 76.8
32 1 0 1 0.5 38.4 <
64 1 1 0 0.25 19.2
128 1 1 1 0.125 9.6 (default)
*/
Serial.begin(9600); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
} // end Setup
void loop() {
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fht_input[i] = k; // put real data into bins
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_log(); // take the output of the fht
sei();
Serial.print("Start: ");
for (byte i = 0 ; i < FHT_N/2 ; i++) {
Serial.print(fht_log_out[i]); // send out the data
Serial.print(" ");
}
Serial.println();
}
}
With relative quiet at the mic, getting results like...
Start: 129 169 142 115 130 109 82 117 107 95 83 98 87 76 93 86 94 80 76 88 66 74 85 85 76 82 75 74 74 74 71 75 74 65 68 70 63 68 73 70 66 69 70 67 70 68 67 67 65 63 64 60 65 66 62 65 62 64 64 65 64 63 66 65
...with the numbers bouncing around some, which I'd expect due to noise. However, when I whistle into or tap the microphone, I expect to see at least some of the bin values change significantly, but they do not. With a scope at input A0, there is an audio signal representative of what the mic hears, on a DC offset of 2.5V.
With mic disconnected and input A0 grounded, see mostly "0" for results which seems correct and tells me that the FHT is doing something.
Any idea why I don't see values change with a change in audio input? It's acting as though the mic is dead, but scope shows it isn't.