Debug and control Arduino sketches from the Serial Monitor.
Set variables, watch live values, and list commands — without scattering Serial.print calls through your firmware.
- Set sketch variables from Serial (
temp 23.4) - Show / stop live monitoring of values (
sensors show) - Built-in help listing for all registered commands
- Templated
set()/print()— works withint,float,String, and other numeric types "..."_fPROGMEM labels (same idea asF("..."), less noise)println(...)to dump several fields on one line
Arduino Library Manager: search for CmdSerial, or install from ZIP / clone into your libraries folder:
git clone https://github.com/fire1/CmdSerial.gitThen restart the Arduino IDE.
#include <CmdSerial.h>
CmdSerial cmd;
int testInt = 0;
float temperature = 21.5;
void setup() {
Serial.begin(9600);
}
void loop() {
cmd.listen(); // required every loop
cmd.set("test"_f, testInt, "Set the test integer"_f);
cmd.set("temp"_f, temperature, "Set temperature"_f);
if (cmd.show("test"_f, "Monitor testInt"_f)) {
cmd.print("Test value:"_f, testInt);
}
if (cmd.show("sensors"_f, "Print several values"_f)) {
cmd.println("temp"_f, temperature, "test"_f, testInt);
}
}Open the Serial Monitor (newline ending). Try:
| Command | Effect |
|---|---|
help |
List all commands |
test help |
Help for one command |
test 12 |
Set testInt to 12 |
temp 23.4 |
Set temperature |
test show |
Start monitoring |
test stop |
Stop monitoring |
sensors show |
Print several fields each interval |
#include <CmdSerial.h>
CmdSerial cmd; // uses Serial by default
// CmdSerial cmd(Serial1); // or any StreamCall cmd.listen() once per loop().
float temperature;
if (cmd.set("temperature"_f, temperature, "Board temperature"_f)) {
// optional: ran only when a new value was applied
}Serial input: temperature 21.5
set() works with numeric types and String. Confirmation messaging can be disabled with a fourth argument: false.
if (cmd.show("data"_f)) { // every 500 ms while active
cmd.print("Output"_f, testInt);
}
if (cmd.show("banana"_f, "Help text"_f, 1000)) { // custom interval
cmd.print("Banana"_f, banana);
}name show— start printing on the intervalname stop— stop
cmd.print("label"_f, value); // one line: label <sep> value
cmd.println("temp"_f, temperature, "hum"_f, humidity); // several fields on one line"Hello"_f keeps the text in flash on AVR, like F("Hello"):
cmd.print("Test value:"_f, testInt);
// same as:
cmd.print(F("Test value:"), testInt);| Input | Result |
|---|---|
help |
Lists every set / show command registered in the sketch |
<name> help |
Help text for that command |
Default separator is space; end of line is \n.
| Keyword | Role |
|---|---|
show |
Start monitoring |
stop |
Stop monitoring |
help |
List or describe commands |
Override via macros before including the header (CmdSerial_KeywordShow, CmdSerial_ShowTime, …) — see src/CmdSerial.h.
Wokwi playground — type help in the terminal.
Full API: docs/api.md
MIT — see LICENSE.txt.