Skip to first unread message

Zacharias Antony

unread,
Aug 12, 2018, 3:16:28 PM8/12/18
to MIT App Inventor Forum
Hi i am very new to app inventor

i have one arduino that sends data via bluetooth  with single byte (character)

if (UpRightLimitState == LOW) {
 
Bluetooth.write('a'); delay(10);
 
}
 
else if (UpRightLimitState == HIGH) {
   
Bluetooth.write('b'); delay(10);
 
}

 
 
if (UpLeftLimitState == LOW) {
 
Bluetooth.write('c'); delay(10);
 
}
 
else if (UpLeftLimitState == HIGH) {
   
Bluetooth.write('d'); delay(10);
 
}

 
 
if (DownRightLimitState == LOW) {
 
Bluetooth.write('e'); delay(10);
 
}
 
else if (DownRightLimitState == HIGH) {
   
Bluetooth.write('f'); delay(10);
 
}

 
 
if (DownLeftLimitState == LOW) {
 
Bluetooth.write('g'); delay(100);
 
}
 
else if (DownLeftLimitState == HIGH) {
   
Bluetooth.write('h'); delay(10);
 
}

in app inventor i have made an app that detects the changes and   appears a text (green or red) depending the character readings

for two cases works fine

when i add 4 cases then  when it should appear the green text  it  make it appear and then go again to red text and then back to green

when i add more cases then display only red text... like if cant read the data


my  app inventor blog  is like that (for the 4 cases)



Screenshot from 2018-08-12 22-05-40.png




I know that something have done wrong with the type of received data


the app look like that :

Screenshot_20180812-220858.png

The Green texts (the one before the red one and the other after the other red one)  going red and then green again  but the should stay in green based the arduinos port status

any help about what i have made wrong? 

thanks in advance


ps : i used in my arduino code  and the  serial.print     and  "h"  instead 'h'   character but had no change..  the results were the same in app behavior

Abraham Getzler

unread,
Aug 12, 2018, 6:17:45 PM8/12/18
to MIT App Inventor Forum
Each time you issue a BlueTooth Read Text for 1 byte, you are throwing
away the previous value and getting a new piece of text from the buffer.

To make each received character available for all those if/then/elseif tests,
receive one character into a global variable C, then send it down 8 if/then tests:

if global C = 'a' then
  ...
if global C = 'b' then
  ...
if global C = 'd' then
  ...
etc.

Your else clauses were a problem, since the ELSe of C = 'a' would be triggered by
'b', 'c', 'd, 'e', ...

ABG

Abraham Getzler

unread,
Aug 12, 2018, 6:20:00 PM8/12/18
to MIT App Inventor Forum
Also, 10 millisecond delays are a bit fast for AI2.
It can't drink from a fire hose.

What is your AI2 Clock interval?

ABG

Zacharias Antony

unread,
Aug 13, 2018, 6:05:26 AM8/13/18
to MIT App Inventor Forum
the clock interval is  at 100

Abraham Getzler

unread,
Aug 13, 2018, 11:46:27 AM8/13/18
to MIT App Inventor Forum
Get your logic right first, then worry about the interval.

Remove the ELSE clauses and grab the input into a variable,
checking the variable against each letter separately.

ABG

Zacharias Antony

unread,
Aug 13, 2018, 1:04:45 PM8/13/18
to MIT App Inventor Forum
i have one problem with global variable

i dont know how to make the ''app inventor'' read the characters separately

i made this option

Screenshot from 2018-08-13 19-44-46.png




And this one 


Screenshot from 2018-08-13 19-42-12.png



but in both  options  when i open the compiled application in my android phone i get this message

Bad arguments to>
the operation  > cannot accept the arguments : , [adfhikoradfhikoradfhikor],[0]


where the  : adfhikoradfhikoradfhikor      
are the characters that arduino sending via bluetooth depending the i/0 port status,   i was changing the status of i/o  ports and i could see the characters changing as i supposed to be based in my programing

Abraham Getzler

unread,
Aug 13, 2018, 1:55:04 PM8/13/18
to MIT App Inventor Forum
i dont know how to make the ''app inventor'' read the characters separately 

You were doing it fine in your previous setup.

Since all your codes are single bytes, you can get away with asking for them one at a time,
and the availability test is to see if the available count > 0.

See attached, just the part I circled.

Take 1 byte into the global, then apply 8 tests to it.

ABG

 

Zacharias Antony

unread,
Aug 13, 2018, 2:30:53 PM8/13/18
to MIT App Inventor Forum
I cant see the attached file  (sorry but not used to this kind of forum setup )

Abraham Getzler

unread,
Aug 13, 2018, 3:55:58 PM8/13/18
to MIT App Inventor Forum
Test for Bytes Available > 0,
then receive just 1 byte of text.

ABG

Zacharias Antony

unread,
Aug 13, 2018, 5:36:09 PM8/13/18
to MIT App Inventor Forum
My mistake... in my original setup i had it like that..   >0   and checking for 1 byte     and change it to 8 as i was trying to find out what was wrong (and stayed like that when i took the screen-shot )


Ok now i make a new setup using the variable  and stopped having the problem about fluxing between  the 2 states (green and red)  now displays just the right color  based in arduino i/o ports state

the problem is that this setup works only for checking only 4 ports ( 8 scenarios  ,  4 for on  and   4 for closed) if i add  to check and a fifth one then the program doesnt work well , displays just 2 or 3 of the   ports

Screenshot from 2018-08-14 00-23-53.png





















































Just a bigger view of my new setup


Screenshot from 2018-08-14 00-24-22.png





























































Abraham Getzler

unread,
Aug 13, 2018, 5:50:16 PM8/13/18
to MIT App Inventor Forum
You should have only a single Receive Text in your Timer event.

Otherwise, you will be discarding inputs without having subjecting them to all the needed tests.

ABG

Zacharias Antony

unread,
Aug 13, 2018, 7:18:56 PM8/13/18
to MIT App Inventor Forum
 When you say '' Receive Text ''   are you talking about this block ?


Screenshot from 2018-08-14 02-16-44.png

Abraham Getzler

unread,
Aug 13, 2018, 8:59:51 PM8/13/18
to MIT App Inventor Forum
When you say '' Receive Text ''   are you talking about this block

Yes 

Zacharias Antony

unread,
Aug 14, 2018, 1:31:06 AM8/14/18
to MIT App Inventor Forum
ok this time i think i understand what you were telling me from the beginning (as it is the first time i am using the app inventor i had to start understand the logic of blocks)

i make this setup and my app when i start the bluetooth connection  read the status of all the arduino's i/o  ports right  :) 

But now i have an other issue
if i change the the status of arduino's ports then the app doesnt read them or  will read them after very long time
if i press the button to connect again to bluetooth (it is all ready connected) then shows the changes.
It is like i have to make a manual refresh  so i am guessing that  it is something wrong with my settings about clock  or havent place something in blocks that will make the refresh to happen automatic (i dont know if there is a block with this function)


Screenshot from 2018-08-14 08-14-25.png

Zacharias Antony

unread,
Aug 14, 2018, 5:06:43 AM8/14/18
to MIT App Inventor Forum
as i told in my previous post the new setup worked  but had problem with the time that the app needed to read the changes in my arduino's ports

I changed the clock's  TimerInterval  to : 10    and now works fine

at the first half minute is little late (not so much issue)  and after that the response is fine

so everything is as i wanted

Thanks Mr Abraham Getzler  for your patient  to make me understand finally what should had done in order to work  :)
Reply all
Reply to author
Forward
0 new messages