So I am trying to implement a fast hartley transform that I found online for the Arduino. I am trying to call an array from the library in my code directly below, from the program from the website. I am getting an out of scope error. It was working before, and I could have sworn that I didn't change anything, but for some reason it has trouble finding the scope of the variable now. I am programming using the Arduino uno.
It cannot find the scope for the array fht_lin_out. I tried to copy the code for FHT that I downloaded from the website onto here, but it is too many characters to fit.
Note: That A-weighting table is not being used right now so you can ignore that.
#include <FHT.h>
/*
fht_adc.pde
guest openmusiclabs.com 9.5.12
example sketch for testing the fht library.
it takes in data on ADC0 (Analog0) and processes them
with the fht. the data is sent out over the serial
port at 115.2kb. there is a pure data patch for
visualizing the data.
*/
#define LIN_OUT 1 // use the log output function
#define FHT_N 256 // set to 256 point fht
// this is the A-Weighting Table for 8 Hz resolution and 256 samples.
long weightTable[128] = {};
// array that will output A-weighted values
long weightedValues[128];
// sets up the serial port
void setup()
{
Serial.begin(9600); // use the serial port
}
void loop()
{
while(1)
{
// reduces jitter
int sum = 0;
// UDRE interrupt slows this way down on arduino1.0
cli();
// save 256 samples
for (int i = 0 ; i < FHT_N ; i++)
{
delay(.00048828);
int k = analogRead(A0);
sum = sum + k;
fht_input[i] = k;
}
// calculates DC bias
int average = sum / 256;
// subtract DC bias from each bin
for ( int j = 0; j < FHT_N ; j++)
{
int k = fht_input[j];
fht_input[j] = k - average;
}
// FHT Functions
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_lin(); // take the output of the fht
sei();
// show me da values
for( int j = 2 ; j < 128 ; j++)
{
//send out the data
Serial.println(fht_lin_out[j]);
}
// stops the program after first aqusition (basically)
delay(10000000000);
}
}
So, by default, the array is not defined.
If you expect to use the array, you need to make sure that it is defined.
Hi thank you for your response. At the top of my code, I define.
#define LIN_OUT 1 // use the log output function
It worked perfectly before. I just recopied the actual programs reference code that worked perfectly before (and SHOULD work perfectly) into my arduino and I am getting the same error. This is very odd.
So I went into the actual FHT program itself and changed the LIN_OUT variable to 1 and tried to run it.
This is the error I got:
Arduino: 1.6.3 (Mac OS X), Board: "Arduino Uno"
FHT_Coming_Together.cpp.o: In function `fht_mag_lin':
/Users/hongjiang/Documents/Arduino/libraries/FHT/FHT.h:1014: undefined reference to `fht_lin_out'
/Users/hongjiang/Documents/Arduino/libraries/FHT/FHT.h:1014: undefined reference to `fht_lin_out'
/Users/hongjiang/Documents/Arduino/libraries/FHT/FHT.h:1014: undefined reference to `_lin_table'
/Users/hongjiang/Documents/Arduino/libraries/FHT/FHT.h:1014: undefined reference to `_lin_table'
FHT_Coming_Together.cpp.o: In function `loop':
/Users/hongjiang/FHT_Coming_Together.ino:74: undefined reference to `fht_lin_out'
/Users/hongjiang/FHT_Coming_Together.ino:74: undefined reference to `fht_lin_out'
/Users/hongjiang/FHT_Coming_Together.ino:92: undefined reference to `fht_lin_out'
/Users/hongjiang/FHT_Coming_Together.ino:92: undefined reference to `fht_lin_out'
/Users/hongjiang/FHT_Coming_Together.ino:95: undefined reference to `fht_lin_out'
FHT_Coming_Together.cpp.o:/Users/hongjiang/FHT_Coming_Together.ino:95: more undefined references to `fht_lin_out' follow
collect2: error: ld returned 1 exit status
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Ok thanks. Additionally I completely deleted and reinstalled my libraries folder, put the FHT library back in, tried to run the reference code and it is still giving me an error of accessing a variable in the FHT program.
Arduino: 1.6.3 (Mac OS X), Board: "Arduino Uno"
Test_Reference.ino: In function 'void loop()':
Test_Reference.ino:45:18: error: 'fht_log_out' was not declared in this scope
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Ok so I kind of figured out the issue. I am not very familiar with Arduino, I'm a newbie, but building the code from the ground up, it all works out fine until I introduce the weight table that I put in my code that has like 128 longs. This is too much information for the Arudino to store and I'm assuming that interferes with my ability to use the FHT library.
Issue is that even after I delete the array, it still doesn't recognize the variable. Weird. Is it some offhand effect of overloading the memory of the Arduino?
Then it again, it seems to be an issue with the compiler, because even when I don't have the arduino plugged in, it still doesn't recognize the variable.