Hi I am working on a speech recognition project for my arduino. I want to have my arduino use ELM Chan's ffft library because it seems to work great with the parts I have. The example for the fft sampling to the computer works fine and im currently trying to expand the original code to store 1024 values stored from the arduino into an SD card, to access them later. My code is getting stuck somewhere because it won't do anything when I open up the serial monitor. I have NO IDEA what is wrong with it, but I think something might be happening in the adcInit() or ISR(ADC_vect) functions.
Any help would be GREATLY appreciated!
Thanks
Judd
And here is my code:
#include "SD.h"
#include "stdint.h"
#include "ffft.h"
#define IR_AUDIO 0
volatile byte pos = 0;
volatile long zero = 0;
int count;
int nextCount;
int incomingByte;
int16_t capture[FFT_N];
complex_t bfly_buff[FFT_N];
uint16_t spektrum[FFT_N/2];
uint16_t signal[(FFT_N/2)*16]; // this allows 64 bit resolution per bin and 16 sets of bins
// FFT_N = 128
void setup() {
Serial.begin(115200);
Serial.println("Start of Sketch.");
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
while(!Serial) {
digitalWrite(8, HIGH);
}
digitalWrite(8, LOW);
Serial.println("Initializing SD card...");
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(1000); // must have delay here
if(!SD.begin(10)) {
Serial.println("Card failed, or not present");
while(1 == 1) {
digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);
delay(100);
}
}
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(100);
Serial.println("Card initialized.");
delay(100); // here too
adcInit();
adcCalb();
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
}
if(incomingByte == 'H') {
digitalWrite(8, HIGH);
}
if(incomingByte == 'L') {
digitalWrite(8, LOW);
}
for(count = 0; count < (FFT_N/2)16; count++) {
if(pos == FFT_N) {
fft_input(capture, bfly_buff);
fft_execute(bfly_buff);
fft_output(bfly_buff, spektrum);
pos = 0;
}
for(nextCount = 0; nextCount < FFT_N/2; nextCount++) {
signal[((count(FFT_N/2))+1)+nextCount] = spektrum[nextCount];
}
File dataFile = SD.open("Voice Recognition.txt", FILE_WRITE);
}
}
ISR(ADC_vect) {
for(pos = 0; pos < 128; pos++) {
capture[pos] = ADC;
if(capture[pos] == -1 || capture[pos] == 1) {
capture[pos] = 0;
}
}
Serial.println("Done.");
return;
}
void adcInit() {
ADMUX = _BV(REFS0) | IR_AUDIO; // | _BV(ADLAR);
ADCSRA = _BV(ADSC) | _BV(ADEN) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
sei();
}
void adcCalb() {
long midl = 0;
for (byte i = 0; i < 2; i++) {
pos = 0;
delay(100);
midl += capture[0];
delay(900);
}
zero = -midl/2;
}