Skip to content

Instantly share code, notes, and snippets.

@alw1746
alw1746 / Serial_printf.h
Last active October 5, 2023 03:14 — forked from ridencww/SerialPrintf.txt
Basic printf functionality for the Arduino serial ports
/* https://gist.github.com/ridencww/4e5d10097fee0b0f7f6b
* Simple printf for writing to an Arduino serial ports eg. Serial..Serial3. Note: format
* specifier must match actual argument type eg. int32 should be formatted as %l, not %d.
* Usage: Serial_printf(Serial,"%d\n",vars);
* %B binary (d = 0b1000001) %b binary (d = 1000001) %c character (s = H)
* %d/%i integer (d = 65) %o boolean on/off (d = On) %% escaped percent ("%")
* %f float (f = 123.45) %.3f/%3f float (f = 123.346) %l long (d = 65)
* %s char* string (s = xyz) %X hexadecimal (d = 0x41) %x hexadecimal (d = 41)
* For more float formats, dtostrf(float_value, min_width, num_digits_after_decimal, where_to_store_string)
eg. dtostrf(fpvalue,8,3,fpstr);