In order to simply test the system I used a processing sketch:
import processing.serial.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioInput in;
FFT fft;
int buffer_size = 4096;
float sample_rate = 200000;
int freq_width = 150;
int bands = 64;
Serial port1;
float[] spectrum = new float[bands];
byte []freq_array = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float[] freq_height = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char start = '<';
char end = '>';
void settings()
{
size(512, 360);
}
void setup() {
background(255);
port1 = new Serial (this, "COM7", 19200);
}
void draw() {
background(255);
for(int j=0; j<64; j++){
freq_array[j] = byte(random(0,17));
}
port1.write(start);
port1.write(freq_array);
port1.write(end);
}
void stop()
{
in.close();
minim.stop();
super.stop();
}
Now, the original idea was to have this working wireless with an HC05 module. But to first validate the system I simply used an FTDI basic board to hook up the standalone arduino to the computer running the processing sketch.
The problem that I am currently facing is that this seems to work just fine at 19200 baud but the display is laggy (essentially out of sync with the music). If I use a higher baud, say 38400, the display simply hangs at random (the arduino side) even when running the above processing test sketch.
However, adding a small delay at the end of port1.write(end) (40ms was the minimum I could go to), the system seems to work fine. While this solution somewhat works, I am wondering if someone could help me understand this behavior and if there is a way around this.
Thanks
Nitin