Skip to first unread message

AlexisFrJp Android

unread,
Sep 6, 2015, 7:34:04 AM9/6/15
to mitappinv...@googlegroups.com
Hi everyone,

I read A LOT of topics on this forum but nothing relevant. When it becomes interesting, no one reply anymore.

Arduino send via bluetooth to android something like this : 125A1023A845A15A etc... ie a integer between 0 and 1023 separated with "A".
I'd like to get the integer and display it continuously.

Then with a BytesAvailableToReceive, I'm trying to parse the text but I don't know. I tried too many things, I'm tired cause I didn't find anything.

The "buffer" is a global variable called buffer_var.
number_display is the variable for one number.
I'd like to be able to do :

while i < (buffer_var.size - 1) do
-- number_display = 0
-- while buffer_var[i] != "A"  {i++}  // To remove incomplete integer before the delimiter "A"
-- i++; // It's A then we go to the first number
-- while buffer_var[i] != "A" { number_display[y] = buffer_var[i]; i++; }
-- DISPLAY number_display in the LABEL.

How I can do ?!

Thank you very much.

Abraham Getzler

unread,
Sep 6, 2015, 12:14:15 PM9/6/15
to MIT App Inventor Forum
You are using the letter "A" as a delimiter for text transmission.
If you examine the AI2 Designer attributes of a Bluetooth client,
you will see a place where you can specify a delimiter value.
(Usually, people specify a LF here.)
In your case, provide the numerical value of "A" off an Ascii chart, decimal column.

If you examine the tool tip text of the Receive Bluetooth Bytes block 
(not the exact name. browse around), you will see a special case of
how to specify how many bytes to receive if you want just enough
to reach the next delimiter and no further (0).

The decision to do the receive operation is still the same, bytes available > 0.

That should give you the text bytes up to the next "A", which you
can drop into a label.text or a variable.

ABG

Abraham Getzler

unread,
Sep 6, 2015, 12:19:26 PM9/6/15
to MIT App Inventor Forum
By the way, if you use println() on the Arduino side instead of print(),
you will send a LF character after your text, useful as a delimiter on the receiving end.

ABG


AlexisFrJp Android

unread,
Sep 6, 2015, 10:36:04 PM9/6/15
to MIT App Inventor Forum
Hi,
Thank you very much,
Yes I already tried ...

Arduino : Serial.println(Amps); (Amps is a integer from 0 to 1023)

App inventor : see the picture


"text ReceiveText(number numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received."
then I set at -1.
This doesn't work, after having chosen the bluetooth device, black screen.

Actually, I don't want to stop to the next delimiter because he can receive just a part of the first number. Eg : 1023 LR 1574, it can receive 23 LR 1574  and then I'll get only 23 instead of 1023.
Then I'd like it begins at the first delimiter and stops at the second delimiter.


AI.jpg

Abraham Getzler

unread,
Sep 7, 2015, 11:53:04 AM9/7/15
to MIT App Inventor Forum
I don't see you guarding your Bluetooth client.ReceiveText block
with a test for client.BytesAvailabletoReceive > 0.

I believe you need that in addition to the connection check.

ABG

AlexisFrJp Android

unread,
Sep 7, 2015, 9:22:36 PM9/7/15
to mitappinv...@googlegroups.com
Hi,
I did, after I select the BT module, it's freezing and 10sec afterthat "The app doesn't respond".
My arduino send every 200ms a : println("")
The app inventor clock refresh is at 100ms.
Is the way I did is good or not ?
Thank you.
aze.jpg

Abraham Getzler

unread,
Sep 7, 2015, 11:10:01 PM9/7/15
to MIT App Inventor Forum
The blocks shown look okay, so let's look elsewhere.

Show us the Designer settings for the Bluetooth client,
especially its delimiter, and your Arduino transmission code too.

Also, what else is going on in the AI2 app?

ABG

Reply all
Reply to author
Forward
0 new messages