-Arduino UNO r3/1.0.5
-Seeed Studio TFT v2 (with SD card slot)
http://www.seeedstudio.com/wiki/2.8''_TFT_Touch_Shield_v2.0
-Seeed TFT Library
-Open Music Labs FFT Library
http://wiki.openmusiclabs.com/wiki/ArduinoFFT
I am able to read/write the SD card to display a .bmp on the TFT.
I also have the FFT displayed on the TFT, so I know all the seperate parts work.
It's just when I add the SD library that things break
If I comment out either:
-
#include <SD.h>
-or- - ANYTHING inside the if (Serial.available >0)
It works! But if I try to do both, TFT display is blank. Any hot tips appreciated,
Carl
#include <stdint.h>
//FFT
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library
//TFT
#include <TFTv2.h>
#include <SPI.h>
#include "TFTv2.h"
//SD Card
//#include <SD.h>
//#include <Streaming.h>
const int chipSelect = 4;
boolean isFrozen = false;
////////////////////////////SETUP////////////////////////////////
void setup() {
//FFT
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x45; // use adc5 - The microphone input pin
DIDR0 = 0x01; // turn off the digital input for adc0
//TFT
Tft.TFTinit(); //init TFT
Tft.drawString("Hello v01",70,150,2,YELLOW); //Say Hello
Tft.drawHorizontalLine(0, 320, 240, YELLOW);
Tft.drawVerticalLine(240, 0, 320, YELLOW);
//uC2
Serial.begin(9600);
//SD card
pinMode(10, OUTPUT);
//SD.begin(chipSelect);
}
void loop() {
char uC1Rx;
while(1) { // reduces jitter
if (!isFrozen){
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // 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
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
for (int j = 21 ; j < 127 ; j++){ //display > 3kHz
Tft.drawHorizontalLine(0, (j - 21) * 3, fft_log_out[j], CYAN);
Tft.drawHorizontalLine(fft_log_out[j], (j - 21) * 3, 239 - fft_log_out[j], BLUE);
}
if(Serial.available() > 0){ /////////IF I rem this out, I can load the SD library and the TFT works
Tft.drawString("uC1 RX'd",50,250,2,YELLOW);
Tft.drawString(" ",50,200,2,YELLOW);
} else {
Tft.drawString("uC1 DOWN",50,200,2,YELLOW);
Tft.drawString(" ",50,250,2,YELLOW);
}
}
}
}