toInt()

Hey Guys,

I've been trying the toInt on a string and I can't get it to work. I tried something like

String testSpeed = "22";
int speed = testSpeed.toInt();
Serial.println("Speed: " + speed);

and I get a print out of

Speed:

So I guess it's not converting but I took a look at the doc and the only reason why it would not work was that it's that the string should start by a numeral number.

Thank you for the help.

i use this

Kanal = stringTOint(Dummy);

int stringTOint(String wert)
{
char carray[wert.length() + 1]; //determine size of the array
wert.toCharArray(carray, sizeof(carray)); //put Stringinto an array
int erg = atoi(carray); //convert the array into an Integer
return erg;
}

I've had troubles with adding numbers to strings in a Serial.println() like you do. :slight_smile:

Try :
Serial.print("Speed: ");
Serial.println(speed);

toInt() should work in that case :slight_smile:

Oh ok I'll give it a try when I get back home.

Thank you both