I am working on a project that passes a string from an Arduino Uno to MIT App Inventor via an HC-05 Bluetooth thingy.
The Arduino does a routine to create several integers (weight_FL, weight_FR, weight_RL and weight_RR). I then take these integers and create a string for each. I then join the separate strings into one with a delimeter between them.
StringFL = String(weight_FL,0);
StringFR = String(weight_FR,0);
StringRL = String(weight_RL,0);
StringRR = String(weight_RR,0);
StringDataSent = String(StringFL + "/" + StringFR + "/" + StringRL + "/" + StringRR);
The AI2 is receiving the string but says it cannot use the string/number in mathematical caluclations. I believe this is due to each number being preceeded with a space (I have been told elsewhere that AI2 is smart enough to auto convert a text number to a number). I have looked in the serial monitor and there is definitely a space being added when first 4 strings are created.
Previously I used
StringFL = String(weight_FL);
but this resulted in "0.00" being sent even though I had previously converted the value to an integer. Originally I thought the ".00" part was causing this issue.
I think I need to fix this issue in the Arduino code so that either the ".00" is not added to the end or no space is added at the beginning but I have drawn a blank even though I am sure it is a simple solution. Can you assist??
Simple answer, skip the useless String and go for string
Is slow and takes a lot of memory for a simple task.
Just don't concatenate it first, just send it the way you want it
Serial.print(weight_FL);
Serial.print('/');
Serial.print(weight_FR);
Serial.print('/');
Serial.print(weight_RL);
Serial.print('/');
Serial.print(weight_RR);
Wow super fast response!!
I tried the code you suggested and all that does is to go back to adding ".00" onto the end of the strings. AI2 still cannot perform maths on those strings.
If your weight variables are floats, you will get the decimals for free
It's the way Serial.print works (and probably the String class as well);
To get rid of it, the first line posted by septillion will be
Serial.print((int)weight_FL);
If you get .00 then your variables are not int like you said
Or change them to real int (float is slow and isn't needed for 99% of the calculations on the forum anyway). Or use Serial.print(weight_FL, 0) to specify you want 0 decimal places.
OK I am a complete nob. I thought they were integers but septillion made me question it. I had a routine that ensured they rounded to the nearest integer (I think the int command just cuts off the decimals without rounding up?) but I had not actually set them as integers. Stupidity just cost me 3 hours!!!
I assume using septillions code rather than my clumsy Strings would run faster??
Thanks for the help.
Yep it does. Sting has a lot of (memory) overhead.
Btw, rounding to the nearest int instead of flooring it is easy by just adding 0,5. Or, don't use float at all 
PS Things like this happen when you don't follow forum rules and just post a snipped. 