Go Down

Topic: Problem in serial monitor with FFT library (Read 1 time) previous topic - next topic



I want to use the FFT library for a project but when i try to run the examples i have problem reading the data from the serial monitor.
The results i get are like the picture.
What could be wrong?

Thank you!


You're probably using the wrong baud rate, or you are using Serial.write(int) instead of Serial.print(int).
We can't say much if you don't post your code.



Jan 18, 2017, 02:10 pm Last Edit: Jan 18, 2017, 02:16 pm by yamahandreas
Thanks for your reply!

The baud rate is 115200 and that's what i choose in the serial monitor
The code is this
Code: [Select]

guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.  there is a pure data patch for
visualizing the data.

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(115200); // 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

void loop() {
  while(1) { // reduces jitter
    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
    Serial.write(255); // send a start byte
    Serial.write(fft_log_out, 128); // send out the data

I've tried changing Serial.write to Serial.print but I get this error "call of overloaded 'print(uint8_t [128], int)' is ambiguous" for Serial.print(fft_log_out, 128); witch I could not figure out.


This sketch sends an array of data over Serial in binary format, you can't read it in the Serial Monitor because it shows ASCII text and line endings only.

You could look for a program that will plot the data (on your computer) maybe there is one included with the library, maybe a Processing sketch or something. Or you could write your own processing sketch. It's not that hard, just open the serail port, wait for the start byte, store the received data and plot some points on the screen in a for-loop.

If you really want to see it in the Serial Monitor, you could loop over fft_log_out 128 times and Serial.print each number (in your Arduino sketch).



To see the results of the FFT transformation on the serial monitor, replace
Code: [Select]

Serial.write(fft_log_out, 128);


Code: [Select]

  for (int i=0; i<FFT_N/2; i++) {
    Serial.print(" ");


Go Up