[Arduino framework] vsnprintf does not generate expected output

Hi all,
I’m trying to write a simple wrapper around ‘Serial.print’ so I can easily disable all my output messages in one go. I was also creating something a bit more powerful that would allow for multiple arguments.

I created this:

#define DEBUG_LOG(msg, ...) MsgOutImpl(msg, ##__VA_ARGS__)

void MsgOutImpl(const char* msg, ...)
    char buff[256];
    va_list argptr;
    va_start(argptr, msg);
    vsnprintf(buff, 256, msg, argptr);

Now, it seems to work fine for most things, however I was trying to print out float values and the output is a ‘?’.
So doing DEBUG_LOG("%f", 12.0f) will print ‘?’.

Target platform is: nanoatmega328new

Any ideas what may be going on here?

Floating point support depends on the used C library and flags. Without knowing the platform you’re compiling for (ststm32?) we cannot suggest a solution.

Ah sorry about that. This is targeting ‘nanoatmega328new’.

As discussed in https://blog.startingelectronics.com/floating-point-numbers-dont-print-sprintf-atmel-studio-avr-c/, you can see that you need to add

build_flags = -Wl,-u,vfprintf -lprintf_flt

to the platformio.ini to enable floating point printf support.

Got it, I’ll give it a go this evening.
Thanks a bunch.