How to display a float number via bluetooth
-
Good evening
I have only recently started using GUI-O and have not yet been able to understand how I can display a simple float variable on the display if a bluetooth connection is used. Is there perhaps a good example in this forum that explains my problem?
Thank you very much for your support.
Regards Fehr -
@Fehr
Hi!Glad to have you on-board the GUI-O enthusiasts!
You can use a label widget for displaying any kind of text/numeric values.
After connecting over Bluetooth, you can create a label by sending a string:
"|LB UID:my_label X:50 Y:50 TXT:\"<your float as string>\"\r\n"
The \ before the double quotes is an escape sequence, so that double quotes are properly interpreted within the command.
You can build this command by using "snprintf" on a char buffer (this is a c/c++ language standard library function).
You can check out the examples here:
https://www.gui-o.com/examplesAlso, the manual describes the label (and other widgets) in more detail. You can download tge manual cia the GUI-O app or from GUI-O website.
If you need any additional information or help, feel free to ask.
Best regards,
Kl3m3n -
Good morning,
In the initialization script, simply define a Label:
|LB UID:your_label X:95 Y:96 W:20 FGC:#fb0001 FSZ:5 FFA:'font8' TXT:'0000'".
and write from your program In this Label "your_label " in the form of a string.
I don't know in C but with Bascom:
Dim Float as single //float variable
Float=3,414 // Float value
Dim Value as string *10 // declare Value as string
Value=Str(Float) // convert in string
Print "@your_label TXT:" ; Value ; " // print in your_label
and there you have it!
It works via Bluetooth or Wifi, it doesn't matter.
Bernard -
@kl3m3n said in How to display a float number via bluetooth:
Hi kl3m3n, thank you very much for the quick reply.
Unfortunately, my char array variable is still not output correctly in the following example. I am currently using an ESP32 as test hardware.
I can now generate a correct string with the snprintf function. This is confirmed by the following console output.
In the GUI display, however, the variable name is still displayed instead of the content of the char array. This is actually my general question, how do I have to pass the content of a string variable (char array) correctly so that I get the same output in the GUI as on the console?
Thank you very much for your support.
Regards Fehr -
with an update function that retrieves the entire string that needs to be sent, I finally managed to transfer the desired number to the GUI display.
The following string is displayed on the Arduino console:
And the desired numbers values are now finally visible in the GUI:
Basically, it works. However, my question now is is there no easier way to achieve the same result? Thank you very much for your feedback and regards.
Fehr -
@Fehr Hi.
The easier way is to fist create a label (like @Bernard suggested):
"|LB UID:my_label X:50 Y:50"
Then just modify its TXT property:
@my_label TXT:\"<value>\"\r\n
If you don't want to use snprintf, you can just use + operator:
String str = "@my_label TXT:" + "\"" + String(val) + + "\"" + "\n\r";
You can simply create a function to avoid repeating this command with different TXT values.
P. S. Similar topic:
https://forum.gui-o.com/post/116Best regards,
Kl3m3n -
@kl3m3n
Thank you very much for your support.
To use a string instead of a char array is even easier -
@Fehr No problem!
I plan to write a FAQ page on GUI-O website, which will also include this explanation.
Best regards,
Kl3m3n