This is the best forum I could think of to post this... mods please move it if necessary.
Anyway, a lot of us know about the linker options to allow using native floating point support in Arduino sketches.
The method is to add this to the compiler/linker command line string:
-Wl,-u,vfscanf,-lscanf_flt,-u,vfprintf,-lprintf_flt
On a hunch, I wondered if the entire thing was needed for simply using printf with floats. For example, I always do this:
fprintf (stdout, "Output: %6.2f volts DC\n", volts);
which might print something like this:
[b]Output: 7.45 volts DC[/b]
but, I rarely, if ever, use the SCANF/FSCANF functions, so I wondered if the linker option line could be simply:
-Wl,-u,vfprintf,-lprintf_flt
Turns out, it can and it works and it uses a lot less memory.
Testing it with this sketch:
int main (void)
{
init ();
char buffer [32];
Serial.begin (115200);
sprintf (buffer, "Output: %6.2f Volts DC\n", 123.45);
Serial.print (buffer);
while (1);
}
With both printf and scanf floating point options turned off, the sketch uses 8008 bytes and, of course, prints this:
** **Output: ? Volts DC** **
With the SCANF option only enabled, it uses 10758 bytes and also prints this:
[b]
Output: ? Volts DC[/b]
With the PRINTF option only enabled, it uses 9596 bytes and prints this:
** **Output: 123.45 Volts DC** **
With BOTH enabled, it uses 12348 bytes and prints this:
** **Output: 123.45 Volts DC** **
So, if you ONLY need floating point PRINTING, you can enable only the "fprintf" part and save quite a bit of flash memory since it seems that the FSCANF support part uses the most memory!
The printf support uses about 1588 extra bytes, the scanf support uses about 2750 more bytes (!!!) and together they use 4338 more bytes.
1588 bytes versus 4338 bytes is a heck of a savings!
For what it's worth.......