Welcome, Guest
Username: Password: Remember me

TOPIC: Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA

Arduino FFT Spectrum Analyzer with pedalSHIELDMEGA 7 months 3 weeks ago #1476

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Platinum Member
  • Posts: 575
  • Thank you received: 133
  • Karma: 32
This is a poor man's spectrum analyzer with pedalSHIELD MEGA. it basically uses the ADC0 to read the analog signal and plot it on the 128x64 OLED display.



The code is a modification of the code by blurtime (blurtime.blogspot.com/2010/11/arduino-re...-audio-spectrum.html) all credit to him.
//Based on previous works by http://blurtime.blogspot.com/2010/11/arduino-realtime-audio-spectrum.html
//Adapted and Coded by RAy www.electrosmash.com
 
#include "U8glib.h"
#include "fix_fft.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//other variables
int input, bit_crush_variable=0;
int counter=0;
int count=64; //initially in mid position
 
char im[128], data[128];
char x = 0, ylim = 64;
int i = 0, val;
int dat, var;
int min=1024, max=0;
 
void setup() {
  //setup IO
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(TOGGLE, INPUT_PULLUP); 
  pinMode(PUSHBUTTON_1, INPUT_PULLUP);
  pinMode(PUSHBUTTON_2, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(6, OUTPUT); //PWM0 as output
  pinMode(7, OUTPUT); //PWM1 as output
 
  u8g.firstPage();
 do {
    u8g.setFont(u8g_font_helvR18r);
    u8g.drawStr( 0, 30, " Spectrum");
    u8g.drawStr( 0, 60, "  Analyzer");   
    } while( u8g.nextPage() );
delay (1500);
  }
 
void loop() 
{   
//turn on the LED when footswitch pressed
if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH); 
else digitalWrite(LED, LOW);
 
//read the audio signal
  for ( i = 0; i < 128; i++) 
  {
    val = analogRead(A0);
    data[i] = val / 4 - 128;
    im[i] = 0;
    if(val>max) max=val;
    if(val<min) min=val;
  }
 
  fix_fft(data, im, 7, 0);
 
if(digitalRead(TOGGLE))//if the toogle is HIGH make a fine FFT representation
{
 u8g.firstPage(); 
    do {
     for ( i = 1; i < 64; i++) 
     {   
      dat = sqrt(data[i] * data[i] + im[i] * im[i]);   
      var = ylim - dat;
      if (var<0) var=0;
      u8g.drawLine(i*2 + x, ylim, i*2 + x,var ); // skip displaying the 0-500hz band completely.
     }
        } while( u8g.nextPage() ); 
}
else //if the toogle is LOW make a course FFT representation
{
  u8g.firstPage(); 
    do {
     for ( i = 1; i < 64; i+=2) 
     {       
      dat= sqrt(data[i] * data[i] + im[i] * im[i]);  
      var = ylim - dat;
      if (var<0) var=0;
      u8g.drawLine(i*2 + x, ylim, i*2 + x,var );
      u8g.drawLine((i*2 + x)+1, ylim, (i*2 + x)+1,var );
     }
        } while( u8g.nextPage() ); 
}
}

The hardware configuration and the number of resources that the FFT takes make the Arduino unable to play back the signal at the same time that it is represented, so if you want to just visualize the signal is fine. BUT if you want the signal to be visualized and also to go (clean) through the pedal you would need to use a small cable to jump input and output pins like the image below:

IMG_0292.jpg
Last Edit: 7 months 3 weeks ago by Ray.
The administrator has disabled public write access.
Time to create page: 0.130 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio