How to input through serial monitor

hello, I just changed to platformio, and i dont get how i can interact through the serial monitor. I want to test functions by calling them, but i cant find the input windows. I know there are other threads on this topics but i dont get it.

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readString();

    if (command == "sleep") {
      Serial.println("Cell is sleeping");
    } else if (command == "start") {
      Serial.println("Cell started");

Please note that the new line character (\n = Ascii Code 10) is also read in with ReadString()!
You will therefore not only receive “start” but “start[\n]” (Ascii codes: 115,116,97,114,116 and 10 for the new-line character)

Solution: Use readStringUntil('\n')

By default, PlatformIO’s serial monitor sends the characters over serial as soon as you type each letter. If your program is written to expect the serial input “all at once” without much delay, then you can just configure the serial monitor to only send something when you press enter.

See docs for the platformio.ini:

monitor_filters = send_on_enter

And indeed you will need to strip any newlines in the command string.

1 Like

Thanks for the reply, but i´m allreay struggling one step ahead, where can i input my string in the first place? I guess its normaly obvious, but i just cant find it. In the arduino ide, there is a input field above the sm.

ok thanks, i will try

It worked thanks. I was confused, because it didn’t show the string in the terminal, when i typed it in.

The serial monitor does not echo back the typed characters by itself. For that you’d have to add monitor_echo = yes (docs).