How to convert received ASCII data to a value

Hi ABG, thanks for your suggestion. I am using microbit block coding, they have a pre-written block 'bluetooth uart service' and can't seem to find print command.. :sweat_smile: :sweat_smile: I am sorry that i am not a coding-savvy guy, still much dependent on block coding

You can also read this topic:

i try to use the block 'segment text..start...length' but get into error also..
[50,49,51] => segment text getLDR, start 2, length 8 doesn't seem to be the correct approach. Please advise. Thank You.

Thank you Patryk_F, I'll have a look.

This way you can convert numbers and text.

test_tool.aia (9.7 KB)

Dear @Thenk_Hou, as far as your "[" and "]" question, you can do like this:
image

in other words, you can replace whatever character with a null character (not a blank/space, but an empty/null one). Then you can split the remaining at commas.
Of course the suggestions from @Patryk_F or @ABG are good as well !!! You can try and choose whichever ir simpler (the simplest the best, always :grinning:)

Another algorithm...

If you write [50,49,51,10] and do a Receive Text in AI2, there is a good chance you will receive your 3 digit number as a piece of text, with no extra markup ("",)

The extra 10 I added at the end if a Line Feed, that can be used like in my Delimiter article to catch a whole message in AI2.

Hi Juan, thanks for your advice. I have tried ur code but so strange that I am getting back some funny output. :joy:

if i set the label1.text to global ldr, the output value is "50,49,51";
if i set the label1.text to global decimal, the output value is back to [50,49,51] and
if i set it to global ldrList, the value is [[50,49,51]].. seems like the code will add back the "[" and "]" automatically..

Please englighten. Thanks in advance.

Try

borrar_decimal.aia (2.7 KB)

Let's have a contest who has the simplest solution. This is mine:
Add a Webviewer to your design. It does not have to be visible, therefore you do not have to see it.
Now, add this block:


The string in the join is actually this:
window.AppInventor.setWebViewString(String.fromCharCode(

So, instead of waiting for BytesReceived, you wait for WebViewStringChange.
Also add this block:


Here I add the value to a label containing previously received text. You may want to do something different.
The trick is that JavaScript knows how to convert ASCII and AppInventor does not. We have asked for this alreay to be implemented. Keep your fingers crossed.

Great Juan! I have found out I pick some wrong block thus resulting in error. The code works! Tq very much!

Hi Ghica, I'll try ur code out after this to see if it does simplify the process. May I know if the java script actually already built in? Cos i dun see any website address in ur code..

Thanks for your help. Appreciate it.

Hi ABG, microbit have their own Bluetooth extension which I m using. Therefore I can't apply any trick u share on the ClientBluetooth1 block..:sweat_smile::sweat_smile:

Still thanks to ur offer of help. :pray:

The block you are running is called RunJavaScript and as input you provide some JavaScript. JavaScript has some handy functionality built-in to convert ASCII to UTF or whatever character set you have. So, what is your problem?

In the case that you receive one, two or three digits, the code should be...

Now that I understand the game, here is the map/reduce version, generalized to all text, based on @Italo's ASCII conversion:
AsciiCHRASCprocedures.aia (4.4 KB)


make_string_test_capture

1 Like

you can use the following extension:
ConversionAsciiTexte.aix (9.3 KB)

image

here is a documentation of the extension
https://community.appinventor.mit.edu/t/extension-app-inventor-pour-donner-le-code-ascii-dun-caractere-et-inversement/80397