Skip to content

Problem with Serial.available() and while(!Serial); #2123

Closed
@ffissore

Description

@ffissore

The following "echo sketch" does not work as expected after #1953

void setup() {
  Serial.begin(9600);

  while (!Serial);
}

void loop() {
  if (Serial.available()) {
    Serial.print('-');
    Serial.print(Serial.read());
    Serial.print('-');
  }
}

It should print the code of each character given as input, sorrounded by two hyphens.
When started, you should see a blank IDE serial monitor. As soon as you type something, like "a", you should see printed
-97--10- (when using new line as line terminator)

Instead serial monitor will immediately display -0-, like I had given the null char as input.

Commenting line while (!Serial); prevents the error from happening.

This has been verified with a yun and with a leonardo

/cc @pbrook @embmicro @cmaglie

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions