Go Down

Topic: Adding an AVR library (ffft, suart) (Read 19349 times) previous topic - next topic


Following a link given in this post, I have found an FFT library for Atmega* chips. However, I just don't know how to install it so I can use it in my Arduino scripts.

The files, available here in a zip file, contain the following files:


J. S.


It should be possible, but it's not as easy as it could be due to some current limitations of the Arduino software (that have been pointed out, so they should have been fixed - sorry about that).  You'll probably need to compile the code manually, at the command line.  You can do this with avr-gcc, which is included in the Arduino distribution.  The command is something like:

Code: [Select]

avr-gcc -mmcu=atmega168 -c ffft.S
avr-gcc -mmcu=atmega168 -c suart.S

(but avr-gcc needs to be in your path - it's in the tools/avr/bin subdirectory of your Arduino application directory).  Once you've done that, you can copy the .o files and the .h files to a new subdirectory (called ffft) of the lib/targets/libraries subdirectory of the Arduino application directory.  Then, you should be able to go to the Sketch > Import Library menu and select ffft, which will add the appropriate #include's to your sketch.  You'll also need to add:

Code: [Select]
#include <avr/pgmspace.h>

as the first line of your sketch (above the other includes).  I got it to compile by doing that, but didn't try actually using the library.  Also, if you only need the ffft functions and not the software uart (for debugging), you can get rid of suart.h and suart.h.


Hi tatien,

did you manage to get it working?
I am trying to include it in my project too but with no luck so far.


I haven't really been touching it again, sorry.


Hey guys,

I have been trying to compile under Windows XP and the compiler tells me to use cygwin.

Can I compile from a Windows environtment ?

And, if not, did anyone get the FFT library to work?

Thanks a lot


To run avr-gcc from the command prompt in windows, the current directory needs to have the cygwin dll's in it.  These are included in the root directory of the Arduino application.  You can either cd to that directory, or copy the .dlls to the directory you're compiling from.


To run avr-gcc from the command prompt in windows, the current directory needs to have the cygwin dll's in it.

It will also work if the dll directory is in your PATH, IIRC.



hello everybody.

i'm stuck with the same problem.
i figured out myself how to get ffft.h and fft.o to be an arduino library.
but on compile, when i actually reference the methods (fft_input, fft_execute & ffft_output), the compiler complains about undefined references.
i think the problem is, that the object file (ffft.o) isn't correctly linked.

someone has a fix for that?



no good news.

i'm trying to use the FFT in my project, similarly to what was done in the main.c example code included in the avr-fft library.
i'm currently trying to use a 512 points fft over a signal coming from preamp/mic mapped to arduino analogInput. Since i've got atmega328p chip, i've succesfully compiled avr-fft lib with this option:

Code: [Select]

avr-gcc -mmcu=atmega328p -c ffft.S

in practical words, what i'm trying to do is like:

Code: [Select]
static uint16_t i=0;
 while (i < NUM_SAMPLES) {
   sound = analogRead (MIC);
   int16_t adc_val = (int16_t) sound;
   capture [i] = (int16_t) adc_val;

   fft_input((int16_t)capture, bfly_buff);

the compiler fails with:


In function 'void loop()':
error: invalid conversion from 'int16_t' to 'const int16_t*'

If i do not cast capture to int16_t while passing it to fft_input(), i get this other error:

In function `loop':
undefined reference to `fft_input(int const*, _tag_complex_t*)'

By this way fft_input seems to misunderstood the "capture" parameter...

No way out from this problem.

Any suggestions?




Here is a suggestion for you. Rename ffft.S to ffft.cpp.S and compile it as suggested above and see if the error goes away.

I converted ffft.S to the gcc inlined assembly conventions. After finally getting it to compile in arduino as a library, I ended up getting the same undefined function error in the Arduino IDE!

Eventually, I renamed my library from ffft.c to ffft.cpp and the error went away and it compiled! I suspect arduino is telling the linker to look for .cpp.o files. Thus, if you do as I suggest above, it may link correctly.

While I've managed to get my assembly inlined version to compile, I haven't been able to verify it works yet. I'll post to code as soon as I get it working.


P.S. If you want the possibly non-working code before then, shoot me a PM with your email and I'll toss it your way.


Hello everybody,

any news regarding the code, I'm getting same error...


Aug 22, 2010, 11:31 am Last Edit: Aug 22, 2010, 11:35 am by amurchick Reason: 1
I compiled fft!

Arduino IDE compile as C++, asm files generated in "C"!
From "C" to C++ there are difference in function naming in .o files!

Workaround in ffft.h:
Code: [Select]
#ifdef INPUT_IQ
void fft_input (const complex_t *, complex_t *);
extern "C" { void fft_input (const int16_t *, complex_t *); }
extern "C" {
void fft_execute (complex_t *);
void fft_output (complex_t *, uint16_t *);
int16_t fmuls_f (int16_t, int16_t);

Thanks to Coding Badly http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282393804

p.s. Create dir in arduino\libraries\ and copy into ffft.h and ffft.S, in main module enough #include <ffft.h>



thanks AMurchick for your reply, I did as you suggested but still I'm getting error:
 invalid conversion from 'int16_t' to 'const int16_t*'.
at line:
 fft_input((int16_t)capture, bfly_buff);

I tried add * or
  • or & but no luck. Can you help?


Aug 24, 2010, 04:13 am Last Edit: Aug 24, 2010, 04:14 am by amurchick Reason: 1
How you define capture?
In original sources defined as:

Code: [Select]
int16_t capture[FFT_N];                  /* Wave captureing buffer */
complex_t bfly_buff[FFT_N];            /* FFT buffer */
uint16_t spektrum[FFT_N/2];            /* Spectrum output buffer */


Exactly like you:

int16_t capture[FFT_N];            /* Wave captureing buffer */
complex_t bfly_buff[FFT_N];            /* FFT buffer */
uint16_t spektrum[FFT_N/2];            /* Spectrum output buffer */

Go Up