Galileo GEN2 Project - Real-Time Audio Spectrum Analyzer

Version 2

    I use a Galileo GEN2 to implement a real time audio spectrum analyzer. The maximum frequency recognized by the analyzer is 1only 800Hz due to the sampling rate limitation of the Galileo Arduino function, analogread(). The analyzer had been verified by the assiatance of the free Audacity tool.

    small_DSCF1360.jpg

     

     

    The components used in the project are:

    1. A Galileo GEN2

    2. A Nokia 5110 LCD (There are many producers. Their pinouts may be different.)

    3. A sound sensor (Buy Grove - Sound Sensor [SEN12945P] | Seeedstudio)

     

     

    The Arduino sketch is as follows:

    #include <stdint.h>  //For New Arduino
    #include "PCD8544.h"

    #define pin_adc 0
    #include <fix_fft.h>
    char im[128];
    char data[128];
    int analog_value[128];
    int i=0;

    PCD8544 nokia = PCD8544(3, 4, 5, 7, 6);
    // pin 7 - Serial clock out (SCLK) connects Dig3
    // pin 6 - Serial data out (DIN) connects Dig4
    // pin 5 - Data/Cmd. selct. (D/C) connects Dig5
    // pin 4 - LCD reset (RST) connects Dig6
    // pin 3 - LCD chip select (CS) connects Dig7

    void setup() {
      nokia.init();
      nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
      nokia.clear();
      analogReadResolution(8);
    }


    void show_big_bars(char *spektrum) {
        int spek_for_draw;
        nokia.drawline(10, 15, 10, 39, BLACK);
        for (byte i = 1; i < 64; i++){ // Skip 0 Channel
          // Serial.print(spektrum[i],BYTE);
          spek_for_draw = 1.5*(spektrum[i]); // 0/2.5 ~ 255/2.5
          if (spek_for_draw > 39) spek_for_draw = 39;
          nokia.drawline(i+10, 39 - spek_for_draw, i+10, 39, BLACK);
        }
        //nokia.drawstring(5, 5, "0 09 22 36 49");
        nokia.drawstring(5, 5, "0");
        nokia.drawstring(21, 5, "4");
        nokia.drawstring(37, 5, "8");
        nokia.drawstring(48, 5, "12");
        nokia.drawstring(67, 5, "18");
        nokia.drawstring(5, 0, "Spectrum");
        nokia.drawstring(5, 1,"* 0.1KHz");
        nokia.display(); // Update Screen
        nokia.clear(); // Clear Screen for the animation
    }

    void loop(){
      static long tt;
      int val;
      if (i < 128){
          analog_value[i] = analogRead(pin_adc);
          i++; 
       }
       else{
            for (i=0; i< 128;i++){ //Prepare data for FFT
                data[i] = analog_value[i] - 128;
                im[i] = 0;
            }
       //this could be done with the fix_fftr function without the im array.
            fix_fft(data,im,7,0);
       // I am only interessted in the absolute value of the transformation
            for (i=0; i< 64;i++)
                 data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
       //do something with the data values 1..64 and ignore im
            show_big_bars(data);
            i=0;
       }
    }

     

    The PCD8544 Arduino library for Nokia 5510 LCD can be downloaded in:
    http://120.107.171.121/~tywua/sub/ISAR/Intel_Nokia5110.rar

    The password for decompressing this .rar file is 406. The FFT (Fast Fourier Transform) Arduino library can be downloaded in:

    https://github.com/TJC/arduino/tree/master/sketchbook/libraries/fix_fft
    Add the following statement to both fix_fft.h and fix_fft.cpp.

        #include <Arduino.h>

    Put the downloaded libraries to your arduino-1.5.3-Intel.1.0.3\libraries\. You need add some header files for arduino-1.5.3-Intel.1.0.3. Please refer to the document:

    https://communities.intel.com/message/227354

     

     

    The connections between the Galileo (or Arduino UNO) and my Nokia 5110 LCD are described in the previous Arduino sketch. The following picture shows the connection. Note that Nokia 5110 LCD boards are produced by many producers. Their pinouts may be different.

    The SIG output pin of the sound sensor connects A0 of the Galileo.

     

    nokia.jpg

     

    The video is as follows: