Skip to main content
1 of 5
Madivad
  • 1.4k
  • 8
  • 26

I wouldn't normally put two answers to a question, but I only just found this today, where you can use printf without any buffer. (Caveat: I haven't yet tried it, and it's not mine, refer to link above)

// Function that printf and related will use to print
int serial_putchar(char c, FILE* f) {
    if (c == '\n') serial_putchar('\r', f);
    return Serial.write(c) == 1? 0 : 1;
}

FILE serial_stdout;

void setup(){
    Serial.begin(115200);

    // Set up stdout
    fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);
    stdout = &serial_stdout;
    
    printf("My favorite number is %6d!", 12);
}

void loop() {
    
}

This still has the floating point limitation.

Madivad
  • 1.4k
  • 8
  • 26