Help with understanding bufferUntil

So i have earlier tried reading strings via serial, and its a pain. I then found something about bufferUntil, but im not sure i understand it.

So to use it, would you put the Serial.bufferUntil in the loop(), and then handle all the serial reading and such in the serialEvent?

I think its kinda hard to find documentation on it :confused:

This is the only official thing ive found:

So to use it, would you put the Serial.bufferUntil in the loop()

No. bufferUntil() would be called in setup().

and then handle all the serial reading and such in the serialEvent?

Possibly.

What is the problem you are trying to solve?

working with an RTC, and want to send it a string via a processing program. The string would be a unix timestap followed by a '!'

ive actually just solved it (-_-), but i now have the problem of converting a String object, to an int, im just doing some googleing right now. Im thinking of using the toCharArray() function, and then converting that to an integer, just gotta find out how it was that was done :slight_smile:

so far, the string thing is done by a modified version of the serialEvent example

void serialEvent() 
{
  while (Serial.available()) 
  {
    if(Serial.peek() == '!')
    {
      Serial.read();
      stringComplete = true;
    }
    else
    { 
      char inChar = (char)Serial.read(); 
      // add it to the inputString:
      inputString += inChar;
    }
  }
}

knew it was simple :slight_smile:

checked the reference, and found int() :slight_smile:

any advice on improving the code?

You could use the String::toCharArray() function and then the atoi() function to get an int from a String. Or you could use the String::toInt() function.

String::toInt()? dont see that in the reference.

checked the reference, and found int()

Which will not convert a string, or String, to an int. The int() "function" is for people that do not understand how to cast a value to an int.

then i gues thats for me :confused: care to explain?

im lost :stuck_out_tongue:

care to explain?

int(sameVariable) is exactly the same as (int)someVariable (which is the proper way to perform a cast).

It tells the compiler to treat the variable as an int, even though the variable is not an int. You might do this if you have a long that you KNOW contains a value that fits in an int that you want to pass to a function that only takes ints.

It will NOT convert a string or a String to an int, no matter what the string or String contains.

ahh okay thanks, im a bit confused now though, how will i use the toCharArray? And where would the char array im getting out of it go to?