Simple keyboard string read won't work on Mega

this is so simple, yet won't give me the string back.
Works perfect on a Teensy.

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

}

void loop() {
if (Serial.available () > 0 ) // receiving stuff from keyboard - Serial monitor
{ //ReadENC_Master = 0; // stop the reading
//Calc_Once = 0;
Kbd_Str = Serial.readStringUntil('\n');
Serial.println (Kbd_Str);
}

all I get is ???? instead of the string.
Please help

Thanks

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It’s barely readable as it stands. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)

—-

➜ ! Make sure your serial monitor is set at 115200 bauds and does actually send the \n (line feed) character

Maybe using a baud rate of 115200 works better than 112500.

1 Like

Yep.

Wow.

112500 of course… typed too fast

No, the error is in the presented code.

right - I did not even see that, I thought I was ton only one who typed it wrong :wink:

@OP

Can you spot looking at the following tested codes what are the mistakes you did in your sketch?

String Kbd_Str;

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

void loop()
{
  if (Serial.available () > 0 ) // receiving stuff from keyboard - Serial monitor
  { //ReadENC_Master = 0; // stop the reading
    //Calc_Once = 0;
    Kbd_Str = Serial.readStringUntil('\n');
    Serial.println (Kbd_Str);
  }
}

@GolamMostafa - coming after the party there ! :wink:

Be sure to wear double masks while in the party though the British Govt. has relaxed some restrictions.

off topic
better: be sure to get vaccinated...
/off topic

Thanks every one, 115200 did it.
I feel so silly

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