Issues compiling arduinoFFT codes

Hi, I am trying to get just a basic audio spectrum analyzer going on an LCD display. The problem is that none of the codes work for me when I try to compile them. I have tried on 3 different laptops. I'm using the Arduino Uno and IDE 2.3.2. and decided to just try a simpler program to start with and copied the code from the project for the loudest frequency detector I am using the "arduinoFFT" library by Enrique Condes. The results are the same for any program using FFT, I get told that "arduinoFFT does not name a type". Each one of the programs I try obviously works for the author and others who copy it - why am I getting errors? Thanks in advance.

C:\Users\Owner\AppData\Local\Temp.arduinoIDE-unsaved2024630-7180-1qx75sa.grqqi\sketch_jul30a\sketch_jul30a.ino:28:1: error: 'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'?
arduinoFFT FFT = arduinoFFT();
^~~~~~~~~~
ArduinoFFT
C:\Users\Owner\AppData\Local\Temp.arduinoIDE-unsaved2024630-7180-1qx75sa.grqqi\sketch_jul30a\sketch_jul30a.ino: In function 'void loop()':
C:\Users\Owner\AppData\Local\Temp.arduinoIDE-unsaved2024630-7180-1qx75sa.grqqi\sketch_jul30a\sketch_jul30a.ino:60:5: error: 'FFT' was not declared in this scope
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
^~~
exit status 1
Compilation error: 'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'?"

READ the error message, it literally tells you what the problem is.

Hint: arduinioFFT and ArduinoFFT are NOT the same thing! Your code, which nobody here can see, is obviously wrong.

I see the capitalisation but that is how the file is named when downloaded. Is the problem in the 'arduinoFFT" library or the code that is written for it? because every code that is written for FFT returns the same error.

The code is on that linked that I posted but I will put it here so you can see it:
/*
File/Sketch Name: AudioFrequencyDetector

Version No.: v1.0 Created 12 December, 2019

Original Author: Clyde A. Lettsome, PhD, PE, MEM

Description: This code/sketch makes displays the approximate frequency of the loudest sound detected by a sound detection module. For this project, the analog output from the
sound module detector sends the analog audio signal detected to A0 of the Arduino Uno. The analog signal is sampled and quantized (digitized). A Fast Fourier Transform (FFT) is
then performed on the digitized data. The FFT converts the digital data from the approximate discrete-time domain result. The maximum frequency of the approximate discrete-time
domain result is then determined and displayed via the Arduino IDE Serial Monitor.

Note: The arduinoFFT.h library needs to be added to the Arduino IDE before compiling and uploading this script/sketch to an Arduino.

License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) version 3, or any later
version of your choice, as published by the Free Software Foundation.

Notes: Copyright (c) 2019 by C. A. Lettsome Services, LLC
For more information visit My Weekend Project: Audio Frequency Detector w/ Arduino|ClydeLettsome.com

*/

#include "arduinoFFT.h"

#define SAMPLES 128 //SAMPLES-pt FFT. Must be a base 2 number. Max 128 for Arduino Uno.
#define SAMPLING_FREQUENCY 2048 //Ts = Based on Nyquist, must be 2 times the highest expected frequency.

arduinoFFT FFT = arduinoFFT();

unsigned int samplingPeriod;
unsigned long microSeconds;

double vReal[SAMPLES]; //create vector of size SAMPLES to hold real values
double vImag[SAMPLES]; //create vector of size SAMPLES to hold imaginary values

void setup()
{
Serial.begin(115200); //Baud rate for the Serial Monitor
samplingPeriod = round(1000000*(1.0/SAMPLING_FREQUENCY)); //Period in microseconds
}

void loop()
{
/Sample SAMPLES times/
for(int i=0; i<SAMPLES; i++)
{
microSeconds = micros(); //Returns the number of microseconds since the Arduino board began running the current script.

    vReal[i] = analogRead(0); //Reads the value from analog pin  0 (A0), quantize it and save it as a real term.
    vImag[i] = 0; //Makes  imaginary term 0 always

    /*remaining wait time between samples if  necessary*/
    while(micros() < (microSeconds + samplingPeriod))
    {
      //do nothing
    }
}

/*Perform FFT on samples*/
FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal,  vImag, SAMPLES, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

/*Find peak frequency and print peak*/
double peak = FFT.MajorPeak(vReal,  SAMPLES, SAMPLING_FREQUENCY);
Serial.println(peak);     //Print out the most  dominant frequency.

/*Script stops here. Hardware reset required.*/
while (1); //do one time

}

This is wrong. Case matters. Check whether the actual class names in the library file have the first letter capitalized.

Please use code tags when posting code.

Hint: when starting with a new library, the very first step is to make sure that one or more of the library example programs compiles and works as expected. Then study the examples to make sure your "other code" has all the function calls and names used and spelled correctly.

Edited: So the code that has been shared on the youtube video is wrong? I get that error for every code on every project though?

If the example code in the "official library" compiles without errors and works correctly, then it is not wrong.

Someone else's code may very likely refer to an outdated library, and the library authors are under no obligation to make their code backwards compatible. It is your responsibility to check.

The latest version of the official library may be downloaded on the Arduino reference site, or included using the library manager. If you look at the first example in that library (FFT_01.ino) as I suggested, you will see that it has the following lines:

/* Create FFT object */
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

PS: LOTS of code shared on YouTube is out of date and plenty of it is nonsense for other reasons. YouTube is not at all a reliable code resource.

1 Like

I just tried with a project from the Arduino projecthub and it also faults at "arduinoFFT FFT = arduinoFFT(); " with the same error message "'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'?" , so does that mean every one of the 5 or 6 projects I have tried to copy is outdated?

/*
Copyright (c) 2019 Shajeeb TM

https://github.com/shajeebtm/Arduino-audio-spectrum-visualizer-analyzer/
https://create.arduino.cc/projecthub/Shajeeb/32-band-audio-spectrum-visualizer-analyzer-902f51

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <arduinoFFT.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define SAMPLES 64            //Must be a power of 2
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW   // Set display type  so that  MD_MAX72xx library treets it properly
#define MAX_DEVICES  4   // Total number display modules
#define CLK_PIN   13  // Clock pin to communicate with display
#define DATA_PIN  11  // Data pin to communicate with display
#define CS_PIN    10  // Control pin to communicate with display
#define  xres 32      // Total number of  columns in the display, must be <= SAMPLES/2
#define  yres 8       // Total number of  rows in the display


int MY_ARRAY[]={0, 128, 192, 224, 240, 248, 252, 254, 255}; // default = standard pattern
int MY_MODE_1[]={0, 128, 192, 224, 240, 248, 252, 254, 255}; // standard pattern
int MY_MODE_2[]={0, 128, 64, 32, 16, 8, 4, 2, 1}; // only peak pattern
int MY_MODE_3[]={0, 128, 192, 160, 144, 136, 132, 130, 129}; // only peak +  bottom point
int MY_MODE_4[]={0, 128, 192, 160, 208, 232, 244, 250, 253}; // one gap in the top , 3rd light onwards
int MY_MODE_5[]={0, 1, 3, 7, 15, 31, 63, 127, 255}; // standard pattern, mirrored vertically

 
double vReal[SAMPLES];
double vImag[SAMPLES];
char data_avgs[xres];

int yvalue;
int displaycolumn , displayvalue;
int peaks[xres];
const int buttonPin = 5;    // the number of the pushbutton pin
int state = HIGH;             // the current reading from the input pin
int previousState = LOW;   // the previous reading from the input pin
int displaymode = 1;
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers


MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);   // display object
arduinoFFT FFT = arduinoFFT();                                    // FFT object
 


void setup() {
    
    ADCSRA = 0b11100101;      // set ADC to free running mode and set pre-scalar to 32 (0xe5)
    ADMUX = 0b00000000;       // use pin A0 and external voltage reference
    pinMode(buttonPin, INPUT);
    mx.begin();           // initialize display
    delay(50);            // wait to get reference voltage stabilized
}
 
void loop() {
   // ++ Sampling
   for(int i=0; i<SAMPLES; i++)
    {
      while(!(ADCSRA & 0x10));        // wait for ADC to complete current conversion ie ADIF bit set
      ADCSRA = 0b11110101 ;               // clear ADIF bit so that ADC can do next operation (0xf5)
      int value = ADC - 512 ;                 // Read from ADC and subtract DC offset caused value
      vReal[i]= value/8;                      // Copy to bins after compressing
      vImag[i] = 0;                         
    }
    // -- Sampling

 
    // ++ FFT
    FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
    FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
    // -- FFT

    
    // ++ re-arrange FFT result to match with no. of columns on display ( xres )
    int step = (SAMPLES/2)/xres; 
    int c=0;
    for(int i=0; i<(SAMPLES/2); i+=step)  
    {
      data_avgs[c] = 0;
      for (int k=0 ; k< step ; k++) {
          data_avgs[c] = data_avgs[c] + vReal[i+k];
      }
      data_avgs[c] = data_avgs[c]/step; 
      c++;
    }
    // -- re-arrange FFT result to match with no. of columns on display ( xres )

    
    // ++ send to display according measured value 
    for(int i=0; i<xres; i++)
    {
      data_avgs[i] = constrain(data_avgs[i],0,80);            // set max & min values for buckets
      data_avgs[i] = map(data_avgs[i], 0, 80, 0, yres);        // remap averaged values to yres
      yvalue=data_avgs[i];

      peaks[i] = peaks[i]-1;    // decay by one light
      if (yvalue > peaks[i]) 
          peaks[i] = yvalue ;
      yvalue = peaks[i];    
      displayvalue=MY_ARRAY[yvalue];
      displaycolumn=31-i;
      mx.setColumn(displaycolumn, displayvalue);              // for left to right
     }
     // -- send to display according measured value 
     
    displayModeChange ();         // check if button pressed to change display mode
} 

void displayModeChange() {
  int reading = digitalRead(buttonPin);
  if (reading == HIGH && previousState == LOW && millis() - lastDebounceTime > debounceDelay) // works only when pressed
  
  {

   switch (displaymode) {
    case 1:    //       move from mode 1 to 2
      displaymode = 2;
      for (int i=0 ; i<=8 ; i++ ) {
        MY_ARRAY[i]=MY_MODE_2[i];
      }
      break;
    case 2:    //       move from mode 2 to 3
      displaymode = 3;
      for (int i=0 ; i<=8 ; i++ ) {
        MY_ARRAY[i]=MY_MODE_3[i];
      }
      break;
    case 3:    //     move from mode 3 to 4
      displaymode = 4;
      for (int i=0 ; i<=8 ; i++ ) {
        MY_ARRAY[i]=MY_MODE_4[i];
      }
      break;
    case 4:    //     move from mode 4 to 5
      displaymode = 5;
      for (int i=0 ; i<=8 ; i++ ) {
        MY_ARRAY[i]=MY_MODE_5[i];
      }
      break;
    case 5:    //      move from mode 5 to 1
      displaymode = 1;      
      for (int i=0 ; i<=8 ; i++ ) {
        MY_ARRAY[i]=MY_MODE_1[i];
      }
      break;
  }

    lastDebounceTime = millis();
  }
  previousState = reading;
}


The compiler is clearly telling you that the code and the library are not compatible, and giving you a hint about how to correct that particular error.

Thanks, I see that it is due to a change in the official "arduinoFFT" library, since finding a post that mentions the exact fault codes I am getting when compiling FFT codes in this discussion at post #7. I might have to roll back to 1.6.2 as suggested there.

Compiles ok with 1.6.2 .......... :grinning:

1 Like

Since you're creating a new project, it's generally better to update your code in order to bring it in line with the latest version of the library as the latter my include important bug fixes.

Is it too much trouble to change a lower case 'a' to an uppercase 'A' in your code?

Not it isn't, now that I know where the issue lies. But at the moment I don't know how to code and I am trying various libraries of spectrum analyzers with several different displays and none of it is my code so it is much easier to simply roll back ardunoFFT to 1.6.2 while I locate the library that works best for my purposes and then I will play with the code.

It is slower, but quite a bit less frustrating to start a new hobby at the beginning, rather than tackle a complex project with zero training or experience, i.e. learn to crawl before trying to run.

I'll do that once I know what code I am going to go with. First I need to be able to run the various libraries I find quickly to see if it's what I'm after and if I can adapt it to work with my display.

I can understand that, which is why I also got an Arduino book for beginners and am going through the beginners projects one at a time.
I'm not totally new to coding in that I did first year computer science at University and did quite well with programming in Pascal. But that was 40 years ago and time has not been good to my memory.
At the moment I have a specific project in mind that will prove very useful and cost-saving at the factory where I work so I am pretty focussed on getting that working as well.

That brings up other errors...so still no go.
As above ...1.6.2 compiles fine.

1 Like

One step at a time!

It all depends what a person wants to do but it's like someone hiring an interpreter for a visit to China, why spend years learning the language if you're only going to have a one week business trip and never again. [one project]
For me though, I think it is an interesting hobby to get into eventually so I will learn it slowly over time, but for now the interpreter[other people's libraries along with guidance on interfacing it with my project] will do the job for the project I have in mind.