Spectrum Analyzer + Arduino Mega + TFT ILI9841 480x320

Hello. I'm planning to make a spectral analyzer (audio) similar to this one, but I want to use a TFT screen.

The TFT screen is this: https://hallroad.org/3.2-inch-ips-tft-lcd-display-ili9481-480x320-36-pins-for-arduino-mega2560.html.

The code in the video is: Arduino/Spectrum_Analyzer.ino at master · GadgetReboot/Arduino · GitHub

I tried to change the code based on my screen, but it doesn't display anything properly (here and because I don't have much knowledge in Arduino). If anyone can help me with its implementation / code modification, thank you in advance.

The code is as follows:

#include <UTFT.h>
#include "fix_fft.h"                                  // fixed point Fast Fourier Transform library
#define audioIn A0                                    // audio input port
extern uint8_t SmallFont[];
UTFT myGLCD(ILI9481,38,39,40,41);


char re[128], im[128];                                // real and imaginary FFT result arrays
byte ylim = 60;                                       // OLED y-axis drawing boundary limit

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  analogReference(DEFAULT);                           // use the default analog reference of 5 volts (on 5V Arduino boards)
                                                      // or 3.3 volts (on 3.3V Arduino boards)
};

void loop() {

  // The FFT real/imaginary data are stored in a char data type as a signed -128 to 127 number
  // This allows a waveform to swing centered around a 0 reference data point
  // The ADC returns data between 0-1023 so it is scaled to fit within a char by dividing by 4 and subtracting 128.
  // eg (0 / 4) - 128 = -128 and (1023 / 4) - 128 = 127
 
  for (byte i = 0; i < 128; i++) {                    // read 128 analog input samples from ADC
    int sample = analogRead(audioIn);
    re[i] = sample / 4 - 128;                         // scale the samples to fit within a char variable
    im[i] = 0;                                        // there are no imaginary samples associated with the time domain so set to 0
  };

  fix_fft(re, im, 7, 0);                              // send the samples for FFT conversion, returning the real/imaginary results in the same arrays

  myGLCD.clrScr();                         // clear display
//  display.setCursor(0, 0);                            // set cursor to top left corner of the display
  myGLCD.print("ANALIZOR SPECTRAL", CENTER, 290);                   // print a header on the top row of the display

  // The data array will contain frequency bin data in locations 0..127 for samples up to the sampling frequency of approx. 9 KHz
  // Each frequency bin will represent a center frequency of approximately (9 KHz / 128 samples) = 70 Hz
  // Due to Nyquist sampling requirements, we can only consider sampled frequency data up to (sampling rate / 2) or (9 KHz / 2) = 4.5 KHz
  // Therefore we only acknowledge the first 64 frequency bins [0..63] = [0..4.5KHz]

  for (byte i = 0; i < 64; i++) {
    int dat = sqrt(re[i] * re[i] + im[i] * im[i]);     // frequency magnitude is the square root of the sum of the squares of the real and imaginary parts of a vector
    myGLCD.drawLine(i * 2, ylim, i * 2, ylim - dat); // draw bars for each frequency bin from 0 Hz to 4.5 KHz
  }

//  display.display();                                   // update the display
}

Arduino + TFT only
get that working

then throw in the rest of the stuff

.

The title is wrong, I want to make with the help of Arduino Mega and TFT a spectral analyzer.

AlexandruSD:
The title is wrong, I want to make with the help of Arduino Mega and TFT a spectral analyzer.

And again, get an example code to work with the Arduino Mega and the TFT.
You have either connection problem or code problem.

Learn how to debug yourself.

.