How to make serial.read work in the serial monitor?


#1

Hi,

I can’t make serial.read work in the serial montor, as in:

  if ( Serial.available() > 0) {
    char c = Serial.read();

    if ( c == 'i') { mode = INSERT; printMenu();}
    if ( c == 'd') { mode = DELETE; printMenu();}
    if ( c == 'n') { mode = NORMAL; printMenu();}
  }

This works in the Aduino IDE monitor as expected. In the PlatformIO monitor all keyboard input seems to be ignored.

Am I overlooking something here?

Dennis


#2

I know you need some patience here, but two weeks is a long time… There must be someone with a little more experience here.


#3

Do you use correct baudrate?


#4

Yes, of course. Otherwise the other print statements would not come true, like printing the menu.

So you’re stating this normally should work as designed.


#5

Tried another simple example piece of code:

#include <Arduino.h>

void setup()
{
  Serial.begin( 9600);
  Serial.println( "Ready for input");
}

void loop()
{
  char c;

  if ( Serial.available() > 0) {
    c = Serial.read();

    Serial.print  ( "Char = ");
    Serial.println( c, DEC);
  }
}

First println is shown correctly, nothing happens after that, no matter what key I press.

Am I the only one again?


#6

What is your operation system?


#7

Currently Windows 10 x64


#8

Just found out that ctrl-C to stop the serial monitor stream does not work as well. I think it is connected to my other problem.

Any new thoughts (apart from re-installing everything)?