Need help for ListPicker function


So for this part it splits list with a space is it? e.g. [F, ,100]? is it like this? so index for F is 0 and index for 100 is 2

The split at spaces block returns a list splitted in spaces. For example, if you split the string Apples are tasty at spaces, it will return a list with the first item as Apples, the second item as are and the third as tasty.

1 Like

Then why is the global Script empty? Also does the spaces in the list counted as one index?

Because BytesAvailableToReceive is 0, and that converted into text is an empty string.

Yes, global List has an empty text item, but that list still has a length of 1.

So should I set other number for the BytesAvailableToRecieve?
But I thought it is >0?

Yes, probably.

I have tried >1 or >2 but it still doesn't works

I checked the description for that block.

image

It attempts to receive text from the Bluetooth, and if it returns empty text, it is probably an error (in your code).

So there is problem in my Arduino code?

Maybe. That's all I know - I think a power user should know more than me.

1 Like

ok thank you so much

1 Like

From your Arduino code, I see you are sending NL-delimited messages of the form
single letter - space - number - NL

To receive complete messages, follow this standard advice:

Please see the Delimiter article in FAQ

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.
BlueToothClient1_Properties
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.

1 Like

May I know how can I check this? any programming or need to check manually

Also how to test for this?

Are you referring to the Arduino code for this?

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

3 Likes

Yes. But I already saw that in your (?) Arduino code.

But I need to use ListPicker... If I use these blocks then I need to change my code in Arduino right? Or these blocks are just add-on?

How can I open this file? which app do i need to use to open this?

Import it in app inventor

graphic

1 Like

Download the file, on the top bar, click on Projects > Import project (aia) from my computer, and then upload the AIA file.

2 Likes

Thanks guys... imported

2 Likes