void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial);
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
String code = Serial.readStringUntil('f');
Serial.print(code);
}
}
this is the simplified code I've been trying to debug . Right now, I've been directly typing the strings for serial reading into the Serial Monitor (e.g. "yesf", "nof" without the quotation marks) and there have been no error messages, yet nothing is printed out on the serial monitor when my text is sent. Anyone know what the problem is? Help would be much appreciated .
You are checking the serial input many thousands of times a second so a read until is not going to work. Each time you do a read you loose it from the buffer so there is only ever one character you are extracting.
Hi @20tongy1 welcome to the forum.
Sorry for the confusion, both UKHeliBob and Grumpy_Mike are wrong.
First of all, your sketch does not compile.
Can you put your sketch between code tags ?
One way is with three backslash-single-quotes or the </> button.
```
Your sketch
```
Another way is to use the Arduino IDE.
Press Ctrl+T to format the text of your sketch (or in the menu: Tools / Auto Format)
Then menu: Edit / Copy for Forum
and paste it in a post here.
We don't use the readStringUntil and similar functions. It is not clear what they do and it is not fully documented. Sometimes there is a CarriageReturn or LineFeed or both at the end of a line, those function do not deal with those. Some of those function fill a buffer, but it is not defined if the result will be a zero-terminated buffer.
The OP needs to remember that: 1. The Arduin sketch has two seperate functions as shown below; whereas, his posted sketch does not comply with it. The sketch what he has posted is given in Step-2.
void setup()
{
}
void loop()
{
}
2.
void setup()
{
void loop()
{
}
3. The function that he has used to read string from the InputBox of Serial Monitor is:
String code = Serial.readStringUntil('f');
4. The argument of the functio/method of Step-3 should be a terminating charcater which preerably be one of the control charcaters. Most of the users like the Newline ('\n') charracter at the Line ending tab of the Serial Moniotr (Fig-1 of Step-5). So, the correct version of the code of Step-3 would be: