Skip to content

An Arduino library with additions to vanilla Serial.print(). Chainable methods and verbosity levels. Suitable for debug messages.

License

Notifications You must be signed in to change notification settings

klenov/advancedSerial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

advancedSerial

This library provides some additions to vanilla Serial.print():

1. Chainable print() and println() methods:


// you can chain print() and println() methods
aSerial.print("x = ").print(x).print("y = ").println(y);

// short method names are also available
aSerial.p("x = ").p(x).p("y = ").pln(y);

You can find a complete example here.

2. Optional verbosity levels: Verbosity levels provide a convinient way to control how many messages will be printed. It is mostly suitable for debugging. There are four verbosity levels: v, vv, vvv, vvvv. You can choose at wich verbosity level a message will be printed and also set a filtering threshold. Only the masseges less or equally verbose to the treshold level will be printed. It may be easier to see this in the example:

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

  aSerial.setPrinter(Serial);
  aSerial.setFilter(Level::vv); // The filtering threshold is set to Level::vv
}

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"); 
  
  // 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.println(F("This string will be stored in flash memory"));

You can find a complete example here.

You should have Arduino IDE 1.5.8 or newer to use this library.

Public Methods

Method Short alias Description
setPrinter(Print) Print could be a hardware or software serial
setFilter(Level) Level could be one of Level::v, Level::vv, …, Level::vvvv
off() Disables the output
on() Enables the output
level(Level) v(), vv(), vvv(), vvvv() Sets the message verbosity level
print(x) p(x) The same functionality as Serial.print()
println(x) pln(x) The same functionality as Serial.println()

Tested with

  • Arduino Uno
  • Arduino Nano
  • Arduino Pro Micro
  • Arduino Mega 2560
  • Teensy 3.1
  • NodeMCU 1.0
  • Arduino Due

Similar libraries

About

An Arduino library with additions to vanilla Serial.print(). Chainable methods and verbosity levels. Suitable for debug messages.

Topics

Resources

License

Stars

Watchers

Forks

Languages