I found a nice library, advancedSerial, for debug printing to the Serial Monitor port. I’ve tested it successfully in both VSCode (250k baud) and the Arduino IDE (500k baud) and printing in the Serial Monitor.
I’m still looking into other alternatives. I’d still like a printf-like solution that supports Flash properly and does not become a memory hog (e.g. format strings).
You can add it to the Arduino IDE via “Include Library” (which will be picked up by VSCode). It works well with the existing Blinks ServicePortSerial class, and it supports using Flash for text strings, chaining method calls, as well as controlling what’s displayed quite easily!
Here’s an example (I modified one that comes with the library so it uses the ServicePortSerial Print class and demonstrates chaining too):
#include “Serial.h”
#include “advancedSerial.h”advancedSerial aSerial;
ServicePortSerial sp;void setup() {
sp.begin(250000); // kenj: mod to support 250k baud for VSCode// Specify to use our SerialPortMonitor
aSerial.setPrinter(sp);aSerial.setFilter(Level::vv);
/* Uncomment the following line to disable the output. By defalut the ouput is on. */
// aSerial.off();
}void loop() {
// This message will be printed
aSerial.v().println(“Level v() is less verbose than the filtering threshold”);// This message also will be printed
aSerial.vv().println(“Level vv() is equal to the filtering threshold”);// Chaining calls
aSerial.v().p(“Level v() using shortened name”).p(" and chaining").p(" multiple prints");// This message won’t be printed
aSerial.vvv().println(“Level::vvv is more verbose than the filtering threshold”);// This message won’t be printed
aSerial.vvvv().println(“Level::vvvv is more verbose than the filtering threshold”);// Consider storing long strings on flash memory rather than RAM using F() macro
aSerial.v().pln(F(“This string will be stored in flash memory”));// Two empty lines
aSerial.v().println().pln();}