user63258: I am using the library SerialCommands and I am just trying to print the first text message in the Serial Monitor. But this code does not work for some reason.
The expected result is that the Serial monitor prints a message ("Hello world !!") when I write "hello" and press "enter" as input. Is there something wrong or is this not working like I was expecting? Is there another way to check if these commands work? Is there anythin that I am missing?
#include <SerialCommands.h>

char serial_command_buffer_[32];
SerialCommands serial_commands_(&Serial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", ",");

void cmd_hello(SerialCommands* sender) {
  sender->GetSerial()->println("Hello world !!");
}

SerialCommand cmd_hello_("hello", cmd_hello);

void cmd_unrecognized(SerialCommands* sender, const char* cmd) {
  sender->GetSerial()->print("ERROR: Unrecognized command [");
  sender->GetSerial()->print(cmd);
  sender->GetSerial()->println("]");
}

void setup() {
  Serial.begin(9600); // Serial comm begin at 9600bps
  serial_commands_.AddCommand(&cmd_hello_);
  serial_commands_.SetDefaultHandler(&cmd_unrecognized);
  Serial.println("Ready");
}

void loop() {
  serial_commands_.ReadSerial();
}


user42015: You defined, that every command will end with \r\n. So you need to choose "Both NL & CR" as line ending in the Serial monitor, so that it appends the line ending to your command. If you don't send the correct line ending, the library will think, that the command hasn't finished yet, and thus will do nothing, until it receives the correct line ending.

63258: <p>I am using the library <a href="https://github.com/ppedro74/Arduino-SerialCommands" rel="nofollow noreferrer"><strong><code>SerialCommands</code></strong></a> and I am just trying to print the first text message in the Serial Monitor. But this code does not work for some reason.</p>

<p>The expected result is that the Serial monitor prints a message ("Hello world !!") when I write "hello" and press "enter" as input. Is there something wrong or is this not working like I was expecting? Is there another way to check if these commands work? Is there anythin that I am missing?</p>

<pre><code>#include &lt;SerialCommands.h&gt;

char serial_command_buffer_[32];
SerialCommands serial_commands_(&amp;Serial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", ",");

void cmd_hello(SerialCommands* sender) {
  sender-&gt;GetSerial()-&gt;println("Hello world !!");
}

SerialCommand cmd_hello_("hello", cmd_hello);

void cmd_unrecognized(SerialCommands* sender, const char* cmd) {
  sender-&gt;GetSerial()-&gt;print("ERROR: Unrecognized command [");
  sender-&gt;GetSerial()-&gt;print(cmd);
  sender-&gt;GetSerial()-&gt;println("]");
}

void setup() {
  Serial.begin(9600); // Serial comm begin at 9600bps
  serial_commands_.AddCommand(&amp;cmd_hello_);
  serial_commands_.SetDefaultHandler(&amp;cmd_unrecognized);
  Serial.println("Ready");
}

void loop() {
  serial_commands_.ReadSerial();
}
</code></pre>
 42015: <p>You defined, that every command will end with <code>\r\n</code>. So you need to choose "Both NL &amp; CR" as line ending in the Serial monitor, so that it appends the line ending to your command. If you don't send the correct line ending, the library will think, that the command hasn't finished yet, and thus will do nothing, until it receives the correct line ending.</p>
