HC-06 (Bluetooth) Configuration (RN-42 Code Added)
JonnyMac
Posts: 9,105
I haven't searched the forums, but I'll bet the HC-06 made it onto the list of Erco specials -- it's an $8 Bluetooth module that is available everywhere. I've been playing with a few Bluetooth modules for an upcoming project. I have the Parallax RN42 module, an XB-socket compatible RN42 module from Sparkfun, and an HC-06 that I bought from eBay (which, surprisingly, shipped from Los Angeles so I had it in two days instead of four weeks).
The HC-06 is cheap and easy to use (just look at the number of Arduino tutorials for it....), but it's finicky if you want to change the settings. You see, it doesn't use a line-ending character for commands, it uses a timeout period -- and that's pretty darned fast.
I want my BT modules to have unique names and pairing codes, so I wrote the attached configuration program. Honestly, it's overkill, but with a point. I've recently created a parsing engine (subject of my April column) for a bunch of projects and I used this to make setup of the HC-06 easier. For example, instead of sending "AT+BAUD8" I can enter "BAUD 115200" -- and when I request a baud rate change in the module (which should be done after everything else is set), the serial link to the module is restarted with the new baud rate. This is useful if the module is set to something other than the default (9600). In my case, I'm using 115200. If I want to change something, I start the configuration tool and enter "AT" -- if I get "OK" back, I know I'm connected. If I don't, I use the BAUD setting until AT gives the correct response. It's easier to do than to explain.
I'm having fun with Bluetooth. A couple weeks ago Rick Galinson and I were having dinner and I set an activity board with HC-06 on the table. I pulled out my phone, started a little app (created with MIT App Inventor 2), and made things happen. We giggled like kids. It's no big technological feat, but the ability to control our Propeller projects from a cell phone with a bit of code and an $8 module makes us very happy.
The HC-06 is cheap and easy to use (just look at the number of Arduino tutorials for it....), but it's finicky if you want to change the settings. You see, it doesn't use a line-ending character for commands, it uses a timeout period -- and that's pretty darned fast.
I want my BT modules to have unique names and pairing codes, so I wrote the attached configuration program. Honestly, it's overkill, but with a point. I've recently created a parsing engine (subject of my April column) for a bunch of projects and I used this to make setup of the HC-06 easier. For example, instead of sending "AT+BAUD8" I can enter "BAUD 115200" -- and when I request a baud rate change in the module (which should be done after everything else is set), the serial link to the module is restarted with the new baud rate. This is useful if the module is set to something other than the default (9600). In my case, I'm using 115200. If I want to change something, I start the configuration tool and enter "AT" -- if I get "OK" back, I know I'm connected. If I don't, I use the BAUD setting until AT gives the correct response. It's easier to do than to explain.
I'm having fun with Bluetooth. A couple weeks ago Rick Galinson and I were having dinner and I set an activity board with HC-06 on the table. I pulled out my phone, started a little app (created with MIT App Inventor 2), and made things happen. We giggled like kids. It's no big technological feat, but the ability to control our Propeller projects from a cell phone with a bit of code and an $8 module makes us very happy.
Comments
Now I just have to invent more time to implement those ideas. :-/
It could be updated to do that, yes, but the RN-42 is far more friendly to setup. I've attached my RN-42 terminal program which basically echoes what you type into PST, and takes from the RN-42 and sends it to PST. Easy-peasy.
The first BT module I had was the Parallax RN-42, then I got the XBee socket compatible unit from Sparkfun. BT is fun -- I just wish creating a cool little app for my Android was as easy as programming in Spin.
re:-- I just wish creating a cool little app for my Android was as easy as programming in Spin.
Have you tried Basic for Android? I know you like basic LOL
By purchasing the hosted Mac builder service you agree to our terms.
B4A Enterprise + B4i Enterprise
Requires a local Mac computer
$189 instead of $238 USD
With Hosted Mac Builder (1 year)
$199 instead of $266 USD
B4A (Android)
Standard
Includes two months of free upgrades.
$59 USD
Basic for Android:
http://www.b4x.com/store.html
http://www.basic4ppc.com/android/screenshots.html
I tried it once and it was easy and affordable. I had a trial version at the time.
Bluetooth (serial ports) was listed.
Thanks!! I'll try it next week.
It turns out that I had a really old version so I was able to get the upgrade at a good deal -- just the Android stuff.
I'm really busy with some big projects, so it may be a month or two before I really dig in. I have played a bit with MIT App Inventor, but don't enjoy the blocks programming interface.
Not much to look at, but it does work well.
https://play.google.com/store/apps/details?id=com.tecit.datareader.android.getblue.full&hl=en
http://www.picaxeforum.co.uk/showthread.php?27141-RoboRemoFree-App-with-the-HC-06
BTW, here is a helpful comparison of HC05/HC06 modules: http://mcuoneclipse.com/2013/06/19/using-the-hc-06-bluetooth-module/
-- http://forums.parallax.com/showthread.php/159920-Android-Control-of-Propeller-using-Joystick-BT-Commander-App-Spin-Code
An Arduino enthusiast has created a nice little robot control app for Android; I waded through his code and ported it to the Propeller. It would be a little work, but it could be used with the BS2 as well.
There's a bit of an error on that page: you can in fact put the HC-06 in master mode. The problem is that it wants to pair with the first BT module it finds -- this could make things tricky.
OK, Before I go any further I want to clarify this comment in your jm_rn-42_terminal.spin file:
Connect RN-42.RTS to RN-42.CTS
So just a jumper wire from RTS to CTS on the RN-42 module, correct? I know it may seem like a moot question but I do not want to burn up my RN-42 or my PPDB.
-- http://forums.parallax.com/showthread.php/159920-Android-Control-of-Propeller-using-Joystick-BT-Commander-App-Spin-Code
That ultimately gives -100 to +100. You can use this method to convert that range to servo values.
Why don't you post you code -- that would be easier than guessing.
Some days I just want to give up....