Arduino IDE 2.0.0-rc9: Input in Serial Monitor is not working

I am using Arduino Due in windows 11. In my code, I have to give some input in the serial monitor to run the sketch, but when I provide the desired input and press Ctrl+Enter, input data is not getting accepted by the code. Am I doing something wrong?

Everything works perfectly when I do the same thing without any change in IDE 1.8.19. Is it a bug or am I doing something wrong?

I welcome any suggestion.

Post your code (using code tag </>) so others can read it and help you.

It seems to be a bug, have you tried the IDE example?

I seem to experience the same problem as @anon78116600. Serial Monitor does receive data but does not send; the Rx LED on the Nano does not flash.

I type a character in serial monitor and press <enter>, no reaction. I notice that there is no send button as in the 1.8.x version but that might have been the case with all IDE 2.0 versions.

This applies to both RC8 and RC9; I've just deleted older versions :frowning: so can't check.

"Installations" are ZIP versions. Code works as expected in 1.8.5.

Code is irrelevant but just in case

bool f01();
bool f02();
bool f03();
bool f04();
bool f05();
bool f06();
bool f07();
bool f08();


struct SWITCHES
{
  bool (*f[8])(void);
};

SWITCHES switches =  //
  {
    { f01, f02, NULL, f04 },
  };

void setup()  //
{
  Serial.begin(115200);
  Serial.println("Hello");
}

void loop()  //
{
  if (Serial.available())  //
  {
    char ch = Serial.read();
    Serial.print("received ch = ");
    Serial.write(ch);
    Serial.print(" > ");
    if (ch >= '0' && ch <= '9')  //
    {
      if (switches.f[ch - '0'] != NULL)
        switches.f[ch - '0']();
      else
        Serial.println("Not implemented");
    }
  }
}

bool f01()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f02()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f03()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f04()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f05()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f06()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f07()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

bool f08()  //
{
  Serial.println(__FUNCTION__);
  return true;
}

// Edit:
PS
Win 10 Home

Hi @sterretje. Unfortunately the established Enter is not currently supported by the Arduino IDE 2.x as a send trigger. You must use Ctrl+Enter instead.

This issue is being tracked by the Arduino IDE developers here:

If you have a GitHub account, you can subscribe to that issue to get notifications of any new developments related to this subject.

If you have any problems with the Serial Monitor when using the current Ctrl+Enter keyboard shortcut, please do let us know. I am interested in investigating the problem reported by @anon78116600, but there is currently not sufficient information in the report for me to be able to proceed with that.

This is being tracked by the Arduino IDE developers here:

That is correct.

Thanks a lot; it's working. I think that somewhere I knew about the <ctrl><enter> but did forget :frowning: Ah, found it, the text in the input field. I'm so embarassed :man_facepalming:

FYI, I do not miss the <send> button.

I had the same confusion when I started using the new IDE. It is true that the placeholder text explains it, but that text disappears as soon as you start typing in the field. I didn't bother to read it in advance, and then it wasn't there to read once I needed it.

Interesting. I'm not sure how I feel about it. I think that it does exacerbate the poor user experience resulting from the unintuitive change to the keyboard trigger. It might be that once the standard keyboard trigger is restored we will find that the Send button is superfluous.

You can see that the designer did choose to add a Send button to the Arduino IDE 2.x Serial Plotter:

image

The Serial Plotter design is fairly finalized, while the current Serial Monitor design is more of a placeholder with plans to completely redesign it in the near future.

I was trying Ctrl + enter but no success in IDE 2.0. I tried some other codes only to try user input, that worked. Below is my code part which is working perfectly alright in IDE 1.8.19:

  Serial.println("Insert the y position:");
  while (k == 0) {
    Kin2 = Serial.readStringUntil('\n');
    if (Kin2 != "") {
      k = 1;
      y1 = Kin2.toDouble();
    }
  }

Hope this will help to investigate the problem further.

I've tested your snippet with below code in RC9 and it works.

void setup() {
  Serial.begin(115200);
}

void loop() {

  static int k = 0;

  while (k == 0) {
    Serial.println("Insert the y position:");
    String Kin2 = Serial.readStringUntil('\n');
    if (Kin2 != "") {
      k = 1;
      float y1;
      y1 = Kin2.toDouble();
      Serial.println(y1);
    }
  }
}

I have some doubts that this is an IDE2.0 issue.

Thanks for checking. I also tried the above code you posted and it worked iDE 2.0!

But surprisingly, inside my whole code, it is still working in 1.8.19 and not in IDE 2.0 rc9.

Let me do some checks and get back to you.

I think the issue in my case is I am trying to get user input once and this is an input that should work with other setup parameters in void setup(). And it is not working under the setup(). Will there be any change in the code if I want to use it in setup()?

@sourkarm2, can you post a minimal example so I can check. Which board are you using?

I am using Arduino due. I tried both way ( putting user input in setup() and loop()), none of them worked in IDE 2.0 rc9.2 (with Ctrl + [Enter]), but working perfectly in IDE 1.8.9. (with [Enter]). I tried on multiple computers with Windows 11, same issues.

int ans = 0;
int usrAns = 0;
String userAns;

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
    Serial.println("Go to Home Poisition? (0 = No; 1 = Yes) [0/1]: ");
    while (ans == 0) {
      userAns = Serial.readStringUntil('\n');
      if (userAns != "") {
        ans = 1;
        usrAns = userAns.toInt();
        Serial.println(usrAns);
      }
    }
}

The other code is:

int ans = 0;
int usrAns = 0;
String userAns;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Go to Home Poisition? (0 = No; 1 = Yes) [0/1]: ");
  while (ans == 0) {
    userAns = Serial.readStringUntil('\n');
    if (userAns != "") {
      ans = 1;
      usrAns = userAns.toInt();
      Serial.println(usrAns);
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

Not behind a PC to check the behaviour of your code but readStringUntil does not return an int.

For a Due, you might want to implement while(!Serial); after Serial.begin() if you don't want to miss the first text that you send.

Hi @anon78116600. I think the problem will become clear with this more simplified sketch:

void setup() {
  Serial.begin(115200);
}

void loop() {
  if(Serial.available()){
    String userAns = Serial.readStringUntil('\n');
    Serial.print("string: ");
    Serial.println(userAns);
    Serial.print("int: ");
    Serial.println(userAns.toInt());
  }
}

I get this output in Serial Monitor at 1 Hz when I don't provide any input:

string: ▯▯
int: 0

This results from a known bug in the Arduino IDE 2.x Serial Monitor, which is being tracked by the developers here:

Depending on the timing, you might get this spurious data in addition to the intentionally sent data. For example sending a '1' might result in this:

string: ▯▯1
int: 0

Note that even though I sent a '1', the extra garbage caused userAns.toInt() to return 0.

Something I should mention is that the rectangles ( .notdef glyph?) seen in the Serial Monitor output disappear when you copy and paste that text to a post on the Arduino forum. I actually replaced them with equivalent visible characters in my post above in order to accurately represent the text in the Serial Monitor.

This screenshot shows the actual Serial Monitor contents:

image

Thank you @ptillisch for explaining the issue. I suspected from the very beginning that it is a bug and your details made my suspicion confirmed.

'Hope in the final release, this issue will be corrected.

You are welcome. I also hope to see this issue resolved.

Regards, Per

The final version 2.0 has been released. but surprisingly, the ISSUE IS STILL EXISTING!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.