Arm Mbed and Pelion Device Management support forum

HC-06 Values using mbed

Hi,
I am trying to send float values from my K64F to the android app using mbed. The Arduino code which I am referring is using

Serial blue(PTC15, PTC14);
while (true) {
blue.print(Val)
val = val + 1 ;
}

But I am unable to use the “print” function in mbed. How to use it? I tried sprintf and printf (Not helping).
I don’t want to visualize all the values being sent. The latest value is what I wanted to see. Can anyone help me with this?

Hardware: K64F, HC-06
Thank you
Regards
Niranjan

Here’s the Mbed Serial API documentation. You’ll want to use printf, but you need to format the string in the following way, assuming that val is an integer and you’re delimiting by CRLF.

blue.printf("%i\r\n", val);

Also, in your code Val in the line blue.print(Val) has a capital V. Below that you increment val, with a lowercase v.

Hope this points you in the right direction.

Adam

Ahoj,
print is not a member of Serial.h, how wrote Adam, use the printf.
When you want to send a float type, you need to format it first because the output on opposite side is represented as a string type.

So if the variable val is int type then
blue.printf("%d\r\n", val);
but when the variable val is float type then
blue.printf("%f\r\n", val);

BR, Jan

Hi,
Yes, I was able to fix it.
Now I have to send two values but they should come up in separate text boxes in my android app.
For example:
int val = 200;
int result = 2;
blue.printf("%d", val); - > In android display, it should come on first field(text box)
blue.printf("%d", result); - > In android display, it should come on second field(text box)
Thanks and Regards
Niranjan

You should send something like:

blue.printf("val: %d", val);
blue.printf("result: %d", result);

When you read them on Android, you can send the right one to the right box thanks to the label.

Looking further, you could even format your output as json like this:

blue.printf("{ \"val\": %d, \"result\": %d }", val, result);

And use a json decoder on Android.
But the Android part is out of the scope of this forum.

Hi,
Yes, I used that. I was wondering if there is any other way.
Thank you for the information.
Regards
Niranjan