Listen to the serial port

Dear everyone How can I use the serial monitor to read some data I want to use in my programme?
Where I can input data?
thanks


const int BUFFER_SIZE = 100;
char buf[BUFFER_SIZE];

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // check if data is available
  if (Serial.available() > 0) {
    // read the incoming bytes:
    int rlen = Serial.readBytesUntil('\n', buf, BUFFER_SIZE);

    // prints the received data
    Serial.print("I received: ");
    for(int i = 0; i < rlen; i++)
      Serial.print(buf[i]);
  }
}

There’s no final Serial.println() or Serial.flush() after this?

The serial monitor opened via the monitor task will do just fine. Data is by default not echoe by the terminal.

1 Like