Go Down

Topic: Convert String From Serial Data to Numerical Value (Read 3 times) previous topic - next topic

chiques

Hello Everyone,
I've been able to read and select a string of data to display on my terminal using:

Code: [Select]

for (int i=6;i<11;i=i+1) {
  Serial.print(sensorstring[i]);
      }
Serial.println(" Liters/Minute");
//


My goal is to convert this value to a 'number' so I can run an algorithm on it. I tried to use

Code: [Select]

Serial.parseInt()


but am unable to figure out the syntax and the Arduino Reference site does not have any examples.

Any insight is appreciated.

billroy


HazardsMind

#2
Jan 14, 2013, 11:59 pm Last Edit: Jan 15, 2013, 12:11 am by HazardsMind Reason: 1
That "string" is an array so by using atoi(sensorstring) it will be converted to an integer.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

chiques

Thanks for that, I tried:

Code: [Select]

      int value = atoi(sensorstring);
      Serial.println(value);


Quote

error: cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'


Is it because it's reading sensorstring as '1'?

billroy

Sorry, it's probably time to show us all your code, please.  I was guessing that sensorvalue was char[] not String.

-br

Go Up