system
March 17, 2010, 7:33pm
1
Hi
I have found hard to use the simple built-in print functions, so I wrote my own. If you feel that it is usable please integrate it to the base arduino software. I have used it with Serial and Ethernet as the support nicely character by character i/o. Any other similar device can be added as easily.
The code is here
lumme.org/~marlumme/nightguard/NightGuard/The_Missing_Printf.html
None of these solutions worked for you?:
http://www.arduino.cc/playground/Main/Printf
:-?
It's always good to see alternatives, though...
system
March 18, 2010, 4:59pm
3
Yes, but I am running out or RAM. This print calls only character output.
I believe that second printf() example on the playground page will not properly handle newlines.
Here is another example of how to handle this and no longer have to worry about all the PSTR() or progmem stuff and simply use:
SerialPrintf("format string", args...)
And the format string is automagically put into FLASH instead of in RAM.
It makes printf() work like it should even in a Harvard environment.
--- bill
/*
* Define a REAL printf since Arduino doesn't have one
*
* SerialPrintf() will automatically put the format string in AVR program space
*
*/
#define SerialPrintf(fmt, ...) _SerialPrintf(PSTR(fmt), ##__VA_ARGS__)
extern "C" {
int serialputc(char c, FILE *fp)
{
if(c == '\n')
Serial.write('\r');
Serial.write(c);
return(0);
}
}
void _SerialPrintf(const char *fmt, ...)
{
FILE stdiostr;
va_list ap;
fdev_setup_stream(&stdiostr, serialputc, NULL, _FDEV_SETUP_WRITE);
va_start(ap, fmt);
vfprintf_P(&stdiostr, fmt, ap);
va_end(ap);
}