Printf not working for Due

Hello everyone,

Recently I tried to compile a friend's software for Due, and there are #includes as follows:

/* Required c++ Headers: */
#include <cmath>
#include <cstdio>
#include <cstdlib>

Then I get the compile error message:

c:\users\tz24w7\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\c++\4.8.3\cstdio:122:11: error: '::printf' has not been declared
   using ::printf;

anyone have any ideas why it wouldn't like printf?

some reading

https://playground.arduino.cc/Main/Printf/

Hi LML,

Thanks for the link - the thing I find strange is that my friend is not too software savvy and as-far-as-I-know, he did not modify the Print.h file.

Any ideas?

Thanks

Some Arduino compatible board cores have printf() enabled out-of-the-box, such as most esp8266 boards.

printf does work fine indeed on more recent architectures, probably your friend is not using a DUE or UNO or MEGA but something more "modern"

Hi JML,

We're both using Due. Do you think maybe it has to do with the level of the arduino install?

Thanks

Pretty much every 3rd party platform core provides a printf() method in their Print class. Arduino.cc board platforms are the odd man out as they still refuse to update their Print class to support it.
In the 3rd party platforms you can use:

{print-class-object}.printf(...);
i.e.
Serial.printf("hello world\n");
etc...

Here is a way you can add a function called Pprintf() to give you printf functionality in the Arduino environment using the Print class.
It works like fprintf() but instead of passing in a FILE pointer you pass in the Print class object.
i.e.
Pprintf(Serial, "Hello world\n");

It will work with any object that has Print class support including things like lcds etc...
So you can format output to them using:
Pprintf(lcd, "Hello World");

You can have this by adding this to the top of your sketch or a header file that is included:

#ifndef PPRINTF_BUFSIZE
#define PPRINTF_BUFSIZE 64
#endif
size_t Pprintf(Print &outdev, const char *format, ...)
{
char buf[PPRINTF_BUFSIZE];
	va_list ap;
	va_start(ap, format);
	vsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);
	return(outdev.write(buf));
}

Here is an example that uses it:

void setup(void)
{
	Serial.begin(115200);
	Pprintf(Serial, "Pprintf...\n");
}
void loop(void)
{
	Pprintf(Serial, "Seconds up: %04ld\n", millis()/1000);
	delay(1000);
}
1 Like

I doubt so. Ask your friend if s/he installed special stuff

Are there different versions of the board files that could change the available functions ?

For instance the latest version of the ESP32 board definitions introduced the previously unavailable analogWrite() function

Maybe just try an add-in library to determine if you can get a clean compile.
GitHub - embeddedartistry/arduino-printf: Add printf support to the Arduino SDK
You or your buddy need to get your PCs together and figure out the environment issues.

Even the ones that don't have "printf() enabled" still have printf() in their libraries (but typically its not "connected" to "Serial"), so this seems more complicated an issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.