serial.find()

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

{
  if(Serial.available()>0)
{
  char a=Serial.read();
  boolean b= Serial.find("aa");
  if(b)
  Serial.println("found");}}

is this way of using serial.find.if not help me plzzz

RTFM? Stream.find() - Arduino Reference

I don't think that you need to check serial available for serial find but if you do then make sure there's enough characters available to make the whole match string, >= 2.

void loop() {
  if (Serial.find("aa")) {
    Serial.println("Found!");
  }
}

What the Serial.read() is doing there in your code is anyone's guess...

If you're reading the characters, how do you ever expect to match with characters in the receive buffer, which will now be empty?

should anyone give short example of how to use Serial.find() function .please help me

Some test code you can try using the serial monitor. Send a string like "123aaa456aa78aaa90" to see the output.

void setup() {
  Serial.begin(9600);	// set serial port at desired value
  Serial.println("serial find test"); // echo test
}

void loop() {
  while (Serial.available()) {
    if (Serial.find("aa")) {
      Serial.println("Found!");
    }
    else { 
      Serial.println("not there"); 
    }
  }
}

@zoomkat thank you sir.i understand find()

Serial.findUntil("i dont like you","dont")

in this case it returning 1 so what is use of terminating string

little confusion with terminate string

Please do not cross post, that is posting the same question twice or more on the Arduino forum.

Sorry to say but cross posting is wasting my time that I could have spend on an answer :frowning:

http://forum.arduino.cc/index.php?topic=207773.0
http://forum.arduino.cc/index.php?topic=207839.msg1528225#msg1528225
http://forum.arduino.cc/index.php?topic=207837.msg1528207#msg1528207

Topics merged / deleted.

I have a very low tolerance of cross-posting - it wastes time.

sorry for cross posting.it happened unintentionally .sorry about and thanks for your help

AWOL:
Topics merged / deleted.

I have a very low tolerance of cross-posting - it wastes time.

Well, the other post got *ss wipe answers like "RTFM!", so multi posting was probably in order to get a useful answer. Just my opinion.

Serial find is of limited use since it is a blocking function, ie nothing else runs while find waits.

GoForSmoke:
Serial find is of limited use since it is a blocking function, ie nothing else runs while find waits.

Maybe it should have been called Serial.waitFor()...?

To all the people screaming rtfm, the documentation on Stream and its methods are totally insufficient to try and write code (ie the documentation describes target as a char not a char *. I've spent far too long puzzling over them and then I searched the forums, saw that threads like this were slightly better, but still not fully helpful. After that I looked at the source and now understand it much better but also understand why I'd be hesitant to use it since Stream.findUntil() is buggy.

search for "ABABC" in a stream containing "ABABABC" as an example. Of course it's also impossible to handle cases like this without a buffer of some form but this should at least be mentioned in the docs.

Rather than use Serial.find() read all the data into a char array and search the array for the characters you are interested in. See serial input basics for ... the basics.

...R

Xuth
I totally agreed with you having spent a day effectively hacking to use one of the find commands.
The documentation is so minimal, such a shame to write a library but fail to explain with a few good "hello world" /n examples.

Would be good to know if there is a full list of the stream functions and how they work somewhere as I'm sure were not the only ones having to hack.
Regards
Paul

rowanp:
The documentation is so minimal, such a shame to write a library but fail to explain with a few good "hello world" /n examples.

I know it can be very frustrating but that is because nobody gets paid to write the documentation. It seems that people like writing programs but don't like writing documentation.

I have tried to make a little contribution with serial input basics

...R

1 Like