I have a sketch for an arduino Uno or nano, which compiles and uploads fine to my arduino uno. I then tried to upload it to a esp32 Wroom DA board, but it doesn't compile with this error.
exit status 1
Compilation error: 'int index' redeclared as different kind of symbol
#include <arduinoFFT.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
MD_MAX72XX disp = MD_MAX72XX(MD_MAX72XX::FC16_HW, 10, 4);
arduinoFFT FFT = arduinoFFT();
double realComponent[64];
double imagComponent[64];
int spectralHeight[] = {0b00000000,0b10000000,0b11000000,
0b11100000,0b11110000,0b11111000,
0b11111100,0b11111110,0b11111111};
int index, c, value;
void setup()
{
disp.begin();
Serial.begin(9600);
}
void loop()
{
int sensitivity = map(analogRead(A6),0,1023,50,100);
Serial.println (analogRead(A6));
for(int i=0; i<64; i++)
{
realComponent[i] = analogRead(A1)/sensitivity;
imagComponent[i] = 0;
}
FFT.Windowing(realComponent, 64, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(realComponent, imagComponent, 64, FFT_FORWARD);
FFT.ComplexToMagnitude(realComponent, imagComponent, 64);
for(int i=0; i<32; i++)
{
realComponent[i] = constrain(realComponent[i],0,80);
realComponent[i] = map(realComponent[i],0,80,0,8);
index = realComponent[i];
value = spectralHeight[index];
c = 31 - i;
disp.setColumn(c, value);
}
}
I am new to esp32 boards so I just assumed the sketch would be ok for it.
Please post the complete error message, using code tags.
Hi,
index appears to be a reserved word for the ESP8266 and ESP32
Try with a name other than index. Like indexX
"int indexX, c, value;"
it seems that one of the libraries has a global variable named "index"
So I renamed the variable from index to myIndex
.... and then - - - the next error appeared
Most ESP32-board-definitions do not have defined A0,A1,....
So I looked up the pin-out of the ESP32 nodeMCU
to choose a ADC-capable input-pin of the ESP32
There is another thing you have to correct.
The ADC of the ESP32 are 12 bit = max-value 4095
at the lower and the upper end the onboard ADCs of the ESP32 are non -linear as you can red here
and you have to take care that an ESP32 is a 3.3V device which will be destroyed if you connect an IO-pin to voltages higher than 3.3V
best regards Stefan
As requested
exit status 1
Compilation error: 'int index' redeclared as different kind of symbol
@ruilviana
thanks that worked for that problem, but I had to change an Analog pin number from A1 to 34 as well.
Then I got this error:
exit status 1
Compilation error: invalid types 'int [9][char*(const char*, int)]' for array subscript
Thanks
This is still not the full compiler-log.
You have to activate
This code compiles on my PC with IDE 1.8.19 for board ESP32 dev module (the most general ESP32-board definition which is the dual -core
see differences here
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/hw-reference/chip-series-comparison.html
#include <arduinoFFT.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define A1 32
#define A6 33
MD_MAX72XX disp = MD_MAX72XX(MD_MAX72XX::FC16_HW, 10, 4);
arduinoFFT FFT = arduinoFFT();
double realComponent[64];
double imagComponent[64];
int spectralHeight[] = {0b00000000,0b10000000,0b11000000,
0b11100000,0b11110000,0b11111000,
0b11111100,0b11111110,0b11111111};
int myIndex, c, value;
void setup(){
disp.begin();
Serial.begin(9600);
}
void loop(){
int sensitivity = map(analogRead(A6),0,4095,50,100);
Serial.println (analogRead(A6));
for(int i = 0; i < 64; i++){
realComponent[i] = analogRead(A1)/sensitivity;
imagComponent[i] = 0;
}
FFT.Windowing(realComponent, 64, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(realComponent, imagComponent, 64, FFT_FORWARD);
FFT.ComplexToMagnitude(realComponent, imagComponent, 64);
for(int i = 0; i < 32; i++) {
realComponent[i] = constrain(realComponent[i],0,80);
realComponent[i] = map (realComponent[i],0,80,0,8);
myIndex = realComponent[i];
value = spectralHeight[myIndex];
c = 31 - i;
disp.setColumn(c, value);
}
}
best regards Stefan
@StefanL38
thank you for that, it is much appreciated, and the sketch uploaded to my esp32- wroom-da board with any problems.
I only want to connect a MAX7219 and a sound sensor to the esp32, but I'll check the connections first.
system
Closed
September 10, 2023, 9:00am
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.