2017년 4월 10일 월요일

Bluetooth .connect block unreliable.


Hello and thanks in advance for any help I might get. 

I am writing an AI2 app that uses bluetooth comm to control and Atmel328 MCU via an bluetooth HC-06 module and an android tablet.  For app development I'm using Ubuntu 14.04 and Chrome browser.   My app has multiple screens.  I have read that a bluetooth connection is not maintained when switching screens.  Therefore, I am disconnecting prior to switching to a new screen, and then reconnecting as needed on the new screen.  This seems to work  for the first .connect instance on the new screen, however ALL subsequent connection attempts spawn the dreaded 507 error 'unable to connect'.  Cycling power on the BT module is the only way to recover original functionality.  I have tried this using different  HC-06 modules and android devices, both with the stand-alone apk file and from within the AI2 web development environment.  The results are always the same.. breaks/hangs the BT module on disconnect in the second screen   It seems to me that the bluetooth is not disconnecting properly, although the HC-06's LED blinks to indicate the lost connection.   My questions are; 

1.>  Is it possible to run from bluetooth from multiple screens as long as you disconnect-change screen-reconnect?
2.>  Is there some  minimum wait time between the sending/recieving data, disconnecting a device, changing screens (is it a timeing issue). My data never exceeds 16 bytes at 9600 baud?    
3.>  What Bluetooth device seems to be the the most problem free with respect to arduino comm?

I'm at a loss as to how I can run this problem down and would appreciate any assistance.

--
This seems to be a common problem with embedded Bluetooth modules. I see similar with the Microchip RN42. Are you able to change any settings on the HC-06? I've never used it but from what I've seen it seems to be a very basic unit.

On the RN42 I find that increasing the page scan and inquiry windows helps but even still the unit is not receptive to quick disconnect-reconnect cycles. I've read that this is something to do with how Android implements Bluetooth although I do occasionally get the same problem when connecting via Windows.

I've not tried it myself but I've read elsewhere that others have had some success with hiding parts of the screen rather than switching screens but how well that would work depends on your app.

--
Good to know that I'm not totally clueless.  
I have not tried to change HC-06 settings.  The HC-06 was provided with the default app-style documentation, NONE!  However there are a few user references our there.  I'll give it a go.  
Realizing that the HC-06 is, as you say, a "basic unit", I'm interested in hearing from anyone with better alternative device experience i.e Sparkfun's BlueSMiRF.  Five times the cost - five times better?
You mention increasing the "page scan".  What does that mean and how is it accomplished?  Also "quick" disconnect-reconnect cycles is relative.  What wait duration do you recommend?

--
Google the Microchip RN42 module. The documentation on that is extensive and explains the various page and inquiry scan settings - although they are ones that apply to that module. You'd have to find equivalent commands - should they even exist - for the HC-06. Basically, the module doesn't spend all the time looking for something to connect to, it powers down for a period then wakes up again and scans for things trying to connect. All you do is increase the duration of this scan period.

Unfortunately the duration between cycles sometimes needs to be in minutes to work reliably! It seems to vary, some I can connect to no problem, others take several tries. I also find sometimes it helps to move either phone or module - these things have PCB antennas which are highly direction-sensitive. Moving to a module that uses a whip-type antenna would improve things a lot but also add to the cost.

As for other modules, aside from the occasional connection problem I'm have lots of success with the RN42. In particular it is good for distance - I've been able to communicate with a unit about 30m away through two walls without any problem. Documentation is great, the only problem you may have is finding it in a prototype-friendly form as it is most often sold as a surface-mountable module. I believe there is a version with SIL headers but it costs a lot more.

--
A bit more on the RN42:

You can get the RN42XVP-I/RM - this has pin headers so will be easier to prototype with. Depending on your country you may find a better supplier, as I'm UK based I generally prefer Farnell:
http://uk.farnell.com/microchip/rn42xvp-i-rm/module-bt-802-15-1-xv-cl2-pcb/dp/2321374

The Microchip RN42 page is:
http://www.microchip.com/wwwproducts/Devices.aspx?product=RN42

The command reference guide is the most detailed.

--

댓글 1개: