Skip to content
An Arduino library with additions to vanilla Serial.print(). Chainable methods and verbosity levels. Suitable for debug messages.
C++
Branch: master
Clone or download
Latest commit b420997 Mar 31, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples added more convinient way to set levels Mar 31, 2017
src added more convinient way to set levels Mar 31, 2017
.travis.yml added new boards to ci Aug 2, 2016
LICENSE Initial commit Feb 4, 2016
README.md Update README.md Mar 31, 2017
library.json version bump Mar 31, 2017
library.properties version bump Mar 31, 2017

README.md

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 cand find a complete example here.

2. Verbosity levels: There are four verbosity levels. The order in terms of verbosity, from least to most is 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 or you can manually enable C++11 in the configuration files.

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

You can’t perform that action at this time.