Quantcast
Viewing all articles
Browse latest Browse all 941

Converting string to integer

Hi,

recently i stumbled into an odd problem. The fact is, that i'm not able to convert a number (string) (sent from an arduino like device) to android using Bluetooth. However the same procedure works great when send the same string to a PC using serial port.

So the code on my mbed side is just:

bt.printf("%i\r\n",Tobj1);

where Tobj1 is an integer number varying from 20000 to 100000 (it's a thermopile temp. sensor)

and on the android side I use:

String info2 = trim(info); Tobj = int(info2);

where info is the result from onBluetoothDataEvent

If i use text and try to put the value on screen I can see the results, so this is working fine, but if I want to put on the screen the Tobj variable, it's always 0. So the conversion Tobj = int(info2) does not work. I tried with several methods, using splitTokens, but as far I saw, the lenghth is verying so the app crashes immediatly.

Is there any other way to convert a string into an integer ?


Viewing all articles
Browse latest Browse all 941

Trending Articles