Reading values in String

Hi!
I'm writing a program where the Arduino is receiving data from the HC-06 Bluetooth module. In the default loop function the Arduino checks if there's any data avaliable on the Bluetooth module, and if there's data it runs a loop that receives chars and putting them all together into a String.
The Arduino could receive, for example, "R100R-100". I want the program to get the two numbers 100 and -100 to two variables and get the first "R" into a String variable. Right now I'm trying to do that directly when the Arduino is reading the chars from the Bluetooth module, but I can't get it to work.
Is there's any other way to read values from a String?
Thanks in forehand. :slight_smile:

char incomChar;
bool printData = false;

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

void loop() {
  String incomData = "";
  while (Serial.available() > 0) {
    incomChar = Serial.read();
    incomData += incomChar;
    printData = true;
  }
  if (printData == true) {
    Serial.print(incomData);
    printData = false;
  }
}

Try something like this.
Αnd study on substring function. https://www.arduino.cc/en/Tutorial/StringSubstring

I can't get it to work.

Take a look at Serial input basics - updated

Is there's any other way to read values from a String?

You shouldn't be using Strings on the Arduino. But, the term you are looking for is parsing, not reading. Mr. Google is at work this week. He's sure to be able to help you.

Thanks for the answers, I'll take a look at serial input basics, substring and parsing. And try finding an alternative to Strings

Imim:
Thanks for the answers, I'll take a look at serial input basics, substring and parsing. And try finding an alternative to Strings

Fixed it :wink:

As others have suggested, use char arrays rather than the String class. After making that change, take a look at the strtok() function and see if that might be of help.