0

I'm transmitting: Temperature: 28.22C

and on the receiving end I'm receiving the whole tranmission as a string. I'm trying to spilt Temperature to leave it as a string and 28.22 as a float to compare, how do I do that ?

TX end hardware: (Arduino Uno board with Xbee S1) to computer RX end hardware: (Arduino Uno board with Xbee S2) to computer

asked Jun 10, 2015 at 4:04
2
  • 1
    Is the "receiving end" an Arduino or a computer? If it's a computer, you should tell which language you use and probably ask your question on stackoverflow. Commented Jun 10, 2015 at 4:28
  • Hi, the receiving end is an Arduino Uno board which is hooked up to the computer. The transmitting end is also hooked up to an Arduino Uno board. Both communication goes through Xbee S1 card Commented Jun 10, 2015 at 8:02

2 Answers 2

2

Okk very simple approach :-

Suppose this is your string variable inStr = "Temperature: 28.22C"

String inStr = "Temperature: 28.22C";
int indexOfSpace = inStr.indexOf(' ');
//this stores the address of the space character in the string.
int indexOfC = inStr.indexOf('C');
String Temp = inStr.substring(indexOfScace+1,indexOfC);
//as the parameter for the function is supposed to be the starting point of the string to
 be extracted and one more than its ending point.
//Now to convert to float
float TempFlo = Temp.toFloat();
answered Jun 10, 2015 at 11:58
1
  • @user10566 if this answer worked please consider marking it as accepted so that the SE system does not bump it up as an unanswered question. Commented Jun 4, 2016 at 19:47
0

I suppose your communication is working... In order to retrieve a floating number from a string you might use toFloat() function. You can watch the reference page here to understand how does it work.

answered Jun 10, 2015 at 10:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.