Char split in app

Hello,
I send from arduino to appinventor by bluetooth

Serial.print("A1234") ;
Serial.print("B5678");

In app inventor : a variable witch called ( input1 )must take the first value (A or B),
Then an other variable (input2) takes numbers only after the letter

Any example to do that in app inventor?

This is a good place to use some text blocks:

  • length() to make sure you have enough characters
  • segment(v,1,1) to ask for the first letter
  • segment (v,2,(length(v)-1) the get the rest

Thank you ,
I got error (invalid text operation)
Have to split betwin the texts sent by arduino ?

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Then i did in arduino :
Serial.print ( "A674" );
Serial.print(!);
Serial.print ( "B98544" );
Serial.print(!);
Delay(100);

In the first step I liked to separate the first letter and numbers

Please see the Delimiter article in FAQ

Delimiter Byte 10


global message
(draggable)

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.

Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Replace that last Serial.print(!); with Serial.println(); to include your Line Feed delimiter. You don't need a closing "!" then.

Your splitting at ! is a mess.

You took length of the split result, when you should have been testing if length of list > 1, to prevent selecting nonexisting list items further down.

You did not select items 1 or 2 from the list into variables.
Those are the parts you want to test, right?

In fact, if you are labelling data by their first character (A,B,...), why do you need to group them together in the same message?
Just println them one by one, and then no need to split them when they arrive.

I m begginer in app inventor , i will send the aia file and the arduino code,
I just want to reconize 3 variables in app inventor, I don't like to use the split and index list , because arduino don't send always those variables in order, that why i want to use labels,

balDERtest8.aia (14.8 KB)

ard code.txt (992 Bytes)

I don't know any French, and I don't know which letters on messages should steer them into which variables or labels, so I am guessing blindly.
But here is the pattern to follow ...

ard codeABG.txt (955 Bytes) println
balDERtest8_ABG.aia (12.1 KB)

P.S. You were missing a closing }

Thank you very much ABG !!, I WILL TRY THAT AT HOME

That s working good !,
I will add more labels.

You gave me a good example aia to work on,
Thank you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.