Is there a simple, easy way to modify an Arduino ino file to use existing C libraries that have printf or sprintf statements, without the need to replace those printf and sprintf statements with Serial.print?
Maybe a setup command(s) that directs the sprintf string or the printf stdout to the Serial class.
My research so far has discovered formatting issues with printf and sprintf, but not an answer to my question.
sprintf() is available by default. There is no file system on Arduino, so no stdout, unless you use the workarounds in AVRlibc. In that case you can direct printf() to the serial port.
sthudium:
Is there a simple, easy way to modify an Arduino ino file to use existing C libraries that have printf or sprintf statements, without the need to replace those printf and sprintf statements with Serial.print?
Maybe a setup command(s) that directs the sprintf string or the printf stdout to the Serial class.
My research so far has discovered formatting issues with printf and sprintf, but not an answer to my question.
We don't know what core is being used. It could be AVR but it might not be.
The i/o hooks needed to get a printf() to work for each core are different.
sthudium:
Hi bperrybap, I'm using a Zero. But, I would prefer a universal sol'n.
This library uses standard LIBC functions so it should work with any Arduino microcontroller (although I have not tried it with a Zero). It does work on an Arduino DUE (SAM3X8E based) and, of course, any AVR.
This library fixes some mistakes in the stock Arduino print as well as adding extra functions to support printing from flash or eeprom, and sends a "CR/LF" sequence for printing the variable type CHAR which allows PRINT (and PRINTF) to use the standard "string_of_text\n" sequence rather than "string_of_text\r\n" currently required.
Note that the CR is only added for the CHAR type... other writes go straight through as they are supposed to.
This library uses standard LIBC functions so it should work with any Arduino microcontroller (although I have not tried it with a Zero). It does work on an Arduino DUE (SAM3X8E based) and, of course, any AVR.
The examples in Stdinout don't compile for me using IDE 1.8.5 on any core I tried, AVR, SAM, SAMD, chipkit, esp8266.
There are issues with the use of Stream vs Print class.
Even after the compile issues are resolved, I'd be surprised if it would work on anything but AVR given it ties into the AVR specific fdev stuff.
While I have gotten printf() to work on various cores in the past, it required doing core specific things and creating core specific i/o functions.