Bluetooth- Select list item: List index too large

1,187 views
Skip to first unread message

J. Mur

unread,
Nov 8, 2017, 8:38:12 PM11/8/17
to mitappinv...@googlegroups.com
I am trying to send data over bluetooth and receive data in the app from 3 sensors. 
I attached the arduino code (using bluesmirf silver and arduino uno), the sensors are not connected for this test because I am trying to fix the app at the moment.
However, I keep on getting the warning that the index is too large.

Similar questions have been asked before but the suggested fixes do not seem to be working.
 
Please advise,

Thank-you.
23439524_2056139247952771_821255083_n.png
bloka2.PNG
code.png

Evan Patton

unread,
Nov 9, 2017, 12:23:43 AM11/9/17
to MIT App Inventor Forum
I think the issue here is that in your Arduino sketch you are calling Serial.read() and passing the value to the Bluetooth serial port. Serial.read() only returns a single byte, which will then be sent to App Inventor.

When you attempt to split on ',', this will result in a list of length 1 with the single byte included. Your blocks code attempts to extract 3 elements when only one exists, hence the error.

Assuming that you are writing to Serial for debugging purposes, you may want to consider constructing a String by concatenating the values and then write the String both to Serial and Bluetooth.

Regards,
Evan

J. Mur

unread,
Nov 9, 2017, 10:48:46 AM11/9/17
to mitappinv...@googlegroups.com
Thanks for your help, I tried to follow your suggestion and it seems to not be receiving anything now. Maybe I'm making an error in printing from the bluetooth?
post.JPG
blocks.JPG

Abraham Getzler

unread,
Nov 9, 2017, 12:01:37 PM11/9/17
to MIT App Inventor Forum
I suggest showing us the Clock1 Attributes from the Designer.
It's important to know that it's firing, and at what rate.

Also, I don't see any feedback in your Clock1.Timer
IF CONNECTED statement to announce whether or
not BlueTooth is still connected.  

ABG

J. Mur

unread,
Nov 9, 2017, 12:37:52 PM11/9/17
to MIT App Inventor Forum
here are all the blocks
all blocks.JPG

Martyn_HK

unread,
Nov 12, 2017, 5:29:21 AM11/12/17
to mitappinv...@googlegroups.com

The error message you posted is saying you are trying to use element 2 but the list is only one element long.
This means you are trying to process the data before you have it all. This is a frequent issue when using any kind of serial communication.
To stop this happening you need to use some kind of marker to show you have all the data. My solution is to use start and end markers and a buffer.

When the clock ticks I copy any new data to a buffer, I then check the buffer to see if I have all the data.
If I have all the data I process it. If not I wait for more.

Have a look at the following. These are not exactly what you want but you can use the same  method to read your sensors. Look for the BT_processBuffer procedure.
One
Two
Three








J. Mur

unread,
Nov 13, 2017, 4:41:34 PM11/13/17
to mitappinv...@googlegroups.com
Thank-you for the suggestion!
I solved the issue by fixing things on the arduino side, but I have added this to my app too. Thank-you
Reply all
Reply to author
Forward
0 new messages