Need Help with HC-06 Bluetooth Module

joe paul

Senior Member
Hi Folks,

I bought 3 of the HC-06 Bluetooth modules http://www.ebay.com/itm/Wireless-Serial-4-Pin-Bluetooth-RF-Transceiver-Module-HC-06-RS232-With-backplane-/200924726178 and although I can get my new inexpensive Android tablet to pair with the board, I cannot seem to get either of the apps BlueTerm or RoboRemo to connect to the module. I tested 2 of the 3. I get the blinking LED on the module that indicates power is on and the tablet tells me it is paired. Used the correct password, etc. Tried it connected to the 18M2 and by itself with power, no difference. Both programs try to connect for a while.

Any suggestions? What am I doing wrong? I get the following error message from RoboRemo:

"java.io.IOException: read failed, socket might be closed or timeout, read ret:-1"

Thanks!

Take care, Joe.

P.S. When I tried to enter an incorrect passcode for the pairing, it wouldn't accept it but it does accept the correct "1234" code, then tells me it is paired. I don't have any other devices to test it.
Thanks. J.
 
Last edited:

joe paul

Senior Member
Hi Folks,

Well, I tried an app called "Bluetooth Serial Tester" and I was able to connect and send info to the PicAxe, and flash an LED. Just need to figure out why these other apps don't work!

Will keep everyone posted!

Take care, Joe.
 
Last edited:

joe paul

Senior Member
Hi Folks,

O.K. So far, the free app that works is "SENA BTerm," found it on Google Play. This is with the 18M2 chip and the HC-06 module. My code, which I modified from: http://www.practicaspicaxe.blogspot.com/search?updated-min=2014-01-01T00:00:00+01:00&updated-max=2015-01-01T00:00:00+01:00&max-results=8

Code:
main:

 serin B.5, T9600_8,b0 
 
  if b0=114 then goto red 
  if b0=98 then goto blue 
  if b0=103 then goto green 
goto main


 red:  
 for b1=1 to 4
 high B.4
 pause 1000
 low B.4
 pause 100
 next b1
 goto main

blue:
 for b1=1 to 4
 high B.3
 pause 1000
 low B.3
 pause 200
 next b1
 goto main

green:
 for b1=1 to 4
 high B.6
 pause 1000
 low B.6
 pause 150
 next b1
 goto main
It flashes the LEDs if lower case letters are sent to the module, "r" for red, etc.

Now on to testing the MDFLY MP3 board with this code.

Take care, Joe.

P.S. I actually will change the "serin B.5" to B.2 and use the B.5 for serout when I get to it, if I need it. Wanted to avoid all the voltage divider issues by not using any serout to the HC-06 anyway. J
 
Last edited:

veracruz290

New Member
Joe,this is really cool stuff!!! Please keep posting what you find. I have HC-06 Bluetooth module on order. Hope to pick your brain more after the module arrives. Maybe as late as May 22nd 2015. Cheers, Rick
 

srnet

Senior Member
I had a bit of trouble with SenaTerm, it would crash when it was sent VT100 formatting codes that it is supposed to support.

Blueterm+ was a stable, but then I would not assume that all Android applications behave the same on all tablets or phones that run Android.
 

joe paul

Senior Member
Hi Srnet,

I eventually used the Android app RoboRemoFree http://www.roboremo.com , but at first it wouldn't connect to the HC-06. I e-mailed the developer and got an answer the next day. He said he was aware of the issue on certain Android devices and he was fixing it. Sure enough he did and sent me another e-mail soon after. I had no Bluetooth devices before this and actually bought a cheap 7" Bluetooth enabled tablet just for these projects. I still have one HC-06 that I can pair and connect with, but I think the baud rate isn't the default and I can't communicate with the Picaxe, but I am shooting the dark.

Take care, Joe.
 

Bill.b

Senior Member
Hi Joe

I have has some success connection my sumsung tablet and a chines smart phone using roboremo (Full version).

The default setting of the HC-06 is 9600 with password 1234.

This picaxe test program tests a number of button and slider inputs.

Code:
REM Controlling of 3 LEDs via BT module HC-06 with reception
REM confirmation - PICAXE
setfreq m16  ;set frequency to 16 MHz
pause 1000
b10 = 150
b11 = 150
serout c.2,n2400_16,(254,1)        ' reset  slider values on serial OLED display
do  ;start of program loop
 b0=0  ;clearing memory for commands
 serin [2000],c.0,T9600_16,b0,b1,b2,b3,b4,b5 ;reading from bluetooth (waits 2s for
 ;character)
 
'debug

 select b0  ;selection according to received character
  case 65 	 high b.0        'LED 1  ON
  case 66 low b.0             'LED 1  OFF
 case 67 high b.1            'LED 2 ON
 case 68 low b.1              'LED 2 OFF
 case 69 high b.2             'LED 3 ON
 case 70 low b.2              'LED 3 OFF
 case 113               ' Slider 1
      if b4 > 10 then
		b10 =b2 - "0" * 10 + b3 - "0" * 10 + b4 - "0"
	else

		b10 =b2 - "0" * 10 + b3 - "0" 
	endif	
	serout c.2,n2400_16,(254,128)
	 serout c.2, n2400_16,("Speed  = " ,#B10," ")
 case 114       'slider 2
 	 if b4 > 10 then
		b11 =b2 - "0" * 10 + b3 - "0" * 10 + b4 - "0"
	 
	else

		b11 =b2 - "0" * 10 + b3 - "0" 
	endif	
	serout c.2,n2400_16,(254,192)
 	serout c.2, n2400_16,("Camera = ",#b11," ")
 endselect  ;end of selection of commands
 
loop  ;end of loop
Button ID Codes used
Button 1 - A
Button 2 - B
Button 3 - C
Button 4 - D
etc

The Slider Codes are
1 - ID = q
Range = 0 - 100
2 - ID = r
Range = 0 -100

hope this helps

Bill
 
Last edited:

joe paul

Senior Member
Hi Bill.b,

Thanks for your tips!!!!

What I did was just to set the slider to 10 positions (0-9) that correspond to 10 different pre-set PWM "commands." I didn't know if the math would slow down the speed of reading the SERIN. I see you used the time out option with the SERIN. I will have to experiment with it because once in a blue moon the remote seems to drop-out. I have given up on the one bad HC-06 module and got 5 more (I love this Bluetooth control). My code:
Code:
setfreq m8 

main: 

serin C.0, T9600_8,b0,b1 

if b1 = 48 then goto zero       ;48 to 57 is ASCII for "0" to "9" 
if b1 = 49 then goto one 
if b1 = 50 then goto two 
if b1 = 51 then goto three 
if b1 = 52 then goto four 
if b1 = 53 then goto five 
if b1 = 54 then goto six 
if b1 = 55 then goto seven 
if b1 = 56 then goto eight 
if b1 = 57 then goto nine 
if b0 = 99 then goto Direction       ;99 is ASCII for lowercase "c" 
if b0 = 109 then goto ZeroZero       ;109 is ASCII for lowercase "m" 
if b0 = 110 then goto ZeroReset       ;110 is ASCII for lowercase "n" 

goto main 

zero: 
pwmout B.6, OFF 
Let b2=0 
goto main 

one: 
pwmout B.6, 99, 200 
Let b2=1 
goto main 

two: 
pwmout B.6, 99, 250 
Let b2=2 
goto main 

three: 
pwmout B.6, 99, 275 
Let b2=3 
goto main 

four: 
pwmout B.6, 99, 300 
Let b2=4 
goto main 

five: 
pwmout B.6, 99, 325 
Let b2=5 
goto main 

six: 
pwmout B.6, 99, 350 
Let b2=6 
goto main 

seven: 
pwmout B.6, 99, 375 
Let b2=7 
goto main 

eight: 
pwmout B.6, 99, 400 
Let b2=8 
goto main 

nine: 
pwmout B.6, 99, 450 
Let b2=9 
Goto main 

Direction:      ; reverses leads to the tracks 
pwmout B.6, OFF 
pause 2000 
toggle B.4 
goto ZeroReset 


ZeroZero:       ;PMW OFF 

 pwmout B.6, OFF 

goto main 

zeroReset:       ; for release of STOP/direction button 

if b2=0 then goto Zero 
If b2=1 then goto One 
If b2=2 then goto Two 
If b2=3 then goto Three 
If b2=4 then goto Four 
if b2=5 then goto Five 
If b2=6 then goto Six 
If b2=7 then goto Seven 
If b2=8 then goto Eight 
If b2=9 then goto Nine 

 goto main

I spent time trying to duplicate what one model train company is supposed to launch this spring with Bluetooth, and do it on the cheap, but I don't really want the control within the train, but rather trackside. I want to incorporate sound effects and turnout control, and tain position detection. I wasn't going to get into PWM but I really like the ease of doing it with the Picaxe and it is rather inexpensive compared to other controllers, even homemade versions.

Like a lot of this, you sometimes find yourself going in a different direction than your original plans.

I am still waiting for the other shoe to drop; I have to the put it through it paces on my layout where there is a lot of potential interference (electrical noise) and magnetic fields.

Take care, Joe.
 

erco

Senior Member
"Blue Control" is another free Android app that works fine with Picaxe. Not customizable, but simple to use and ready to go, no configuration required. Thirteen buttons total, your software will decode the fixed values sent.

 

MurrayJ

Senior Member
If you want something customisable I use App Inventor 2. It uses drag and drop buttons, labels, sliders, pictures, text to speech, Sound Playback, Speech Recognition and many more, including bluetooth control. Then each can be programmed in the blocks editor, which is pretty much the same as Blockly for the Picaxe.

You even test your app before putting it on your Android phone, with wifi control of your phone from your computer so you can see exactly how it will look and behave.

I had a simple bluetooth program to change the colors of an RGB Led going in a few minutes. The only downside is that even though you can have multiple screens easily in App Inventor 2, the bluetooth will cut out if you change screens, so limiting you to one for this application. I hope they fix this one day.
 

hippy

Technical Support
Staff member
If you want something customisable I use App Inventor 2.
I would also recommend App Inventor 2. Very easy to use and, as it is all browser based, there is no need to download, install and configure the Android SDK and IDE.

The learning curve is minimal. The price is that it is more limiting but most limitations are not the end of the world.

The only downside is that even though you can have multiple screens easily in App Inventor 2, the bluetooth will cut out if you change screens, so limiting you to one for this application.
One solution I saw suggested for that ( though I have not tried it ) is to have a single screen with multiple layouts which holds the controls which would be on other screens, hide and reveal those as required so it looks like the app is using multiple screens.
 

jims

Senior Member
This may be a bit off the subject...but I can't seem to find info... Is there some way that I can use the bluetooth on my iphone 6 to communicate with Picaxe 20m2? Seems that android is required to use the HC-06. Have any FORUM members done this? Any info to get me started will be appreciated. Thank you...JimS
 

jims

Senior Member
Thank you coparu67...I'll give it a try. JimS

Went to the site and it says that it require Android. Will it actually work on an iphone 6?? JimS
 

inglewoodpete

Senior Member
Thank you coparu67...I'll give it a try. JimS

Went to the site and it says that it require Android. Will it actually work on an iphone 6?? JimS
It appears that the HC-06 is incompatible with iPhone due to iPhone only coded for a subset of Bluetooth protocols. I am not an iPhone user so have no experience with them. However, Googling 'iphone "hc-06" bluetooth' suggests that there are other modules which may do what you want.

Added: Have a look at this instructable. It's not specifically about a PICAXE but the article may help you if the HM-10 BLE module is still available.
 
Last edited:
Top