Using blue tooth connectivity

266 views
Skip to first unread message

Gregary Boyles

unread,
Jul 26, 2015, 9:24:52 AM7/26/15
to mitappinv...@googlegroups.com
I have created my first android app using the app inventor.

It involves connecting my phone to an arduino uno with a HC-05 module and then switching some LEDS connected to the arduino on and off.

I have created two screens.

The first one has a pick list from which you select the appropriate bluetooth device from a list of available devices.

I have created a control structure that attempts to connect to the selected device and displays the message 'connected to ......' and then switches to the next screen with some control buttons.

However the problem is that successful blue tooth connection in the first screen does not carry over to the second screen.

So how do you make a blue tooth client block element in the first screen available to the second screen in a connected state?

If I attempt to do any serial communication on the blue tooth element in my second screen I get a message saying that it is not connected to anything.

I guess what I am trying to do is have a global (to all screens not just all elements in one screen) variable containing the  Blue tooth connection.


FIRST SCREEN


SECOND SCREEN



Taifun

unread,
Jul 26, 2015, 10:52:03 AM7/26/15
to MIT App Inventor Forum, gregsindigen...@gmail.com
for bluetooth you have to use only one screen, else the connection will be lost after going to another screen
you can only one screen and vertical screen arrangements to simulate different screens instead, just set an arrangement to visible = true and other arrangements to visible = false
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Gregary Boyles

unread,
Jul 26, 2015, 11:39:27 AM7/26/15
to MIT App Inventor Forum, taifu...@gmail.com
OK, thanks for that.

I ended up doing that anyway until I got an answer here. So I suppose I will have to be satisfied with a single screen.

My app is successfully communicating with my arduino and switching the LEDs on and off....sort of.


But I seem to be having unusually large problems with serial data errors.

The HC-05 is set to a baud rate of 115200.

When I had two of these communicating from my PC to the Arduino there did not seem to be any data errors at 115200. But my mobile phones seems to be having a problem with it.

I keep getting command text sent through to the arduino with random character substitutions that are messing things up some what.

Is there anything I can do at the mobile phone end to rectify this?

SteveJG

unread,
Jul 26, 2015, 12:11:28 PM7/26/15
to MIT App Inventor Forum, gregsindigen...@gmail.com
Here is how to change the baud on the HC-05 :  http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/  

Instead of 115200 , try 9600 ... your devices do not seem to be able to handle that fast transfer rate and your project itself might not require it.

If you search Android Bluetooth baud, you will find some interesting links indicating it might not be possible, at least on some devices, to change the Bluetooth baud settings.

What happens when you change the baud on the HC-05 to be compatible with what appears to be the standard 9600 on Android devices, at least some of them?


Regards,
Steve

Gregary Boyles

unread,
Jul 26, 2015, 12:22:48 PM7/26/15
to MIT App Inventor Forum, taifu...@gmail.com, gregsindigen...@gmail.com

Is it possible to just set the baud rate lower on the phone and leave the HC-05 baud rate as is?

 

SteveJG

unread,
Jul 26, 2015, 12:39:46 PM7/26/15
to MIT App Inventor Forum, gregsindigen...@gmail.com
RE: "Is it possible to just set the baud rate lower on the phone and leave the HC-05 baud rate as is?"     

I expect not.   The link shows how you can change the baud on the HC-05 to be compatible with most if not all phones, not the other way around.

Keep on searching the Internet Gregary.  I hope you find information to the contrary.

You said you are having  large problems with serial data errors. The reason is the  HC-05 is set to a baud rate of 115200 and the phones to perhaps 9600.  This is a huge mismatch.  You said  when "communicating from my PC to the Arduino there did not seem to be any data errors at 115200. "  That is great, your ports on your PC can easily handle a variety of serial communications speeds.  What I understand about Android on phones is the phones cannot or not easily change baud rate and if it is possible, it is not possible with AI2 commands.    To further research this: https://www.google.com/search?q=change+the+baud+rate+on+my+android+phone&oq=change+the+baud+rate+on+my+android+phone&aqs=chrome..69i57.8703j0j7&sourceid=chrome&es_sm=93&ie=UTF-8   to find out how you might manually change the baud rate on your Android...there might be a way.

Regards,
Steve

Abraham Getzler

unread,
Jul 27, 2015, 1:08:17 PM7/27/15
to MIT App Inventor Forum, gregsindigen...@gmail.com
 keep getting command text sent through to the arduino with random character substitutions that are messing things up some what.

Random character substitutions might also be due to two other causes in serial communication ...

Is there a place to specify if the serial line carries parity bits?  
Getting that wrong between the transmitting and receiving sides might cause random character substitutions.
(Remembering back to my BBS modem days)

 Also, check if your language settings differ on your devices.  There are a lot of different character coding schemes out there.

ABG

MartynC

unread,
Aug 3, 2015, 4:51:00 AM8/3/15
to MIT App Inventor Forum, gregsindigen...@gmail.com
When you say you have set the baud rate on the HC-05 to 115200, do you mean the connection to the Arduino?

This may not be an issue with the communication between the HC-05 and the phone. It could be an issue with the communication between the Arduino and the HC-05, especially if using software serial.

I had a similar problem and slowing the speed the Arduino speaks to the HC-05 solved it. 38400 works quite well, 9600 works perfectly for me.





Reply all
Reply to author
Forward
0 new messages